NobodyIsPerfect Posted February 7, 2020 Posted February 7, 2020 Hello, I have some troubles using GUISetOnEvent with a "Run" instruction. The "Close" event is never detected: when I click on the "X", nothing happens. There is no error after GUISetOnEvent. Here after is the script. Thanks in advance for your answers. #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Opt("GUIOnEventMode", 1) ;Run process $iPID = Run("Notepad.exe") ;Allow window to initialize... Sleep (500) ;Get HWND. $hWnd = _GetHwndFromPID($iPID) GUISetOnEvent($GUI_EVENT_CLOSE, "OnClose", $hWnd) if @error then MsgBox($MB_SYSTEMMODAL, "GUISetOnEvent", "Error : " & @error & @CRLF & @extended) Exit EndIf ;Wait 15 seconds to let the user click on X Sleep(15000) ;Close notepad WinClose($hWnd) ;Function for getting HWND from PID Func _GetHwndFromPID($PID) $hWnd = 0 $winlist = WinList() Do For $i = 1 To $winlist[0][0] If $winlist[$i][0] <> "" Then $iPID2 = WinGetProcess($winlist[$i][1]) If $iPID2 = $PID Then $hWnd = $winlist[$i][1] ExitLoop EndIf EndIf Next Until $hWnd <> 0 Return $hWnd EndFunc;==>_GetHwndFromPID Func OnClose() MsgBox($MB_SYSTEMMODAL, "Message", "Closing the window.", 10) EndFunc
Subz Posted February 7, 2020 Posted February 7, 2020 GuiOnEvent is for your own guis, not for third-party guis.
Zedna Posted February 7, 2020 Posted February 7, 2020 #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> ;Run process $iPID = Run("Notepad.exe") ;Allow window to initialize... Sleep (500) ;Get HWND. $hWnd = _GetHwndFromPID($iPID) While WinExists($hwnd) Sleep(200) WEnd MsgBox(0, "Info", "Notepad was closed.") ;Function for getting HWND from PID Func _GetHwndFromPID($PID) $hWnd = 0 $winlist = WinList() Do For $i = 1 To $winlist[0][0] If $winlist[$i][0] <> "" Then $iPID2 = WinGetProcess($winlist[$i][1]) If $iPID2 = $PID Then $hWnd = $winlist[$i][1] ExitLoop EndIf EndIf Next Until $hWnd <> 0 Return $hWnd EndFunc;==>_GetHwndFromPID Resources UDF ResourcesEx UDF AutoIt Forum Search
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