Jump to content

j981

Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by j981

  1. This is another simple function I've found to be quite handy. USE CASE: Since chrome v32 and later no longer exposes any standard windows API controls, a huge number of "controlsend" based automation functions I was using against webapps broke. I changed things to bring those windows to the foreground instead to send keys and then minimize them again (with the _SendToBottom function I just posted as well), but with the standard 'winactivate' it took too long. This function basically just reduces the winwaitdelay temporarily, but it also disables the automatic flashing of windows in the taskbar which occurs if you activate windows too rapidly, which was extremely annoying. It's not particularly useful if you just want to bring something to the foreground to actively work with, but if the goal is to activate something solely to send a key and then minimize again, it speeds things up quite a bit since it happens almost instantly. Hopefully someone else also finds this useful. #include <WinAPI.au3> $handle = WinGetHandle("Some window you would like to activate") _FastActivate($handle) Func _FastActivate($hWnd) Opt("WinWaitDelay", 20) WinActivate($hWnd) WinWaitActive($hWnd,"",4) _WinAPI_FlashWindowEx($hWnd,0,0,0) Opt("WinWaitDelay", 250) EndFunc
  2. I had a need to change the z-order of windows and their position in the "alt-tab" list. I spent quite a long time trying to figure out how to make it happen, so I thought I'd post this snippet back since I finally came up with a workable solution. USE CASE: I bring music applications to the foreground while I'm working/etc via a hotkey. I then press the hotkey again in order to minimize the program. When I did that, however, my alt-tab order was then modified so that I couldn't continue to "alt-tab" between active windows I was working on, which is a distraction that hurt my workflow. I wanted a way to set a window to the back of the alt-tab list and also to change the z-order of a window (two different problems, as it turned out). I've used this with Windows 8.1. I'm not sure if "WinWaitDelay" is applicable to WinSetState operations. I just have it there for good measure. The _WinAPI_FlashWindowEx bit is needed sometimes to prevent windows from automatically flashing the newly un-hidden window. Also, two ancillary functions are used in order to ensure that a different window is active than the one that is to be sent to the back, since this doesn't seem to work right unless that is the case. #include <WinAPI.au3> $handle = WinGetHandle("A window which you would like to send to the back of all other windows") _SendToBottom($handle) Func _LastWindowTitle($z = 1) If $z < 1 Then Return SetError(1, 0, 0) ; Bad parameter Local $avList = WinList() For $n = 1 to $avList[0][0] If $avList[$n][0] <> "" And BitAND(WinGetState($avList[$n][1]), 2) Then If $z Then $z -= 1 Else Local $arr = [$avList[$n][0],$avList[$n][1]] Return $arr EndIf EndIf Next Return SetError(2, 0, 0) ; z-depth exceeded EndFunc Func _FastActivate($hWnd) Opt("WinWaitDelay", 20) WinActivate($hWnd) WinWaitActive($hWnd,"",4) _WinAPI_FlashWindowEx($hWnd,0,0,0) Opt("WinWaitDelay", 250) EndFunc Func _SendToBottom($hWnd) Local Const $HWND_BOTTOM = 1; Opt("WinWaitDelay", 20) Local $active = WinGetHandle("[ACTIVE]") Local $lastWindow = _LastWindowTitle() Local $lastHandle = $lastWindow[1] If Not ($hWnd <> $active) Then If (WinExists($lastHandle)) Then _FastActivate($lastHandle) EndIf EndIf DllCall("user32.dll", "long", "SetWindowPos", "uint", $hWnd, "uint", $HWND_BOTTOM , "int", 0, "int", 0, "int", 0, "int", 0 , "uint", 0x13) WinSetState($hWnd,"",@SW_MINIMIZE) WinSetState($hWnd,"",@SW_HIDE) WinSetState($hWnd,"",@SW_SHOW) ;disable the taskbar flashing that sometimes occurs when hiding and showing windows... _WinAPI_FlashWindowEx($hWnd,0,0,0) Opt("WinWaitDelay", 250) EndFunc
×
×
  • Create New...