|
-
Aug 16th, 2000, 02:46 PM
#1
Thread Starter
New Member
How can a form be kept on top regaurdless of what program or form is in focus?
Thanks,
JohnMB
-
Aug 16th, 2000, 03:12 PM
#2
Code:
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 Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Sub Form_Load()
OnTop Me, True
End Sub
Private Sub OnTop(frm As Form, TopMost As Boolean)
Select Case TopMost
Case True
Call SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
Case False
Call SetWindowPos(Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
End Select
End Sub
-
Aug 16th, 2000, 03:23 PM
#3
Thread Starter
New Member
Thanks, just what I was looking for.
-
Aug 16th, 2000, 03:27 PM
#4
Since the constants are short and readable, you can omit them, causing your code to reduce slightly.
Code:
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 Form_Load()
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3
End Sub
-
Aug 16th, 2000, 04:00 PM
#5
thats good,
but if you forgot to add comments, a few months later when you look at your code, you may not know what you were trying to do,
thats why I always like to use constants.
-
Aug 16th, 2000, 04:05 PM
#6
I've remembered the code for this (and others) for ages and never forgot them. Using contants for values like -1, 3 etc. just doesn't suit me, however, when dealing with numbers like &H1FF01, it's a good idea to use them.
-
Aug 16th, 2000, 04:10 PM
#7
I remember the code for this(and also to drag a form without a title bar, and many other things)
but some people may not.
and I always like to add the constants, because then people will actually know which part of the code does what...
-
Aug 16th, 2000, 04:38 PM
#8
I usually use comments for that:
Code:
'Bring window to top
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3
Again, this is just in my opinion.
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
|