|
Keep a window always on top |
|
|
|
|
Source Codes -
Visual Basic
|
|
Written by Thomas Kaloyani
|
|
Saturday, 08 April 2006 |
if you have an application and you want to keep it always on top of other windows.
this is an easy way to do it.
Usage:
To keep your form always on top call the
SetWindowOnTop Me, True
and to deactivate the always on top of other windows change the bAlwaysOnTop flag to false.
SetWindowOnTop Me, False
Declarations:
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
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
Code:
Private Sub SetWindowOnTop(f As Form, bAlwaysOnTop As Boolean)
Dim iFlag As Long
iFlag = IIf(bAlwaysOnTop, HWND_TOPMOST, HWND_NOTOPMOST)
SetWindowPos f.hwnd, iFlag, f.Left / Screen.TwipsPerPixelX, f.Top / Screen.TwipsPerPixelY, _
f.Width / Screen.TwipsPerPixelX, f.Height / Screen.TwipsPerPixelY, SWP_NOACTIVATE Or SWP_SHOWWINDOW
End Sub
About the author: Thomas is an experienced Visual Basic developer, with expertise of 7+ years developing especially financial applications. His main IT skills are VB, SQL, Crystal Reports - should you need a Visual Basic developer for your projects feel free to contact Thomas through his personal website at www.Kaloyani.com
Source: www.VBprofs.com |