|
-
Oct 29th, 2001, 02:30 AM
#1
Thread Starter
Addicted Member
Always on top...
Hi,
Does anyone knows how i can make my form always on top.
pls show me some codes.
Thanks in advance.
-
Oct 29th, 2001, 03:25 AM
#2
Frenzied Member
Your welcome. :D
All you need to do is plop this code into a module.
Code:
Option Explicit
#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
Sub KeepOnTop(F As Form, Enabled As Boolean)
Const SWP_NOMOVE = 2
Const SWP_NOSIZE = 1
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
If Enabled Then
SetWindowPos F.hWnd, -1, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
Else
SetWindowPos F.hWnd, -2, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End If
End Sub
If you want to make a form "always on top", you just do this
Code:
Private Sub Command1_Click()
Call KeepOnTop(Me, True)
End Sub
And if you want to disable a form's always on top setting, just,
Code:
Private Sub Command1_Click()
Call KeepOnTop(Me, False)
End Sub
Your welcome, and you need help with anything else, my email adress is [email protected]. Have a good one, dude, later. 
OH! One more thing, you can join a cool club i started. You just need to submit some code. CHeck it out here.
-
Oct 29th, 2001, 04:34 AM
#3
Thread Starter
Addicted Member
Always on Top MDI problem
Hi,
i tried your code but it wont work if the form is a child of an MDI form. how can i resolve this.
pls reply. thanks.
-
Oct 29th, 2001, 07:26 AM
#4
If you don't specify, the folks in this forum will assume that you are using VB, NOT VBA, and that you are dealing with standard forms, NOT MDI forms. Try this
VB 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
Call SetWindowPos(hwnd, -1, 0, 0, 0, 0, 3) - Makes the window topmost
Call SetWindowPos(hwnd, 1, 0, 0, 0, 0, 3) - Makes the window normal
I do not know if this will work with MDI as I never, ever use that, but give it shot.
-
Nov 3rd, 2001, 12:13 PM
#5
Frenzied Member
OK, i am really sorry about this, but i dont know what i can tell you. MDI is a bit weird. The SetWindowPos API dosent seem to have ANY affect at ALL.
So you have a series of options.
[list=1]
Stop using MDI
Find an API call specifically for SetWindowPos MDI style
Or find a way to use the plain old setwindowpos API call.[/list=1]
But, you might as well, store my code somewhere. Have a good one dude, i'm shoving off to go tinker with random chunks of code.
Have a good one!
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
|