Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Stay on Top

17 views
Skip to first unread message

Oin Zea

unread,
Apr 8, 2005, 5:17:20 AM4/8/05
to
is there a way to tell an MDIChild window to always stay on top of the other
in Visual Basic 6?


David Hodgkins

unread,
Apr 8, 2005, 4:35:09 PM4/8/05
to
Yes, there is. I got the following code from a member of another group quite
some time ago. I wish I could remember who it was so I could give credit
where credit is due, but below is what I got and it works great for me.
start by creating a basic module called modSetAlwaysOnTop and put in the
following code:

Option Explicit

Public Const SWP_NOMOVE = 2
Public Const SWP_NOSIZE = 1
Public Const Flags = SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2

Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, _
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

Public Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) _
As Long

If Topmost = True Then 'Make the window topmost
SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, _
0, Flags)
Else
SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, _
0, 0, Flags)
SetTopMostWindow = False
End If
End Function
------------------------------------------------------------------------

Next, in the form you want to keep on top, put the following in the
Form_Load event

Private Sub Form_Load()
Dim lR As Long
'Keep this window on top
lR = SetTopMostWindow(Me.hwnd, True)
End Sub
-------------------------------------------------

Hope this helps!

David Hodgkins, MCSD, MCDBA, MCSE
JSTAR Software Solutions
4402 Sweet Cherry Ln.
Kalamazoo, MI 49004
www.jstarsoftware.com - Home of AutoCompact for Access Databases
269-382-2931


"Oin Zea" <Oin...@hotmail.com> wrote in message
news:6c12f$42557a76$40ed96b2$21...@COQUI.NET...

Oin Zea

unread,
Apr 11, 2005, 6:25:12 AM4/11/05
to
It works but not on a MDI form. If I set the form to be a mdichild it will
hide behind other mdichild windows.

"Oin Zea" <Oin...@hotmail.com> wrote in message
news:6c12f$42557a76$40ed96b2$21...@COQUI.NET...

0 new messages