hello any one can tell me
how i keep my form on the top of any application
Printable View
hello any one can tell me
how i keep my form on the top of any application
VB Code:
Const HWND_TOPMOST = -1 Const HWND_NOTOPMOST = -2 Const SWP_NOSIZE = &H1 Const SWP_NOMOVE = &H2 Const SWP_NOACTIVATE = &H10 Const SWP_SHOWWINDOW = &H40 Private Declare Sub 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) Private Sub Form_Activate() 'Set the window position to topmost SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE End Sub
Hi
I usually put it in Load event but that is by the by.
also is good idea to add unload event
When u do the ontop code it will keep the form on top of all apps which is what u wanted but if you want a 'sub form' in ur app to be always on top (eg Help) and follow the main form if minimized then you should Show the form as follows (still using the same APIs)VB Code:
Private Sub Form_Unload(Cancel As Integer) SetWindowPos hWnd, Hwnd_NoTopMost, 0, 0, 0, 0, _ Swp_NoMove Or Swp_NoSize End Sub
regardsVB Code:
'Form1 is main form, Form 2 is sub form form2.Show vbModeless, Me
Stuart
Vlatko,
I tried your code and it doesn't seem to work...
Vlatko, I also tried your code but it just hides my form....it doesnt show up what so ever :confused:
Try this:
VB Code:
Private Declare Sub 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) Private Sub Form_Load() SetWindowPos hWnd, -1, 0, 0, 0, 0, 3 End Sub