|
-
Sep 15th, 2001, 04:57 AM
#1
Thread Starter
Member
keeping form on top
hello any one can tell me
how i keep my form on the top of any application
-
Sep 15th, 2001, 06:49 AM
#2
Frenzied Member
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
-
Sep 15th, 2001, 06:56 AM
#3
PowerPoster
Hi
I usually put it in Load event but that is by the by.
also is good idea to add unload event
VB Code:
Private Sub Form_Unload(Cancel As Integer)
SetWindowPos hWnd, Hwnd_NoTopMost, 0, 0, 0, 0, _
Swp_NoMove Or Swp_NoSize
End Sub
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:
'Form1 is main form, Form 2 is sub form
form2.Show vbModeless, Me
regards
Stuart
-
Sep 20th, 2001, 12:06 AM
#4
Fanatic Member
Vlatko,
I tried your code and it doesn't seem to work...
-
Oct 7th, 2001, 09:37 AM
#5
Member
errr
Vlatko, I also tried your code but it just hides my form....it doesnt show up what so ever
-
Oct 7th, 2001, 11:40 AM
#6
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|