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?
Printable View
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?
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
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
unfortunately the window does not have a titlebar :(
what is classname ?
Use the Spy++ utility to find the class name.
:p
Instead of wanting to take away the Always on Top property, is it possible to make a Form 'always on top', something like the tool boxes in Adobe Photoshop.
Thank You. :D
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
If you don't know the class name, you can always use null as the parameterQuote:
Originally posted by anoop007
unfortunately the window does not have a titlebar :(
what is classname ?
don't you mean NullString? (constant is vbNullString)
Yes, I did mean NullString. Btw, can I pass 0& instead of vbNullString?
:p
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
;)
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.
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.
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)
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.
Hi
I downloaded a spy program from http://www.planetsourcecode.com/ and it's excellent. It's drag'n drop with treeview and it can even generate the code for topmostwindow, parentwindow and currentwindow. :)
Regards, Xdream
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.
That spy utility was cool..
it served the purpose...
thanks