|
-
Apr 4th, 2001, 04:14 AM
#1
How do I reset the "Always on top" property of a window owned by an external application.?.. Maybe finding the hwnd of the window may do the trick.. but how?
-
Apr 4th, 2001, 04:58 AM
#2
Fanatic Member
you could use the SetWindowPos API with the HWND_NOTOPMOST constant:
Code:
Option Explicit
' SetWindowPos Function
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
' SetWindowPos Flags
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Sub Command1_Click()
'replace Me.hWnd with the hWnd of the window you want to move here
'NB you may encounter problems with dialog boxes, or other windows that REALLY don't want to move
'from the top
Call SetWindowPos(Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, _
SWP_NOSIZE Or SWP_NOMOVE)
Unload Me
End Sub
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Apr 4th, 2001, 04:59 AM
#3
Frenzied Member
Code:
Dim h as Long
h = FindWindow("classname","titlebartext");
SetWindowPos h, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_FRAMECHANGED Or SWP_NOMOVE
-
Apr 5th, 2001, 01:57 AM
#4
unfortunately the window does not have a titlebar 
what is classname ?
-
Apr 5th, 2001, 02:34 AM
#5
PowerPoster
Use the Spy++ utility to find the class name.
-
Apr 5th, 2001, 02:50 AM
#6
Lively Member
-
Apr 5th, 2001, 03:02 AM
#7
PowerPoster
Code:
Const HWND_BOTTOM = 1
Const HWND_NOTOPMOST = -2
Const HWND_TOP = 0
Const HWND_TOPMOST = -1
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
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
Sub MakeWindowAlwaysTop(hwnd As Long)
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
End Sub
Sub MakeWindowNotTop(hwnd As Long)
SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
End Sub
Private Sub Form_Load()
MakeWindowAlwaysTop Me.hwnd
End Sub
-
Apr 5th, 2001, 10:32 AM
#8
PowerPoster
Originally posted by anoop007
unfortunately the window does not have a titlebar 
what is classname ?
If you don't know the class name, you can always use null as the parameter
-
Apr 5th, 2001, 02:41 PM
#9
don't you mean NullString? (constant is vbNullString)
-
Apr 5th, 2001, 09:25 PM
#10
PowerPoster
Yes, I did mean NullString. Btw, can I pass 0& instead of vbNullString?
-
Apr 5th, 2001, 11:18 PM
#11
Lively Member
thanks Lethal. great help
a follow up question is, what is the best way to control this form that is always on top so as when my main form (an MDI Form) is not in focus, let's say minimized or a new application is in use, this AlwaysOnTop Form would no longer be always on top?
thanks again
-
Apr 5th, 2001, 11:50 PM
#12
PowerPoster
Well, just whenever u would not want the form to be set as always on top, in your code, call the MakeWindowNotTop Procedure and Vice Versa.
-
Apr 6th, 2001, 07:30 AM
#13
PowerPoster
You can try that even, but I am not sure it will work.
You can do one thing. Search in the forums for the code to know all displayed windows on the desktop. Once you know all the handles, you can get the caption of each window. This way, I think you can get to know the handle of the ad bar.
Spy ++ is a utility provided with the enterprise edition of Visual Studio. You may even search msdn web site msdn.microsoft.com for the program. They might be giving out for free.
-
Apr 6th, 2001, 08:29 AM
#14
Fanatic Member
If you want to get rid of an address bar just delete the GUID from the registry....(it's not nice I know, but thats the way I did it)
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Apr 6th, 2001, 08:39 AM
#15
PowerPoster
What he is talking about is not the address bar, but a advertising window bar which remains on top all the time.
BTW, anoop007, If you d find the code for getting the handles to all the displayed window, do post a link here.
-
Apr 6th, 2001, 01:25 PM
#16
-
Apr 7th, 2001, 06:29 AM
#17
you can pass a zero two ways: Vbnull or 0&
to have your form on top only when it has focus, that will be taken care of when it's minimized so you dont have to worry about that. When it loses focus, give it normal z-order. When it gains focus, set it on top again.
BTW the 4 zeros are the x and y top and the width and height of the form. You can use this function to set your window size.
-
Apr 7th, 2001, 08:48 PM
#18
That spy utility was cool..
it served the purpose...
thanks
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
|