Atlanta Custom Software Development 

   Search        Code/Page

User Login



Forgot the Password?
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
» Regular Expr Tester
» Free Tools

Topmost windows

Total Hit ( 1618)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article



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_TOPMOST = -1
  Const SWP_NOMOVE = &H2
  Const SWP_NOSIZE = &H1
  SetWindowPos hWnd, IIf(topmost, HWND_TOPMOST, HWND_NOTOPMOST), 0, 0, 0, 0, _
End Sub

When you wish to create a topmost window simply call this procedure passing the handle of the window:

Click here to copy the following block
SetTopmostWindow Me.hWnd

When you want to return to the normal status, call the same function passing False as the second argument:

Click here to copy the following block
SetTopmostWindow Me.hWnd, False

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, SQL Server and other MS technologies. He is, 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 )

Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.