Home » Category » Microsoft Visual Basic

Microsoft Visual Basic: "Always on top"

104| Tue, 04 Dec 2007 11:51:00 GMT| frozen| Comments (7)
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, _
y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE

Private Sub Check1_Click()
If Check1.Value = 1 Then
SetWindowPos Form1.hWnd, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
Else
SetWindowPos Form1.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End If
Settings.CSet "AlwaysOnTop", Check1.Value
End Sub

When I use that code to set my window on top, it works pretty damn good other than when I put the window over my taskbar, it goes behind the taskbar if I click on my it!! :(

Keywords & Tags: always, top, microsoft, visual basic, vb

URL: http://www.programmerbase.com/visual-basic/133/
 
«« Prev - Next »» 7 helpful answers below.
Well the taskbar is a topmost window too. So if you click on it it will go back tothe top instead of your set form. The taskbar has a ssetting to "keep on top of all windows" in its propertiues.

robdog888 | Mon, 03 Dec 2007 17:49:00 GMT |

Only way I can stop this is to disable that setting?

Edit: uploader.ws/upload/200606/bah.png

^^ Why I would like to get it ontop of even the taskbar.

Edit: Yes its the Bandwidth Monitor.

frozen | Mon, 03 Dec 2007 17:50:00 GMT |

Hmm, maybe a bit resource intense but you could call the ontop code in a timer event to restore it if the user clicks on the taks bar.

robdog888 | Mon, 03 Dec 2007 17:51:00 GMT |

Did the trick! Thanks once again.

frozen | Mon, 03 Dec 2007 17:52:00 GMT |

:) glad to help. Does it flicker at all? If it does then its timer interval is set to high. Dont forget to test it on slower machines too. ;)[/color]

robdog888 | Mon, 03 Dec 2007 17:53:00 GMT |

When the timer fires it makes the window the active one out of the rest in the project, but I can deal. :)

You must spread some Reputation around before giving it to RobDog888 again.

Still helping too much I see. :P

frozen | Mon, 03 Dec 2007 17:54:00 GMT |

Darn, and I already cut it down by more then 50% lol.

robdog888 | Mon, 03 Dec 2007 17:55:00 GMT |

Microsoft Visual Basic Hot Answers

Microsoft Visual Basic New questions

Microsoft Visual Basic Related Categories