Tuesday, December 16, 2008

[vb6] Make form stay on top

Sometimes you need a form to stay on top, even when another form has focus, so that its immediately available to the user. This code toggles the OnTop state for a form when passed the hwnd property of a form:
    Private Const GW_HWNDFIRST& = 0
Private Const HWND_NOTOPMOST& = -2
Private Const HWND_TOPMOST& = -1
Private Const SWP_NOMOVE& = &H2
Private Const SWP_NOSIZE& = &H1
Private Declare Function GetWindow& Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long)
Private 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)

Private Sub ToggleTopmost(ByVal hWindow As Long)
Dim hw As Long
hw = GetWindow(hWindow, GW_HWNDFIRST)
If hw = hWindow Then
SetWindowPos hWindow, HWND_NOTOPMOST, 0, 0, 0, 0, _
SWP_NOMOVE Or SWP_NOSIZE
Else
SetWindowPos hWindow, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_NOMOVE Or SWP_NOSIZE
End If
End Sub

3 comments:

  1. Magnificent goods from you, man. I have
    remember your stuff prior to and you're just too excellent.
    I really like what you've acquired right here,
    certainly like what you are saying and the best way by which
    you say it. You make it enjoyable and you continue to take
    care of to keep it wise. I can't wait to read far more from you.
    This is actually a tremendous website.

    Visit my site; More about the author

    ReplyDelete
  2. Thanks in support of sharing such a nice thought, piece
    of writing is fastidious, thats why i have read it entirely

    Also visit my web blog navigate to this website

    ReplyDelete
  3. Howdy! I know this is kind of off topic but I was wondering if you knew where I could locate a captcha plugin for my comment
    form? I'm using the same blog platform as yours and I'm having problems finding one?
    Thanks a lot!

    Also visit my website: lawyer rates

    ReplyDelete