anandchakru Posted February 7, 2009 Share Posted February 7, 2009 Hi everyone, I'm a NooB, can you help me figure out how to find when a window is switched. Say I have paint and notepad window opened, paint being active now. I need to take a screen shot before and after the window is switched from paint to notepad !! Thanks, `A [font="Book Antiqua"]Thanks`A[/font] Link to comment Share on other sites More sharing options...
martin Posted February 7, 2009 Share Posted February 7, 2009 (edited) Hi everyone, I'm a NooB, can you help me figure out how to find when a window is switched. Say I have paint and notepad window opened, paint being active now. I need to take a screen shot before and after the window is switched from paint to notepad !! Thanks, `A You can get the active window in a number of different ways. One way is $llastactive = '' While 1 $activeWindow = WinGetTitle("") If $activeWindow <> $lastactive Then If $activeWindow = $PaintTitle Or $lastactive = $NotePAdTitle Then TakeScreenSHot();whatever you use here EndIf $lastactive = $activeWindow EndIf Sleep(100) WEnd which would take a screenshot whenever one of the 2 programs becomes active. EDIT: Welcome to the AutoIt forums anandchakru Edited February 7, 2009 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
sandin Posted February 7, 2009 Share Posted February 7, 2009 taken from siao's example the following script will hook your previous and your current window:expandcollapse popup#include <GuiConstantsEx.au3> #include <Misc.au3> #include <WindowsConstants.au3> #include <ListboxConstants.au3> #Include <SendMessage.au3> Global Const $HSHELL_WINDOWACTIVATED = 4; Global $bHook = 1 Global $previous_hwnd = "", $previous_title = "" Global $current_hwnd = "" Global $tooltip_display1 = "" Global $tooltip_display2 = "" Global $iGuiW = 400, $iGuiH = 50, $sTitle = "Shell Hooker", $aBtnText[2] = ["START", "STOP"] $hGui = GUICreate($sTitle, $iGuiW, $iGuiH, -1, 0, $WS_POPUP+$WS_BORDER, $WS_EX_TOPMOST) GUIRegisterMsg(RegisterWindowMessage("SHELLHOOK"), "HShellWndProc") ShellHookWindow($hGui, $bHook) GUISetState(@SW_HIDE) While 1 Sleep(1000) WEnd Func HShellWndProc($hWnd, $Msg, $wParam, $lParam) Switch $wParam Case $HSHELL_WINDOWACTIVATED Local $win_title = WinGetTitle($lParam) Local $win_handle = $lParam if $previous_hwnd <> "" Then $tooltip_display1 = "Previous window" & @CRLF & "Title: " & $previous_title & @CRLF & "Handle: " & $previous_hwnd & @CRLF $previous_hwnd = $win_handle $previous_title = $win_title $tooltip_display2 = $tooltip_display1 & @CRLF & "Current window" & @CRLF & "Title: " & $win_title & @CRLF & "Handle: " & $win_handle TrayTip("", $tooltip_display2, 30) EndSwitch EndFunc Func ShellHookWindow($hWnd, $bFlag) Local $sFunc = 'DeregisterShellHookWindow' If $bFlag Then $sFunc = 'RegisterShellHookWindow' Local $aRet = DllCall('user32.dll', 'int', $sFunc, 'hwnd', $hWnd) Return $aRet[0] EndFunc Func RegisterWindowMessage($sText) Local $aRet = DllCall('user32.dll', 'int', 'RegisterWindowMessage', 'str', $sText) Return $aRet[0] EndFuncand as for capturing window images if they are not visible (currently on top of the screen), use this: LINK Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll Link to comment Share on other sites More sharing options...
anandchakru Posted February 7, 2009 Author Share Posted February 7, 2009 Thanks martin, for the warm and quick-reponse-welcome sandin thank you. Serves my question perfect !! [font="Book Antiqua"]Thanks`A[/font] Link to comment Share on other sites More sharing options...
notsure Posted February 11, 2009 Share Posted February 11, 2009 taken from siao's example the following script will hook your previous and your current window: expandcollapse popup#include <GuiConstantsEx.au3> #include <Misc.au3> #include <WindowsConstants.au3> #include <ListboxConstants.au3> #Include <SendMessage.au3> Global Const $HSHELL_WINDOWACTIVATED = 4; Global $bHook = 1 Global $previous_hwnd = "", $previous_title = "" Global $current_hwnd = "" Global $tooltip_display1 = "" Global $tooltip_display2 = "" Global $iGuiW = 400, $iGuiH = 50, $sTitle = "Shell Hooker", $aBtnText[2] = ["START", "STOP"] $hGui = GUICreate($sTitle, $iGuiW, $iGuiH, -1, 0, $WS_POPUP+$WS_BORDER, $WS_EX_TOPMOST) GUIRegisterMsg(RegisterWindowMessage("SHELLHOOK"), "HShellWndProc") ShellHookWindow($hGui, $bHook) GUISetState(@SW_HIDE) While 1 Sleep(1000) WEnd Func HShellWndProc($hWnd, $Msg, $wParam, $lParam) Switch $wParam Case $HSHELL_WINDOWACTIVATED Local $win_title = WinGetTitle($lParam) Local $win_handle = $lParam if $previous_hwnd <> "" Then $tooltip_display1 = "Previous window" & @CRLF & "Title: " & $previous_title & @CRLF & "Handle: " & $previous_hwnd & @CRLF $previous_hwnd = $win_handle $previous_title = $win_title $tooltip_display2 = $tooltip_display1 & @CRLF & "Current window" & @CRLF & "Title: " & $win_title & @CRLF & "Handle: " & $win_handle TrayTip("", $tooltip_display2, 30) EndSwitch EndFunc Func ShellHookWindow($hWnd, $bFlag) Local $sFunc = 'DeregisterShellHookWindow' If $bFlag Then $sFunc = 'RegisterShellHookWindow' Local $aRet = DllCall('user32.dll', 'int', $sFunc, 'hwnd', $hWnd) Return $aRet[0] EndFunc Func RegisterWindowMessage($sText) Local $aRet = DllCall('user32.dll', 'int', 'RegisterWindowMessage', 'str', $sText) Return $aRet[0] EndFunc and as for capturing window images if they are not visible (currently on top of the screen), use this: LINK Sandin, is it possible to stop prevent a process from starting before it started, with this code?? Link to comment Share on other sites More sharing options...
sandin Posted February 11, 2009 Share Posted February 11, 2009 with this code? No. This code is about hooking windows (not process). you'll have to find a way to hook process. Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now