Recent Posts

Wednesday, April 9, 2008

Set Window OnTop in VB 6 Application

Get free code to get your vb 6 application form to sit on top of other forms in your application. 
This code will be very helpful for most of the visual basic softwares. Even you can modify the code and use it in vb net , asp net or c# net applications. 

' Declarations

Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40

' declaring the api 

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



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


'call the function on form load from vb application
SetWindowOnTop Me, True

' True in the end of the function puts the window on top of other forms

Related Posts by Categories




1 comment:

Anonymous said...

THis article is good.

Post a Comment