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

How To Keep Your Form/Window On Top

Windows API

How To Keep Your Form/Window On Top

by  percent  Posted    (Edited  )
If you would like to keep your window on top follow these steps - Add this code to your project you will need to add a timer named timer1 and add a checkbox named Check1 set the caption to "Stay On Top" set the timers interval to 1000 - (the lower the interval the quicker the window gets to the top) although 1000 should be fine since it is ever second
'-------------------CODE BELOW-----------------------------

[color green]
Private 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
Const SWP_NOMOVE = 2
Const SWP_NOSIZE = 1
Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2


Private Sub Check1_Click()
If Check1.Value = True Then
Timer1.Enabled = True
ElseIf Check1.Value = False Then
res& = SetWindowPos(me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
Timer1.Enabled = False
End If
End Sub

Private Sub Timer1_Timer()
res& = SetWindowPos(me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
End Sub
[/color]

[color red]
%, 2004
[/color]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top