Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I set VB6 programs to be "always on top"?

Status
Not open for further replies.

Tigerman

Programmer
May 15, 2001
18
US
Using VB6, is there a property or function that will keep VB applications "always on top" of other applications even though it may not have focus? Thanks!
 
Assuming you are talking about a form:
You can use the SetWindowPos API function.
Code:
'To Force Form On Top
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) As Long
'For SetWindowPos
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2

    Dim i As Long
    'Force Form On Top
    i = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
    'Remove Forced Setting
    i = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
 
Thanks, dsi. Yes, I was speaking about forms. I appreciate the help. I will give it a whirl! Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top