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

Keeping My Window On top

Status
Not open for further replies.

Hmadyson

Programmer
Mar 14, 2001
202
US
I have a visual basic form. I want to make sure that it is always on top of all other windows that the user has open. I do not want the VB window to be the active application, just a window that floats on top. I am using SetWindowPos from the Winapi, but it does not seem to set my window on top. I am also trying to run an event when another application is activated, but I am having no luck. Can anyone out there help me. Thanks.
 
Make Your Form Be Top Most

'This sample will show you how to make your form to be Top Most (Like ICQ)
'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Add 2 CommandButtons to your form (named Command1 and Command2).
'When you will press the first button the form will be top most.
'When you will press the second button the form will back to the regular state.
'Insert this code to the module :

Declare Function SetWindowPos Lib "user32" (ByVal h%, ByVal hb%, _
ByVal x%, ByVal Y%, ByVal cx%, ByVal cy%, ByVal F%) As Integer
Global Const SWP_NOMOVE = 2
Global Const SWP_NOSIZE = 1
Global Const flags = SWP_NOMOVE Or SWP_NOSIZE
Global Const HWND_TOPMOST = -1
Global Const HWND_NOTOPMOST = -2

'Insert the following code to your form:

Private Sub Command1_Click()
res = SetWindowPos(Form1.hwnd, HWND_TOPMOST, 0, 0, 0, 0, flags)
End Sub

Private Sub Command2_Click()
res = SetWindowPos(Form1.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, flags)
End Sub

Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
This is what I am using.

Call SetWindowPos(frmClipboard.hwnd, HWND_TOPMOST, 0, 0, 500, 200, SWP_NOACTIVATE Or SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE)

where frmclipboard is the name of my form. I do not want the window to be the active window, but this is not working.
 
The above code doesn't seem to work on WIN98. Does anyone know of a different technique
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top