|
-
Dec 22nd, 2001, 12:58 PM
#1
Always On Top?
How do I make a form stay on top (visible) on the screen while another window has the focus (the other windows bar is colored and my form is grayed out)...
Also how would I get the windows id (hwnd, or something of that nature) from my form.
Third and finally, how do I send text (or keypreeses if you can't do text) to the window with focus?
ThankS!
NOMAD
-
Dec 22nd, 2001, 01:23 PM
#2
Hyperactive Member
1-
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)
VB Code:
'this code makes the window stay on top
rtn = SetWindowPos(OnTop.hwnd, -1, 0, 0, 0, 0, 3)
'window will not stay on top with this code
rtn = SetWindowPos(OnTop.hwnd, -2, 0, 0, 0, 0, 3)
-
Dec 22nd, 2001, 01:26 PM
#3
Addicted Member
To have the form appear on top always you'll have to use the "SetWindowPos" API. Here's the 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()
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Knowledge is static .... understanding is Dynamic
-
Dec 22nd, 2001, 08:07 PM
#4
Frenzied Member
I built that into a DLL so you can just use it without having to code anything. Just pass in the form name.
~Peter

-
Dec 22nd, 2001, 08:19 PM
#5
You do no really need a DLL for 10 lines of code...
-
Dec 22nd, 2001, 08:21 PM
#6
Frenzied Member
It's just a suggestion, and maybe he can find something else in the DLL useful.
~Peter

-
Dec 28th, 2001, 06:44 PM
#7
Addicted Member
How can i de-activate the always on top thing from hamins code?
Sorry im still a newbie
-
Dec 28th, 2001, 06:48 PM
#8
Hyperactive Member
Look at my post above.
There is the code for cancelling always on top
-
Dec 28th, 2001, 06:55 PM
#9
Addicted Member
O yeh thanks joijo
-
Dec 28th, 2001, 06:58 PM
#10
Frenzied Member
Module
Just plop this into a module! :-D
VB Code:
'====================================================
'====This code was written by joijo and macai=======
'====Use this code freely, but please leave the=======
'====comments. And credit would be nice, too. *wink*====
'====================================================
'Declarations
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)
'Actual Code
Public Sub AlwaysOnTop(F As Form, Enabled As Boolean)
If Enabled Then 'If the programmer wants the form on top.
SetWindowPos F.hwnd, -2, 0, 0, 0, 0, 3
Else 'If the programmer does want the form on top.
SetWindowPos F.hwnd, -1, 0, 0, 0, 0, 3
End If
End Sub
Me and jojo put that together a while back.
-
Dec 28th, 2001, 09:13 PM
#11
'====================================================
'====This code was written by joijo and macai=======
'====Use this code freely, but please leave the=======
'====comments. And credit would be nice, too. *wink*====
'====================================================
About vbworld.com example look like that... and how can you have credit on a Sub that you just do copy and paste
-
Dec 28th, 2001, 09:22 PM
#12
Frenzied Member
DaoK
DaoK, that was from an old thread. I just copied and pasted the
module i have..
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
|