Jump to content

Windows Change event


Recommended Posts

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

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 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

taken from siao's example the following script will hook your previous and your current window:

#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

Link to comment
Share on other sites

taken from siao's example the following script will hook your previous and your current window:

#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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...