VB Form on top
VB Form on top
(OP)
How do I make a VisualBasic form stay on top of SW window (be visible all the time with SW window maximized)?
Andrew
Andrew
When was the last time you drove down the highway without seeing a commercial truck hauling goods?
Download nowINTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS Come Join Us!Are you an
Engineering professional? Join Eng-Tips Forums!
*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting GuidelinesJobs |
|
RE: VB Form on top
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Public 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 Sub ForceWindowOnTop(hwnd As Long, bTrueFalse As Boolean)
Dim i
If bTrueFalse = True Then
i = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
Else
i = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
End If
End Sub
'Then, to call it from a Form:
Private Sub Form_Load()
Call ForceWindowOnTop(Me.hwnd, True)
End Sub
'To turn it off, just use False
Call ForceWindowOnTop(Me.hwnd, True)
Hope this helps...
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: VB Form on top
I tried to use your function but I get the following error:
Compile error
Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules.
?????
Andrew
RE: VB Form on top
A
RE: VB Form on top
Put this in a module:
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Public 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 Sub ForceWindowOnTop(hwnd As Long, bTrueFalse As Boolean)
Dim i
If bTrueFalse = True Then
i = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
Else
i = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
End If
End Sub
Use the function call-outs in the form:
'Then, to call it from a Form:
Private Sub Form_Load()
Call ForceWindowOnTop(Me.hwnd, True)
End Sub
'To turn it off, just use False
Call ForceWindowOnTop(Me.hwnd, False)
The leader question should be a separate thread.
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: VB Form on top
Works great, thank you.
Andrew