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

UnCall a Function?

Status
Not open for further replies.

mpm32

Technical User
Feb 19, 2004
130
US
I found this function that works nicely on the on click event of a button. It keeps the form On top of all other applications.

The Function;

Code:
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 Const HWND_TOPMOST = -1
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOMOVE = &H2

Function TopMost(F As Form)
         Call SetWindowPos(F.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
                           SWP_NOMOVE Or SWP_NOSIZE)
End Function

I call it from here;

Code:
Private Sub OnTopCommand_Click()

Call TopMost([Form])

End Sub

I want a button that disables this function as well so that if the user wants to go back to having other apps on top they could press that button. Right now the form has to be closed and then reopened. This has to be simple, I tried cancel, delete, etc.

Can anyone help? Thanks in advance.
 
How about using a checkbox on the form? Then use your call TopMost as part of an IF statement.
 
Hey, thanks. Good idea. I can make that idea work with a toggle button too, I think.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top