TheRaph Posted December 22, 2014 Posted December 22, 2014 Hello, I've got a question and I hope I'm not to brainless to find the answer already posted in this forum ... (but I'm no native english speaker ... so that may be my fault not to find the right words to search for). I've scripted the core problem in an short example script. There is a main window containing two child-windows. In the left child there is an embedded IE-Control. In the right window, there's an edit field. The GUI looks like I expect and I can do some inputs in the edit control ... so far okay ... but if I try to navigate the cursor (arrow key) inside the edit control it works only up and down. Using LEFTARROW, RIGHTARROW or DEL nothing happens. If I perform a click in the IEControl, the behavor changes when I'm clicking in the edit control again. Now I can NOT use any arrow-key. If I try so, the content of the IE will move.Text inputs anyhow are possible. What should I change in my Code, that if I get focus to the IE, the arrow-keys work with in IE-control and if I get focus back to the edit control the arrow key work within that? Attention! This will be NOT a problem if IE-control and edit control will be in the same window. But this would be not a solution for me. My original script uses multiple tab-controls and therefor ist is necessary to have that all in sub windows. Here the Example code: expandcollapse popup#include <GUIConstants.au3> #include <IE.au3> #include <WinAPI.au3> Local $oIE = _IECreateEmbedded() $whdMain = GUICreate("Embedded Web control Test", 900, 440, _ (@DesktopWidth - 900) / 2, (@DesktopHeight - 440) / 2, _ BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_CLIPCHILDREN )) GUICtrlCreateLabel("", 0, 0, 0, 0) GUISetState(@SW_SHOW) ;Show GUI $whdLeft = GUICreate("Left Hand Side", 500, 400, 10, 10, BitOR($WS_POPUP, $WS_CLIPCHILDREN )) GUISetBkColor(0X006400) GUICtrlCreateObj($oIE, 10, 10, 480, 380) GUISetState(@SW_SHOW) ;Show GUI _WinAPI_SetParent($whdLeft, $whdMain) _IENavigate($oIE, "http://www.google.com") _IEAction($oIE, "stop") $whdRight = GUICreate("Right Hand Side", 360, 400, 520, 10, BitOR($WS_POPUP, $WS_CLIPCHILDREN )) GUISetBkColor(0X000064) $input = GUICtrlCreateInput("text", 10, 10, 340) GUICtrlCreateEdit("<p class=""text"">" & @CRLF & "contents hot" & @CRLF & "</p>" & @CRLF, 10, 40, 340, 350, _ BitOR($ES_NOHIDESEL,$ES_AUTOVSCROLL,$ES_AUTOVSCROLL, $WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE)) GUISetState(@SW_SHOW) ;Show GUI _WinAPI_SetParent($whdRight, $whdMain) While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] ; Main Window? Case $whdMain ; Message? Switch $aMsg[0] Case $GUI_EVENT_CLOSE Exit EndSwitch EndSwitch WEnd GUIDelete() Exit Thank you ...
Moderators SmOke_N Posted December 23, 2014 Moderators Posted December 23, 2014 WS_CHILD and WS_POPUP do not play nicely together. When you SetParent(), you're adding WS_CHILD to the style of the object you're making a child. Run this and see if you get the result you need/want: expandcollapse popup#include <GUIConstants.au3> #include <IE.au3> #include <WinAPI.au3> Local $oIE = _IECreateEmbedded() $whdMain = GUICreate("Embedded Web control Test", 900, 440, _ (@DesktopWidth - 900) / 2, (@DesktopHeight - 440) / 2, _ BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_CLIPCHILDREN )) GUICtrlCreateLabel("", 0, 0, 0, 0) GUISetState(@SW_SHOW) ;Show GUI $whdLeft = GUICreate("Left Hand Side", 500, 400, 10, 10, BitOR($WS_CHILD, $WS_CLIPCHILDREN ), -1, $whdMain) GUISetBkColor(0X006400) GUICtrlCreateObj($oIE, 10, 10, 480, 380) GUISetState(@SW_SHOW) ;Show GUI _IENavigate($oIE, "http://www.google.com") _IEAction($oIE, "stop") $whdRight = GUICreate("Right Hand Side", 360, 400, 520, 10, BitOR($WS_CHILD, $WS_CLIPCHILDREN ), -1, $whdMain) GUISetBkColor(0X000064) $input = GUICtrlCreateInput("text", 10, 10, 340) GUICtrlCreateEdit("<p class=""text"">" & @CRLF & "contents hot" & @CRLF & "</p>" & @CRLF, 10, 40, 340, 350, _ BitOR($ES_NOHIDESEL,$ES_AUTOVSCROLL,$ES_AUTOVSCROLL, $WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE)) GUISetState(@SW_SHOW) ;Show GUI While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] ; Main Window? Case $whdMain ; Message? Switch $aMsg[0] Case $GUI_EVENT_CLOSE Exit EndSwitch EndSwitch WEnd GUIDelete() Exit Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
TheRaph Posted December 24, 2014 Author Posted December 24, 2014 (edited) Thank you very much, this solves that issue with arrow keys. But as I try to put it into my main code I got an other problem. To show you, I use the same code as you mentioned above. I just add two buttons [+} and [-] which are prepared to change "$oIE.document.body.style.zoom". If I start this, I can scroll and klick inside the IE-control as mutch as I want. But if set a zoom level and I try to scroll inside the IE-control, the whole app freezes. Why? I try to solve that problem on my own: First try using "GUICreate" with style "$WS_CHILD" and parent "$whdMain" and using "_WinAPI_SetParent" to set explicit parent and child: - same issue Second try using "GUICreate" with style "$WS_POPUP" and parent "$whdMain" and no "_WinAPI_SetParent": - The sub-windows open as popup ... I should have been expected that Third try using "GUICreate" with style "$WS_POPUP" and parent "$whdMain" and using "_WinAPI_SetParent" to set explicit parent and child: - And it works ... [EDIT:] for 2 seconds - after scrolling the IE, the key issue is back. Issue: Reveal hidden contents expandcollapse popup#include <GUIConstants.au3> #include <IE.au3> #include <WinAPI.au3> Local $oIE = _IECreateEmbedded() Local $fZoom = 1.0 Local $fZoomstep = 0.05 $whdMain = GUICreate("Embedded Web control Test", 900, 440, _ (@DesktopWidth - 900) / 2, (@DesktopHeight - 440) / 2, _ BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_CLIPCHILDREN )) GUICtrlCreateLabel("", 0, 0, 0, 0) GUISetState(@SW_SHOW) ;Show GUI ; -- Left Side -- $whdLeft = GUICreate("Left Hand Side", 500, 400, 10, 10, BitOR($WS_CHILD, $WS_CLIPCHILDREN ), -1, $whdMain) GUISetBkColor(0X006400) ; -- IE Object -- GUICtrlCreateObj($oIE, 10, 50, 480, 340) GUISetState(@SW_SHOW) ;Show GUI _IENavigate($oIE, "http://www.google.com") _IEAction($oIE, "stop") ; -- Button Zoom + -- $idZoomPlus = GUICtrlCreateButton("+", 20, 5, 30, 25) GUICtrlSetResizing ( $idZoomPlus, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE)) ; -- Button Zoom - -- $idZoomMinus = GUICtrlCreateButton("-", 80, 5, 30, 25) GUICtrlSetResizing ( $idZoomMinus, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE)) ; -- Right Side -- $whdRight = GUICreate("Right Hand Side", 360, 400, 520, 10, BitOR($WS_CHILD, $WS_CLIPCHILDREN ), -1, $whdMain) GUISetBkColor(0X000064) $input = GUICtrlCreateInput("text", 10, 10, 340) GUICtrlCreateEdit("<p class=""text"">" & @CRLF & "contents hot" & @CRLF & "</p>" & @CRLF, 10, 40, 340, 350, _ BitOR($ES_NOHIDESEL,$ES_AUTOVSCROLL,$ES_AUTOVSCROLL, $WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE)) GUISetState(@SW_SHOW) ;Show GUI While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] ; Main Window? Case $whdMain ; Message? Switch $aMsg[0] Case $GUI_EVENT_CLOSE Exit EndSwitch Case $whdLeft ; Message? Switch $aMsg[0] Case $idZoomPlus $fZoom = $fZoom + $fZoomstep $oIE.document.body.style.zoom = $fZoom Case $idZoomMinus $fZoom = $fZoom - $fZoomstep $oIE.document.body.style.zoom = $fZoom EndSwitch EndSwitch WEnd Exit Thank you for helping Edited December 24, 2014 by TheRaph
Moderators SmOke_N Posted December 26, 2014 Moderators Posted December 26, 2014 As far as I can tell, it's nothing to do with the style of the ui's, but more the object itself. Not sure off the top of my head how to fix that specific issue. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Solution TheRaph Posted December 31, 2014 Author Solution Posted December 31, 2014 (edited) Okay ... now it's time to create the solution ... First try ... take the newer one. After a short info from SmOke_N (Thank you ), I decide to tell Windows that my programm has to use the IE8-mode for running embedded web browser. This is done by adding a REG-Key: (SmOke_N has implemented it yesterday in his library!) expandcollapse popup#include <GUIConstants.au3> #include <IE.au3> #include <WinAPI.au3> Local $oIE = _IECreateEmbedded() Local $fZoom = 1.0 Local $fZoomstep = 0.05 Local $sExeName = StringRegExp ( @AutoItExe, ".*\\([^\\]*\.exe)$",2) If IsArray($sExeName) Then RegWrite ( "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION" , $sExeName[1], "REG_DWORD", 8000 ) $whdMain = GUICreate("Embedded Web control Test", 900, 440, _ (@DesktopWidth - 900) / 2, (@DesktopHeight - 440) / 2, _ BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_CLIPCHILDREN )) GUICtrlCreateLabel("", 0, 0, 0, 0) GUISetState(@SW_SHOW) ;Show GUI ; -- Left Side -- $whdLeft = GUICreate("Left Hand Side", 500, 400, 10, 10, BitOR($WS_CHILD, $WS_CLIPCHILDREN ), -1, $whdMain) GUISetBkColor(0X006400) _WinAPI_SetParent($whdLeft,$whdMain) ; -- Button Zoom + -- $idZoomPlus = GUICtrlCreateButton("+", 20, 5, 30, 25) GUICtrlSetResizing ( $idZoomPlus, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE)) ; -- Button Zoom - -- $idZoomMinus = GUICtrlCreateButton("-", 80, 5, 30, 25) GUICtrlSetResizing ( $idZoomMinus, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE)) ; -- IE Object -- GUICtrlCreateObj($oIE, 10, 50, 480, 340) GUISetState(@SW_SHOW) ;Show GUI _IENavigate($oIE, "http://www.google.com") _IEAction($oIE, "stop") ; -- Right Side -- $whdRight = GUICreate("Right Hand Side", 360, 400, 520, 10, BitOR($WS_CHILD, $WS_CLIPCHILDREN ), -1, $whdMain) GUISetBkColor(0X000064) _WinAPI_SetParent($whdRight,$whdMain) $input = GUICtrlCreateInput("text", 10, 10, 340) GUICtrlCreateEdit("<p class=""text"">" & @CRLF & "contents hot" & @CRLF & "</p>" & @CRLF, 10, 40, 340, 350, _ BitOR($ES_NOHIDESEL,$ES_AUTOVSCROLL,$ES_AUTOVSCROLL, $WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE)) GUISetState(@SW_SHOW) ;Show GUI While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] ; Main Window? Case $whdMain ; Message? Switch $aMsg[0] Case $GUI_EVENT_CLOSE Exit EndSwitch Case $whdLeft ; Message? Switch $aMsg[0] Case $idZoomPlus $fZoom = $fZoom + $fZoomstep $oIE.document.body.style.zoom = $fZoom Case $idZoomMinus $fZoom = $fZoom - $fZoomstep $oIE.document.body.style.zoom = $fZoom EndSwitch EndSwitch WEnd Exit That has no problems with using arrow key but freeze the app if I try to zoom and scroll. Okay. Next try ... use the ring to rule them all. Or in other words try to rule and embed an existing IE-Window instead of using the "_IECreateEmbedded()" First you need an IE-Window ("_IECreate()"), then remove all menubars and toolbars etc. , then get the handle and enslave the window with "_WinAPI_SetParent()". At last adjust the style. GUISetState(@SW_SHOW) ;Show GUI ; -- IE Object -- $oIE = _IECreate("about:blank", 0, 1) ; empty window Sleep(1000) ; kurz warten Local $whdIE = _IEPropertyGet($oIE, "hwnd") ; Handle ; switch off all toolbars etc. $oIE.Toolbar = False $oIE.AddressBar = False $oIE.StatusBar = False ; merge into our GUI _WinAPI_SetParent($whdIE, $whdLeft) ;replace Style DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $whdIE, "int", -16, "long", BitOR($WS_CHILD, $WS_CLIPCHILDREN )) ; The following is necessary if you don't move the window ... just for repaint ; DllCall("user32.dll", "long", "SetWindowPos", "hwnd", $whdIE, "hwnd", $whdIE, "int", 0, "int", 0, "int", 0, "int", 0, "long", BitOR($SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOZORDER, $SWP_FRAMECHANGED)) ; Move it and change visibility WinMove ( $whdIE, "", 10, 50, 480, 340) $oIE.Visible = True _IENavigate($oIE, "http://www.google.com") _IEAction($oIE, "stop") Okay ... this works ... Next step: Open al local file: Add this at next to "_IEAction ..." : Sleep(5000) _IENavigate($oIE, @ScriptDir & "\templates\newsletter_template.html") _IEAction($oIE, "stop") Okay, It may work at the first time, but mostly it causes horrible graphic errors and zooming will not work after loading local content. The reason for that is, you get lost of "$oIE"-object. I've figured out, that the reason for that are the security areas of IE. "about:blank" and "google.com" are in "internet zone" the local file is in "computer zone". If you change the security zone, IE creates automaticly a new IE-object and left the old one. If you like to rule that new object, you have to re attach it. But how? Using "_IEAttach()"? You can try it .. it won't work. _IEAttach() are not able to detect the IE-window because it is embedded into our aplication. You also maytry to start "_IECreate" with local file as argument, but this also do not work! You will lost the "$oIE" at the moment as the IE starts. I think this may be because IE starts internally with an emty page in "internet zone" and than load the requested page. The correct chain of doings is: Create IE with "about:blank" then get WHND, then load local file, re-attach IE to object variable, remove bars, embed IE to your app, set style (repaint) and be happy. But that's not all. If you've got a co-worker like the person next to me, who like hardlinks to websites on desktop, then you may get in trouble again. If he start his hardlink (to google.com - maybe) it opens up a single IE-window. If you now start this application, "_IECreate" will attach to the already open IE-window, overwrite it's site and creates "$oIE = 0". I've got no idea why! To solve this I've extend the whole thing a little bit, and use "Run" instead of "_IECreate" ... expandcollapse popup#include <GUIConstants.au3> #include <IE.au3> #include <WinAPI.au3> Local $oIE ; = _IECreateEmbedded() Local $fZoom = 1.0 Local $fZoomstep = 0.05 Local $sExeName = StringRegExp ( @AutoItExe, ".*\\([^\\]*\.exe)$",2) If IsArray($sExeName) Then RegWrite ( "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION" , $sExeName[1], "REG_DWORD", 8000 ) $whdMain = GUICreate("Embedded Web control Test", 900, 440, _ (@DesktopWidth - 900) / 2, (@DesktopHeight - 440) / 2, _ BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_CLIPCHILDREN )) GUICtrlCreateLabel("", 0, 0, 0, 0) GUISetState(@SW_SHOW) ;Show GUI ; -- Left Side -- $whdLeft = GUICreate("Left Hand Side", 500, 400, 10, 10, BitOR($WS_CHILD, $WS_CLIPCHILDREN ), -1, $whdMain) GUISetBkColor(0X006400) _WinAPI_SetParent($whdLeft,$whdMain) ; -- Button Zoom + -- $idZoomPlus = GUICtrlCreateButton("+", 20, 5, 30, 25) GUICtrlSetResizing ( $idZoomPlus, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE)) ; -- Button Zoom - -- $idZoomMinus = GUICtrlCreateButton("-", 80, 5, 30, 25) GUICtrlSetResizing ( $idZoomMinus, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE)) GUISetState(@SW_SHOW) ;Show GUI ; -- IE Object -- Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe about:blank") Sleep(100) For $i = 1 To 50 $oIE = _IEAttach ( "about:blank" , "url") if @error = 0 then ExitLoop Sleep(100) Next If $i = 50 Then MsgBox($MB_SYSTEMMODAL, "Error", "Unable to connect to IE (" & @error & ")") Sleep(1000) ; kurz warten Local $whdIE = _IEPropertyGet($oIE, "hwnd") ; Handle _IENavigate($oIE, @ScriptDir & "\templates\newsletter_template.html") Sleep(1000) $oIE = _IEAttach ( $whdIE , "hwnd" ) ;attach new object ; switch off all toolbars etc. $oIE.Toolbar = False $oIE.AddressBar = False $oIE.StatusBar = False ; merge into our GUI _WinAPI_SetParent($whdIE, $whdLeft) ;replace Style DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $whdIE, "int", -16, "long", BitOR($WS_CHILD, $WS_CLIPCHILDREN )) ; The following is necessary if you don't move the window ... just for repaint ; DllCall("user32.dll", "long", "SetWindowPos", "hwnd", $whdIE, "hwnd", $whdIE, "int", 0, "int", 0, "int", 0, "int", 0, "long", BitOR($SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOZORDER, $SWP_FRAMECHANGED)) ; Move it and change visibility WinMove ( $whdIE, "", 10, 50, 480, 340) $oIE.Visible = True ; -- Right Side -- $whdRight = GUICreate("Right Hand Side", 360, 400, 520, 10, BitOR($WS_CHILD, $WS_CLIPCHILDREN ), -1, $whdMain) GUISetBkColor(0X000064) _WinAPI_SetParent($whdRight,$whdMain) $input = GUICtrlCreateInput("text", 10, 10, 340) GUICtrlCreateEdit("<p class=""text"">" & @CRLF & "contents hot" & @CRLF & "</p>" & @CRLF, 10, 40, 340, 350, _ BitOR($ES_NOHIDESEL,$ES_AUTOVSCROLL,$ES_AUTOVSCROLL, $WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE)) GUISetState(@SW_SHOW) ;Show GUI While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] ; Main Window? Case $whdMain ; Message? Switch $aMsg[0] Case $GUI_EVENT_CLOSE WinClose ( $whdIE ) Sleep(100) Exit EndSwitch Case $whdLeft ; Message? Switch $aMsg[0] Case $idZoomPlus $fZoom = $fZoom + $fZoomstep $oIE.document.body.style.zoom = $fZoom Case $idZoomMinus $fZoom = $fZoom - $fZoomstep $oIE.document.body.style.zoom = $fZoom EndSwitch EndSwitch WEnd WinClose ( $whdIE ) Sleep(100) Exit ! Never forget to close IE-window using "WinClose" - If you forget, it causes zombie-windows left in memory ! Raph PS: This forum helps mutch on my way to that solution, thank you. And special thanks to "SmOke_N" for info about that REG-Key. [EDIT 2015-1-5]: Remove some spelling errors. Edited January 5, 2015 by TheRaph
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