|
|
|
This is an evergreen, but it's still popular. It is very easy to create a window that always stays on top of the others, thanks to the SetWindowPos API function. Here is a general procedure that can be called to make a form the topmost window and to revert to the normal status. This capability is extremely useful when implementing palettes, tool windows and the like. |
Click here to copy the following block | Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (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
Sub SetTopmostWindow(ByVal hWnd As Long, Optional topmost As Boolean = True) Const HWND_NOTOPMOST = -2 Const HWND_TOPMOST = -1 Const SWP_NOMOVE = &H2 Const SWP_NOSIZE = &H1 SetWindowPos hWnd, IIf(topmost, HWND_TOPMOST, HWND_NOTOPMOST), 0, 0, 0, 0, _ SWP_NOMOVE + SWP_NOSIZE End Sub |
When you wish to create a topmost window simply call this procedure passing the handle of the window: |
When you want to return to the normal status, call the same function passing False as the second argument: |
You do not need to explicitly revert to the normal status before closing the window.
|
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|