Hello,
I added the following declarations to my MDIParent form:
---- Begin code ------------------
Private Declare Function GetTopWindow Lib "user32.dll " (ByVal hWnd
As IntPtr) As IntPtr
Private Declare Function SetForegroundWi ndow Lib "user32" (ByVal
hwnd As IntPtr) As IntPtr
Private Declare Function GetWindowText Lib "user32" Alias
"GetWindowTextA " (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal
cch As Long) As Long
Private Declare Function SetWindowPos Lib "user32" Alias
"SetWindowP os" (ByVal hwnd As IntPtr, ByVal hWndInsertAfter As Long,
ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long,
ByVal wFlags As Long) As Long
Private Const HWND_TOP As Integer = 0
Private Const HWND_BOTTOM As Integer = 1
Private Const HWND_TOPMOST As Integer = -1
Private Const HWND_NOTOPMOST As Integer = -2
Private Const SWP_NOSIZE As Long = &H1
Private Const SWP_NOMOVE As Long = &H2
Inside my public sub I have:
Me.Show()
Me.WindowState = FormWindowState .Normal
Trace("frmMain. LoadMyForm", "++++++++++++++ +++++++++++ (2) - Me.Handle =
" & Me.Handle.ToStr ing & ", TopWindow = " &
GetTopWindow(Me .Handle).ToStri ng)
'Me.TopMost = True
Dim strTest As String
GetWindowText(G etTopWindow(Me. Handle), strTest, 100)
Trace("frmMain. LoadMyForm", "(2) Prior to doing the SetForegroundWi ndow,
TopWindow Name = " & strTest)
'SetForegroundW indow(Me.Handle )
SetWindowPos(Me .Handle, HWND_TOPMOST, Me.Left, Me.Top, Me.Width,
Me.Height, SWP_NOMOVE Or SWP_NOSIZE)
Trace("frmMain. LoadMyForm", "(2) After doing the SetForegroundWi ndow
Me.Handle = " & Me.Handle.ToStr ing & ", TopWindow = " &
GetTopWindow(Me .Handle).ToStri ng)
Trace("frmMain. LoadMyForm", "(2) - Me.TopMost = " & Me.TopMost.ToSt ring)
Trace("frmMain. LoadMyForm", "(2) - Me.Visible = " & Me.Visible.ToSt ring)
Trace("frmMain. LoadMyForm", "(2) - Me.WindowState = " &
Me.WindowState. ToString)
Trace("frmMain. LoadMyForm", "(2) - Me.Position = " & Me.Left.ToStrin g &
", " & Me.Top.ToString )
'Me.TopMost = False
SetWindowPos(Me .Handle, HWND_NOTOPMOST, Me.Left, Me.Top, Me.Width,
Me.Height, SWP_NOMOVE Or SWP_NOSIZE)
Trace("frmMain. LoadMyForm", "(3) - Me.TopMost = " & Me.TopMost.ToSt ring)
---- End code ------------------
It shrinks my window and puts it all the way in the upper left hand
corner of the screen. I thought that the coordinates system in .NET and
Windows was different, but would have expected the "SWP_NOMOVE Or
SWP_NOSIZE" to prevent that.
Other than that, it works the same as doing the Me.TopMost = True
shortly followed by a Me.TopMost = False. My form doesn't pop to the
top of the z-order that I can see.
My tracefile shows:
10/16/2003 1:46:59 PM : frmMain.LoadMyF orm :
+++++++++++++++ ++++++++++ (2) - Me.Handle = 8390128, TopWindow
= 11142560
10/16/2003 1:46:59 PM : frmMain.LoadMyF orm :
(2) Prior to doing the SetForegroundWi ndow, TopWindow Name =
10/16/2003 1:46:59 PM : frmMain.LoadMyF orm :
(2) After doing the SetForegroundWi ndow Me.Handle = 8390128,
TopWindow = 11142560
10/16/2003 1:46:59 PM : frmMain.LoadMyF orm :
(2) - Me.TopMost = False
10/16/2003 1:46:59 PM : frmMain.LoadMyF orm :
(2) - Me.Visible = True
10/16/2003 1:46:59 PM : frmMain.LoadMyF orm :
(2) - Me.WindowState = Normal
10/16/2003 1:46:59 PM : frmMain.LoadMyF orm :
(2) - Me.Position = -1, 103
10/16/2003 1:46:59 PM : frmMain.LoadMyF orm :
(3) - Me.TopMost = False
10/16/2003 1:46:59 PM : frmMain.LoadMyF orm :
Exit routine
Eric Goforth
Raleigh, NC
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!