-
March 6th, 2011, 11:57 PM
#1
Force some other or a chosen application window to bottom
Hello all, I used to script alot, but it has been years now..anyways, what I need to know, is the proper way in VBS or VB 6, to set or force a chosen applications' window to be BOTTOM all the time, esentially stay behind all other windows...all apps open in front of it. And it is not my app I need to do this with, that's why I need to know how to force someone else windows program to be bottom...I am using a shell replacement written by another company, and I need to force it to always be bottom..hope that makes sense. I believe I can get the program shells real window name using the I beleve spyxx.exe function in VB six...If I could rap an executable that I coud just run on login, with code that does this, that would be awesome...any help is greatly appreciated.
-
March 7th, 2011, 12:22 AM
#2
Re: Force some other or a chosen application window to bottom
Not really, other than to check constantly
-
March 7th, 2011, 01:29 AM
#3
Re: Force some other or a chosen application window to bottom
so it is a tall order to force an application to always be the furthest back? Ack....So no way at all?
-
March 7th, 2011, 02:01 AM
#4
Re: Force some other or a chosen application window to bottom
you could always use the SetWindowPos API function, in a Timer event.
-
March 7th, 2011, 03:01 AM
#5
Re: Force some other or a chosen application window to bottom
Ya, SetWindowPos has that optional constant.
You can respond to changes in an event hook.
In a module:
Code:
Const OB_REORDER As Long = 32772 '-- hwnd + ID + idChild is parent of zordering children
Const WINEVENT_SKIPOWNPROCESS As Long = 2
Const SYS_FOREGROUND As Long = 3 'active window changing.
Const EVENT_MIN As Long = 1
Const EVENT_MAX As Long = 2147483647
Private Declare Function apiSetWinEventHook Lib "user32" Alias "SetWinEventHook" (ByVal eventMin As Long, ByVal eventMax As Long, ByVal hmodWinEventProc As Long, ByVal pfnWinEventProc As Long, ByVal idProcess As Long, ByVal idThread As Long, ByVal dwFlags As Long) As Long
Private Declare Function apiUnhookWinEvent Lib "user32" Alias "UnhookWinEvent" (ByVal lHandle As Long) As Long
Private eHook As Long
Public Sub HookEvents()
If eHook <> 0 Then Exit Sub
eHook = apiSetWinEventHook(SYS_FOREGROUND, SYS_FOREGROUND, 0, AddressOf WinEventFunc, 0, 0, WINEVENT_SKIPOWNPROCESS)
End Sub
Public Sub UnHookEvents()
If eHook <> 0 Then
Dim r As Long
r = apiUnhookWinEvent(eHook)
If r <> 0 Then eHook = 0
End If
End Sub
Private Function WinEventFunc(ByVal eHandle As Long, ByVal LEvent As Long, ByVal hwnd As Long, ByVal objId As Long, ByVal childId As Long, ByVal eThreadId As Long, ByVal eTime As Long) As Long
On Error Resume Next
If LEvent = SYS_FOREGROUND Then
'SetWindowPos(
Beep
End If
WinEventFunc = 0
End Function
-
March 7th, 2011, 12:57 PM
#6
Re: Force some other or a chosen application window to bottom
Originally Posted by staverts
so it is a tall order to force an application to always be the furthest back? Ack....So no way at all?
Well, uses may not like you hooking into their system. Be careful running those, as well.
-
March 8th, 2011, 08:53 AM
#7
Re: Force some other or a chosen application window to bottom
This is the SetWindowPos function and related constants: (It should wotk completely without hooking).
Code:
Public Declare Function SetWindowPos Lib "user32" ( _
ByVal hWnd As Long, _
ByVal hWia As Long, _
ByVal X As Long, ByVal Y As Long, _
ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long _
) As Long
Public Const SWP_NoSize = 1&
Public Const SWP_NoMove = 2&
Public Const SWP_NoZOrder = 4&
Public Const SWP_NoOwnerZOrder = &H200
Public Const SWP_FrameChanged = &H20
Public Const HWND_Top = 0&
Public Const HWND_Bottom = 1&
Public Const HWND_TopMost = -1&
Public Const HWND_NoTopMost = -2&
You need a call like
Code:
SetWindowPos AppshWnd, HWND_Bottom, 0, 0, 0, 0, SWP_NoSize + SWP_NoMove
You need the apps hWnd to do this.
If you havent that one there are more complicated methods to obtain it, like enumerating windows and matching the text in the title bar, or by knowing the ProcessID.
-
March 8th, 2011, 08:18 PM
#8
Re: Force some other or a chosen application window to bottom
Well the OP mentioned "all the time", in which case you would need the timer poll, or event/message hook to do properly.
-
March 9th, 2011, 12:23 PM
#9
Re: Force some other or a chosen application window to bottom
I see. You want to capture any message which would send the app back to foreground.
Hm... to avoid hooking, another method would be to call setwindowpos again every second or so, controlled by a timer. (?)
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
|