Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Advanced
Aug 7, 1998

Make a Form Stay on Top

You can make a form always remain above others, even when it does not have focus. Use this code in a BAS module:

 #If Win16 Then
	Declare Sub SetWindowPos Lib "User" ( _
		ByVal hWnd As Integer, _
		ByVal hWndInsertAfter As Integer, _
		ByVal X As Integer, ByVal Y As Integer, _
		ByVal cx As Integer, ByVal cy As Integer, _
		ByVal wFlags As Integer)
#Else
	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
#End If
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2

Use this code to make the form stay on top in the form module:

 SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
	SWP_NOMOVE + SWP_NOSIZE

Use this code to make the form no longer stay on top in the form module:

 SetWindowPos Parent.hwnd, HWND_NOTOPMOST, _
	 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE

In 16-bit systems, use the 16-bit equivalents.

Rod Stephens
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date