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 TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Form on top 3

Status
Not open for further replies.

dogarila

Mechanical
Joined
Oct 28, 2001
Messages
594
Location
CA
How do I make a VisualBasic form stay on top of SW window (be visible all the time with SW window maximized)?

Andrew
 
I have this as a separate function for use by several forms.
Code:
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.
 
dsi,

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
 
How can I remove the leader added by SW when I insert a block?

A
 
You need to put the declaration of contants in a module. You can not declare constants in the source of a form.

Put this in a module:
Code:
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:
Code:
'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.
 
dsi,

Works great, thank you.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top