Guest Posted May 13, 2014 Share Posted May 13, 2014 (edited) Hello, I created a function like _IECreateEmbedded but the difference is that my function should support the latest internet explorer version that installed on the computer. I tested this function here: '?do=embed' frameborder='0' data-embedContent>> And now after some repairs and improvements, I think that the code works stable. this is the example+UDF: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #include <WinAPIEx.au3> #include <IE.au3> #Include <Array.au3> Example("http://www.autoitscript.com/forum/topic/161333-newiecreatepseudoembedded-create-embedded-ie-frame-with-latest-ie-version/?p=1171158") Func Example($Url) Local $Form1 , $Close_Button , $IECreatePseudo , $oIE , $aMain , $nMsg , $IELoaded , $IEpid , $IEhandle Local $ActiveURL = $Url , $Open_Button , $o_Shell , $o_ShellWindows , $Founnd_Url , $OpenButtonSate #region ### START Koda GUI section ### Form= $Form1 = GUICreate("", 915, 664) $Close_Button = GUICtrlCreateButton("Close", 488, 632, 89, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Open_Button = GUICtrlCreateButton("Open in browser", 328, 632, 105, 25) GUICtrlSetState (-1,$GUI_DISABLE) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW,$Form1) ;~ WinSetOnTop($Form1, "", 1) Local $IEWidth = 897 , $IEHeight = 617 $IECreatePseudo = _NewIECreatePseudoEmbedded($Url, $Form1, 8, 8, 897, 617) If IsArray($IECreatePseudo) And IsObj($IECreatePseudo[0]) Then $oIE = $IECreatePseudo[0] $IEpid = $IECreatePseudo[1] $IEhandle = $IECreatePseudo[2] GUICtrlSetState($Open_Button,$GUI_ENABLE) $OpenButtonSate = 1 $IELoaded = 1 ;~ _IEAction($oIE, "focus" ) ; http://msdn.microsoft.com/en-us/library/ms970456.aspx $oIE.StatusBar = True $oIE.Focus() EndIf #endregion ### END Koda GUI section ### ;~ WinSetOnTop($Form1, "", 1) While 1 If $IELoaded = 1 Then If $oIE.LocationURL <> $ActiveURL Then If StringLeft($oIE.LocationURL,4) = "http" Then $ActiveURL = $oIE.LocationURL If $OpenButtonSate = 0 Then GUICtrlSetState($Open_Button,$GUI_ENABLE) $OpenButtonSate = 1 EndIf Else $o_Shell = ObjCreate("Shell.Application") $o_ShellWindows = $o_Shell.Windows() $Founnd_Url = 0 For $o_window In $o_ShellWindows If $o_window.FullScreen = True And $o_window.Width = $IEWidth And $o_window.Height = $IEHeight Then $oIE = $o_window If StringLeft($oIE.LocationURL,4) = "http" Then $ActiveURL = $oIE.LocationURL If $OpenButtonSate = 0 Then GUICtrlSetState($Open_Button,$GUI_ENABLE) $OpenButtonSate = 1 EndIf $Founnd_Url = 1 ConsoleWrite("Fixed:"&@CRLF) ; < --------------- Debug line EndIf ExitLoop EndIf Next If $Founnd_Url = 0 And $OpenButtonSate = 1 Then GUICtrlSetState($Open_Button,$GUI_DISABLE) $OpenButtonSate = 0 EndIf EndIf $oIE.StatusBar = True ConsoleWrite($ActiveURL&@CRLF) ; < --------------- Debug line EndIf EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE , $Close_Button ;ContinueLoop If $IELoaded = 1 Then _IEQuit($oIE) WinClose($IEhandle) If ProcessWaitClose($IEpid,2) = 0 Then ProcessClose($IEpid) ProcessFullyClose($IEpid) EndIf ;IECreatePseudoEmbedded_CloseAllIEs($IEWidth,$IEHeight) ; If another iexplore.exe process that created with IECreatePseudoEmbedded() is still ; running for some for some reson reason, then that process should be closed now. ; ******** This function is not working. Please write working function and share it with me ******** ExitLoop Case $Open_Button ;~ WinSetOnTop($Form1, "", 0) ShellExecute($ActiveURL) EndSwitch WEnd GUIDelete($Form1) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _NewIECreatePseudoEmbedded ; Description ...: Create IE frame in GUI with the laset IE verison that installed on the computer ; Syntax ........: _NewIECreatePseudoEmbedded($sURL, $h_Parent, $i_Left, $i_Top, $i_Width, $i_Height[, $wait = 5000]) ; Parameters ....: $sURL - The URL to load. ; $h_Parent - The handle of the GUI to create the IE frame in.. ; $i_Left - X pos. ; $i_Top - Y Pos ; $i_Width - The width of the frame. ; $i_Height - The height of the frame. ; $wait - [optional] max time to wait for the IE frame to load. Default is 5000 ms. ; $ShowGui - [optional] use 0 only if you want to use GUISetState(@SW_SHOW) after calling this function. Default is 1. ; Return values .: If error: ; -1 = can't open internet explorer ; -2 = loading time limit reached ; -3 = object error occurred ; .: Id not error: ; Array Variable: ; [0] = $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; the Object is for IE functions in IE.au3 ; [1] = the pid of the IE frame ; [2] = the handle of the IE frame ; Author ........: gil900 ; Modified ......: Yes and No ;) ; Inspired from .: http://www.autoitscript.com/forum/topic/152173-pseudo-embed-google-chrome/ ; http://www.autoitscript.com/forum/topic/138980-iecreatepseudoembedded/ ; http://www.autoitscript.com/forum/topic/99234-iecreate2/#entry712594 ; AutoIt3\Include\IE.au3 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: yes ; ; =============================================================================================================================== Func _NewIECreatePseudoEmbedded($sURL, $h_Parent, $i_Left, $i_Top, $i_Width, $i_Height, $wait = 5000, $ShowGui = 1) Local $Output[3] , $o_IE , $timer , $GIECPE_Edit1 , $pid , $o_Shell , $o_ShellWindows , $o_window , $timedif If $ShowGui = 1 Then $GIECPE_Edit1 = GUICtrlCreateEdit("loading...", $i_Left, $i_Top, $i_Width, $i_Height,$ES_READONLY+$ES_CENTER) GUICtrlSetFont(-1, 35, 400, 2, "Tahoma") GUICtrlSetColor(-1, 0x646464) EndIf $pid = ShellExecute(@HomeDrive&"\Program Files\Internet Explorer\iexplore.exe","-k "&$sURL,"","",@SW_MINIMIZE) If $pid = 0 Then If $ShowGui = 1 Then GUICtrlSetData($GIECPE_Edit1, "Error in opening Internet Explorer") Return -1 EndIf $timer = TimerInit() While 1 $timedif = TimerDiff($timer) If $timedif >= $wait Then If $ShowGui = 1 Then GUICtrlSetData($GIECPE_Edit1, "Error: loading time limit reached") ;~ ProcessClose($pid) ;~ IECreatePseudoEmbedded_CloseAllIEs($i_Width,$i_Height) ; ***** IECreatePseudoEmbedded_CloseAllIEs is not working. Please write working function and share it with me ******** ProcessFullyClose($pid) Return -2 EndIf $o_Shell = ObjCreate("Shell.Application") $o_ShellWindows = $o_Shell.Windows() For $o_window In $o_ShellWindows If $o_window.LocationURL = $sURL Then $o_IE = $o_window $Output[0] = $o_IE ExitLoop 2 EndIf Next WEnd If Not IsObj($o_IE) Then If $ShowGui = 1 Then GUICtrlSetData($GIECPE_Edit1, "Error: object error occurred") ;~ IECreatePseudoEmbedded_CloseAllIEs($i_Width,$i_Height) ; ***** IECreatePseudoEmbedded_CloseAllIEs is not working. Please write working function and share it with me ******** ProcessFullyClose($pid) Return -3 Else $Output[2] = _IEPropertyGet($o_IE, "hwnd") ;~ $Output[1] = WinGetProcess($Output[2]) $Output[1] = $pid ;~ ConsoleWrite($Output[1]&","&$pid&@CRLF) EndIf ;~ If $timedif < 800 Then Sleep(800) If $ShowGui = 1 Then GUISetState(@SW_HIDE, $h_Parent) GUICtrlDelete($GIECPE_Edit1) EndIf _WinAPI_SetParent($Output[2], $h_Parent) _WinAPI_SetWindowLong($Output[2], $GWL_STYLE, $WS_POPUP + $WS_VISIBLE) If $ShowGui = 1 Then GUISetState(@SW_SHOW, $h_Parent) WinActivate($h_Parent) ControlMove($Output[2], "", "", $i_Left + 1, $i_Top + 1, $i_Width , $i_Height) WinActivate($Output[2]) Return $Output EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: ProcessFullyClose ; Description ...: Close the process + all child process of the process (If such exist) ; Syntax ........: ProcessFullyClose($iParentPID[, $ProcessName = ""]) ; Parameters ....: $iParentPID - An integer value. ; $ProcessName - [optional] An unknown value. Default is "". ; Return values .: None ; Author ........: gil900 ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func ProcessFullyClose($iParentPID,$ProcessName = "") Local Const $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20 Local Const $sQuery = 'SELECT * FROM Win32_Process Where ParentProcessId = ' & $iParentPID & ' AND Handle <> ' & $iParentPID Local $objWMIService = ObjGet('winmgmts:\\localhost\root\CIMV2') If IsObj($objWMIService) Then Local $colItems = $objWMIService.ExecQuery($sQuery,'WQL',$wbemFlagReturnImmediately+$wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems If $ProcessName = "" Or $objItem.Name <> $ProcessName Then ProcessClose($objItem.Handle) EndIf Next EndIf EndIf ProcessClose($iParentPID) EndFunc ; ********************* This function is not working.... I hope someone else will write working function ******************* ; #FUNCTION# ==================================================================================================================== ; Name ..........: IECreatePseudoEmbedded_CloseAllIEs ; Description ...: This function will close any iexplore.exe process that started with IECreatePseudoEmbedded() ; The function know what iexplore.exe process to close According to the Width , Height of the embedded frame. ; In order that the function will performs the action correctly, you need to call to the function with the same $i_Width , $i_Height ; values that used in IECreatePseudoEmbedded(). ; Syntax ........: IECreatePseudoEmbedded_CloseAllIEs($i_Width, $i_Height) ; Parameters ....: $i_Width - An integer value. ; $i_Height - An integer value. ; Return values .: None ; Author ........: gil900 ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== ;~ Func IECreatePseudoEmbedded_CloseAllIEs($i_Width,$i_Height) ;~ ConsoleWrite($i_Width&@CRLF) ;~ Return ;~ Local $o_Shell , $o_ShellWindows , $i_Width2 = $i_Width-44 , $i_Height2 = $i_Height-17 , $IsIe , $pid ;~ ConsoleWrite($i_Width&" , "&$i_Height2&@CRLF) ;~ Return ;~ $o_Shell = ObjCreate("Shell.Application") ;~ $o_ShellWindows = $o_Shell.Windows() ;~ For $o_window In $o_ShellWindows ;~ $IsIe = False ;~ ConsoleWrite($o_window.Width&" , "&$o_window.Height&@CRLF) ;~ If $o_window.Width = $i_Width And $o_window.Height = $i_Height Then ;~ $IsIe = True ;~ ElseIf $o_window.Width = $i_Width2 And $o_window.Height = $i_Height2 Then ;~ $IsIe = True ;~ EndIf ;~ If $IsIe Then ;~ $pid = WinGetProcess(HWnd($o_window.HWnd())) ;~ ConsoleWrite($pid&@CRLF) ;~ _IEQuit($o_window) ;~ EndIf ;~ Next ;~ EndFunc ; ********************* This function is not working.... I hope someone else will write working function ******************* Update: - Removed line: If $timedif < 800 Then Sleep(800) Update 2: change name to "_NewIECreatePseudoEmbedded" Edited August 23, 2014 by Guest Link to comment Share on other sites More sharing options...
xOAT Posted August 9, 2014 Share Posted August 9, 2014 (edited) Your example+UDF code is not working correctly for me. IE does not embed into the GUI, but it appears as external window at full screen resolution with not borders or title bar. The embedded edit control later displays "time out" when page loads correctly in IE outside the GUI. When the script closes the full screen IE does not close with it. So, it seems IE does not bind to the parent GUI. I'm on Autoit v3.3.8.1, Win 7 x64, IE11 Edited August 9, 2014 by xOAT Link to comment Share on other sites More sharing options...
Inververs Posted August 9, 2014 Share Posted August 9, 2014 And it's generally do not embed. Your function should be called _IEPseudoEmbedded Link to comment Share on other sites More sharing options...
Guest Posted August 12, 2014 Share Posted August 12, 2014 (edited) Your example+UDF code is not working correctly for me. IE does not embed into the GUI, but it appears as external window at full screen resolution with not borders or title bar. The embedded edit control later displays "time out" when page loads correctly in IE outside the GUI. When the script closes the full screen IE does not close with it. So, it seems IE does not bind to the parent GUI. I'm on Autoit v3.3.8.1, Win 7 x64, IE11 It's weird ..It really worked before.But if I change Example("http://www.autoitscript.com/site/") to: Example("'?do=embed' frameborder='0' data-embedContent>>") then it works as expected.. I do not know what is causing this problem .. I would love if someone would try to figure it out. I have an important questions: 1) When IE11 open in full screen does it opens minimized or not? it should be opened minimized. and after few seconds and if everything works as it should(Which does not in this case), the minimized IE in the taskbar will be hidden. 2) And does the GUI close the IE11 when the "time out" error appears? in this case the IE11 should be closed. Edited August 12, 2014 by Guest Link to comment Share on other sites More sharing options...
Guest Posted August 23, 2014 Share Posted August 23, 2014 (edited) Update: I change the name to "_NewIECreatePseudoEmbedded" Edited August 23, 2014 by Guest 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