Shane0000 Posted September 26, 2014 Share Posted September 26, 2014 I am having an odd problem, If I run the below, the program hangs just before it ConsoleWrites the result of the WinGetHandle _IEAction($oIE, "printdefault") ConsoleWrite(@CRLF & 'Wait ') Local $hWnd = WinGetHandle("Save PDF File As") While Not $hWnd $hWnd = WinGetHandle("Save PDF File As") ConsoleWrite(@CRLF) sleep(150) ConsoleWrite($hWnd) WEnd ConsoleWrite(@CRLF & $hWnd) ConsoleWrite(' WinExists' & @CRLF) the above results in : wait 0X00000000 0x00000000 and then hangs as soon as the "Save PDF ..." window opens. If I stop the autoit script and run just the GetWinHandle section I get: Wait 0x003B1870 WinExists Does some one know why the same code behaves differently when ran after an _IECreateEmbedded? Link to comment Share on other sites More sharing options...
Shane0000 Posted September 26, 2014 Author Share Posted September 26, 2014 (edited) Meh, for some reason switching out ConsoleWrite(@CRLF) w/ ConsoleWrite(@error) resolved the issue ..... ? And then Not working again ..... If I cancel the 'Save PDF as' dialog box and the reinitate the 'Save PDF' dialog autoit will find the winhandle and proceed until the next loop where as it again repeats this problem of hanging just before returning a valid winhandle Edited September 26, 2014 by Shane0000 Link to comment Share on other sites More sharing options...
someone Posted September 26, 2014 Share Posted September 26, 2014 Hey I think you are making this a little harder on yourself then you need to..let me know if this works for you #include <IE.au3> $oIE = _IECreate() _IEAction($oIE, "printdefault") WinWait("Save PDF File As") $handle = WinGetHandle("Save PDF File As") MsgBox(0, "", $handle) While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd Link to comment Share on other sites More sharing options...
Shane0000 Posted September 26, 2014 Author Share Posted September 26, 2014 (edited) Ive have tried winwait also but hang also. thats how I had it originally until I need this loop to debug what was going on The odd thing is that the loop searches, prints 0x00000000 until a title match is made The loop stops but the script does not exit the loop and does not return the hwnd (it just sits inside this loop inactive ....) **If I close the window that caused the loop to stop (but not exit) the loop resumes printing 0x00000000 ** If I then open the dialog box manually, The loop finds the title match, exits the loop, and I have my hwnd The next loop may or maynot succeed , it seems to be near random leaning mostly to the never works as expected side Edited September 26, 2014 by Shane0000 Link to comment Share on other sites More sharing options...
someone Posted September 26, 2014 Share Posted September 26, 2014 Why are you doing a loop in the first place? WinWait will wait (until timeout) for the window to exist, the loop to grab the handle isn't needed. While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd Link to comment Share on other sites More sharing options...
someone Posted September 26, 2014 Share Posted September 26, 2014 This also works reliably for me $oIE = _IECreate() _IEAction($oIE, "printdefault") Do Sleep(250) $hWnd = WinGetHandle("Save PDF File As") Until Not @error MsgBox(0, "", $hWnd) While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd Link to comment Share on other sites More sharing options...
Shane0000 Posted September 26, 2014 Author Share Posted September 26, 2014 (edited) #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <File.au3> #include <Array.au3> #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IECreateEmbedded() GUICreate("Embedded Web control Test", 640, 580, _ (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _ $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) GUICtrlCreateObj($oIE, 10, 40, 600, 360) Global $GUI_Button_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30) Global $GUI_Button_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30) Global $GUI_Button_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30) Global $GUI_Button_Stop = GUICtrlCreateButton("Stop", 340, 420, 100, 30) Global $GUI_Error_Message = GUICtrlCreateLabel("", 100, 500, 500, 30) GUICtrlSetColor(-1, 0xff0000) GUISetState(@SW_SHOW) ;Show GUI _IENavigate($oIE, "autoitscript.com") _IEAction($oIE, "stop") _IEAction($oIE, "printdefault") ConsoleWrite(@CRLF & 'Wait ') Local $hWnd = WinGetHandle("Save PDF File As") While Not $hWnd $hWnd = WinGetHandle("Save PDF File As") ConsoleWrite(@error) sleep(150) ConsoleWrite($hWnd & @crlf) WEnd ConsoleWrite(@CRLF & $hWnd) ConsoleWrite(' WinExists' & @CRLF) ControlSend($hWnd, "", "Edit1", 'This file name ') Edited September 26, 2014 by Shane0000 Link to comment Share on other sites More sharing options...
Shane0000 Posted September 26, 2014 Author Share Posted September 26, 2014 The above will reproduce the error.... as for the loops , I am printing a series of pages from IE, the wingethandle loop is there so I can see why the winwait = method didnt work and just hung the script the above code works some times, and some times it hangs as explained Link to comment Share on other sites More sharing options...
Shane0000 Posted September 26, 2014 Author Share Posted September 26, 2014 Like I said what is really puzziling me is how/why the scrip hangs in that loop after autoit get the title match the only reason that loop should stop is because I have a hWnd If I have a hWnd the loop should exit There should be no reason for the loop to resume but it does after hanging if I manually reopen the print dialog there is no code to tell it to either pause or resume the loop How is it that the loop stops but does not exit ........... Link to comment Share on other sites More sharing options...
someone Posted September 26, 2014 Share Posted September 26, 2014 There is something a little funny about your code, but it works for me by removing the stop command and increasing your sleep a little to 250. But I still don't understand why you are doing this, I gave you a non loop and a looping method that work. Non loop #include <IE.au3> $oIE = _IECreate() _IEAction($oIE, "printdefault") $hWnd = WinWait("Save PDF File As") ControlSend($hWnd, "", "Edit1", 'This file name ') Loop $oIE = _IECreate() _IEAction($oIE, "printdefault") Do Sleep(250) $hWnd = WinGetHandle("Save PDF File As") Until Not @error ControlSend($hWnd, "", "Edit1", 'This file name ') I have run it a bunch of times on my Win 7x64 box running IE8. While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd Link to comment Share on other sites More sharing options...
Shane0000 Posted September 26, 2014 Author Share Posted September 26, 2014 Meh I still get the same issue where the majority of the time this simple loop sits in purgatory stuck some where between finding a wintitle match and then Returning a hWnd and exit the loop like i said , if the loop stops printing 0x0000000 then its found its match and there is no reason in my code that the loop should pause and not exit with a hwnd, there is no reason the loop should continue if I close the 'Save PDF As' dialog box and resume spitting out 0x00000000 The loop states go until X happens, why should the loop pause (not exit) when X happens? The loop states Exit if I have a hwnd else print 0x000000000 Why does the loop do NEITHER of these when the 'Save As PDF' dialog opens? This happens with Hwnd = winwait, wingethandle, do until loops, while loops Link to comment Share on other sites More sharing options...
Shane0000 Posted September 26, 2014 Author Share Posted September 26, 2014 because i tested them and reported back that i have tried them and experience thew same results The sleep should have little to do with the loop not exiting once its condition has been met the sleep i wouldnt think would have an effect in a loop pausing and resuming with no code on my behalf to accomplish this behavior I am unsure of why $hwnd = Winwait('mytitle') hangs and as stated above this is why I switched to a loop so that I could try to determine the issue that is causing this odd behavior Link to comment Share on other sites More sharing options...
Solution jdelaney Posted September 26, 2014 Solution Share Posted September 26, 2014 (edited) The window is modal, meaning your script is waiting for it to close prior to continuing to the next line. Example of starting another process to open the window, so your script may proceed...there are probably menu functions you can use instead, to not require such extreme measures: #include <IE.au3> If UBound($CmdLine)=2 Then $oIE = _IEAttach(HWnd($CmdLine[1]),"HWND") _IEAction($oIE, "print") Exit Else $oIE = _IECreate() $hParent = _IEPropertyGet($oIE, "HWND") Run(@AutoItExe & " /AutoIt3ExecuteScript " & @ScriptFullPath & " " & HWnd($hParent)) ConsoleWrite($hParent & @CRLF) MsgBox(1,1,"enter script to interact with window, here") EndIf Just to clarify, the winwait function is NOT 'hanging', you are just waiting on a return from the _IEAction. Edited September 26, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Shane0000 Posted September 26, 2014 Author Share Posted September 26, 2014 (edited) Ok I had to get rid of the embedded control because I couldnt find a way for the helper program to attach to it. Thank you JDelaney for shedding some insight as to why the program was waiting. I had to give up the embedded IE but it wasnt really important. Thank you guys expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <File.au3> #include <Array.au3> #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IECreate() $oIE_hWnd = _IEPropertyGet($oIE, "HWND") ConsoleWrite(@error & @CRLF) ConsoleWrite($oIE_hWnd & @CRLF) ;$hGui = GUICreate("Embedded Web control Test", 640, 580, _ ;(@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _ ; $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) ;ConsoleWrite(@error & @CRLF) ;ConsoleWrite($hGui & @CRLF) ;$ctrlIE = GUICtrlCreateObj($oIE, 10, 40, 600, 360) ;Global $GUI_Button_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30) ;Global $GUI_Button_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30) ;Global $GUI_Button_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30) ;Global $GUI_Button_Stop = GUICtrlCreateButton("Stop", 340, 420, 100, 30) ;Global $GUI_Error_Message = GUICtrlCreateLabel("", 100, 500, 500, 30) ;GUICtrlSetColor(-1, 0xff0000) ;GUISetState(@SW_SHOW) ;Show GUI _IENavigate($oIE, "autoitscript.com") _IEAction($oIE, "stop") ;$oIE_hWnd = ControlGetHandle ( "Embedded Web control Test", "", $ctrlIE ) ;$oIE_hWnd = _IEPropertyGet($oIE, "HWND") ;ConsoleWrite(@error & @CRLF) ;ConsoleWrite($oIE_hWnd & @CRLF) run(@ScriptDir & "\IE_PrintDefault_0.01.exe " & $oIE_hWnd) ;_IEAction($oIE, "printdefault") ConsoleWrite(@CRLF & 'Wait ') Local $hWnd = WinGetHandle("Save PDF File As") ;While Not $hWnd ; $hWnd = WinGetHandle("Save PDF File As") ; ConsoleWrite(@error) ; sleep(150) ; ConsoleWrite($hWnd & @crlf) ;WEnd Do Sleep(250) $hWnd = WinGetHandle("Save PDF File As") Until Not @error ConsoleWrite(@CRLF & $hWnd) ConsoleWrite(' WinExists' & @CRLF) ControlSend($hWnd, "", "Edit1", 'This file name ') IE_Printdefault.exe #include <IE.au3> If UBound($CmdLine)> 0 Then $oIE = _IEAttach(HWnd($CmdLine[1]),"HWND") If @error Then MsgBox(0,'IE Attach Error', @error & @CRLF & @extended) _IEAction($oIE, "printdefault") If @error Then MsgBox(0,'IE_Action Error', @error & @CRLF & @extended) Exit EndIf Edited September 26, 2014 by Shane0000 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