×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VB Form on top
3

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

RE: VB Form on top

2
I have this as a separate function for use by several forms.

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

(OP)
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

RE: VB Form on top

(OP)
How can I remove the leader added by SW when I insert a block?

A

RE: VB Form on top

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:

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

(OP)
dsi,

Works great, thank you.

Andrew

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources