Olsm Posted July 4, 2012 Share Posted July 4, 2012 (edited) Hello.I have been learning myself Autoit for over a year now, and I love it! It is my first programming language, and I think it is fun to learn.I create programs in my spare time as a hobby, and I have also created many programs at work to improve the efficiency of the job allot by automating a text based program.Thank you to the developers of AutoIt and those who create the great UDF's!Now to the issue:I decided to try and create a web browser using autoit for a specific website.I use the _IECreateEmbedded() function to embed internet explorer to my gui.The website the web browser will go to requires the use of internet explorer 9 or later.But when I tested it on my laptop at work today that has internet explorer 8 installed, internet explorer 7 was embedded.I searched google what is my web browser and found a site I could check the current browser, and I checked in autoit ie embed and in internet explorer.I installed internet explorer 9 and rebooted, but it will still embed ie 7.0 even though internet explorer is updated to 9.0!Now I have tested on my laptop at home, and here it embeds internet explorer 9.It will be a problem if some of my users update must update from ie8 or earlier to ie9 to use my browser and then it will still embed using the old version...I know I can check with _IEGet() what version of internet explorer is installed, and if its earlier than ie9 I could make it say "You must update internet explorer to 9.0, would you like to update now?" and include the ie9 installer.But that is not enough if an old version of ie is used when embedding anyways. So after that I must have a method to force embed the LAST version of ie installed.So to my questions:1: How can I force autoit to embed last version of ie installed, and if internet explorer version earlier than 9.0 is embedded give an error message that it must be updated and then quit?2: The internet explorer embedded object flickers allot when GUI is re-sized, I cannot find how to fix this anywhere. Any solution?3: The website in the browser sometimes becomes white when i maximize/restore/fullscreen, and I must mark with mouse or CTRL+A for content to become visible. How can I fix that?4: If you think some of my functions are too complex and stupid , please tell me how to improve. I will appreciate any tips from the professional AutoIt'ers to improve my coding skills. I have created a test version by renaming the browser and removing some of the functions etc to post it here so you guys can see and test.The web browser is very simple now and I have more features to add, but I have kind of hit a obstacle that I think I must climb over first before I can proceed.I hope you can help me, that would be very much appreciated, thanks in advance!expandcollapse popup#include <IE.au3> #include <WindowsConstants.au3> #include <resources.au3> #include <StaticConstants.au3> #include <ANYGUIv2.8.au3> #include <GuiMenu.au3> #include <HotKey.au3> #include <Misc.au3> Opt("GUIEventOptions", 1) Dim $Version="2.0.0" Dim $FullScreen=False _IEErrorHandlerRegister() $PosX=IniRead(@ScriptDir & "/Settings.ini", "Settings", "PosX","E") $PosY=IniRead(@ScriptDir & "/Settings.ini", "Settings", "PosY","E") $SizeWidth=IniRead(@ScriptDir & "/Settings.ini", "Settings", "Width","E") $SizeHeight=IniRead(@ScriptDir & "/Settings.ini", "Settings", "Height","E") Global $AlwaysOnTopOptionsMenuItemValue=IniRead(@ScriptDir & "/Settings.ini", "Settings", "AlwaysOnTop", "") Global $CheckForUpdateAtStartupOptionsMenuItemValue=IniRead(@ScriptDir & "/Settings.ini", "Settings", "CheckForUpdateAtStartup", "E") Global $FullScreenOptionsMenuItemValue=IniRead(@ScriptDir & "/Settings.ini", "Settings", "Fullscreen","E") Global $MaximizeRead=IniRead(@ScriptDir & "/Settings.ini", "Settings", "Maximize","E") If $MaximizeRead="1" Or $PosX="E" Or $PosY="E" Or $SizeWidth="E" Or $SizeHeight="E" Then Global $GUI = GUICreate("Test Browser", @DesktopWidth, @DesktopHeight, 0, 0, $WS_SIZEBOX+$WS_MAXIMIZE+$WS_MINIMIZEBOX+$WS_MAXIMIZEBOX) Else Global $GUI = GUICreate("Test Browser", @DesktopWidth, @DesktopHeight, 0, 0, $WS_SIZEBOX+$WS_MINIMIZEBOX+$WS_MAXIMIZEBOX) If $PosX<0 Or $PosX>@DesktopWidth Then $PosX=0 If $PosY<0 Or $PosY>@DesktopHeight Then $PosY=0 WinMove($GUI, "", $PosX, $PosY, $SizeWidth, $SizeHeight) EndIf Global $object = _IECreateEmbedded() CreateMenu() If $FullScreenOptionsMenuItemValue="1" Then Fullscreen() EndIf Global $GUIClientSize=WinGetClientSize($GUI) Local $object_ctrl = GUICtrlCreateObj($object, 0, 0, $GUIClientSize[0], $GUIClientSize[1]) GUICtrlSetResizing ( $object_ctrl, $GUI_DOCKAUTO ) GUISetState() _IENavigate($object, "http://www.thismachine.info/") Func CreateMenu() Global $OptionsMenu=GUICtrlCreateMenu("Options") Global $CheckForUpdateAtStartupOptionsMenuItem = GUICtrlCreateMenuItem("Check For Update At Startup", $OptionsMenu) Global $AlwaysOnTopOptionsMenuItem = GUICtrlCreateMenuItem("Always On Top", $OptionsMenu) Global $FullScreenOptionsMenuItem = GUICtrlCreateMenuItem("Fullscreen (F11)", $OptionsMenu) Global $HelpMenu=GUICtrlCreateMenu("Help") Global $CheckForUpdateHelpMenuItem = GUICtrlCreateMenuItem("Check For Update", $HelpMenu) Global $AboutHelpMenuItem = GUICtrlCreateMenuItem("About", $HelpMenu) If $AlwaysOnTopOptionsMenuItemValue="1" Then GUICtrlSetState($AlwaysOnTopOptionsMenuItem, $GUI_CHECKED) If $CheckForUpdateAtStartupOptionsMenuItemValue="1" Then GUICtrlSetState($CheckForUpdateAtStartupOptionsMenuItem, $GUI_CHECKED) EndFunc If $AlwaysOnTopOptionsMenuItemValue="1" Then GUICtrlSetState($AlwaysOnTopOptionsMenuItem, $GUI_CHECKED) WinSetOnTop("Test Browser", "", 1) ElseIf $AlwaysOnTopOptionsMenuItemValue="0" Then GUICtrlSetState($AlwaysOnTopOptionsMenuItem, $GUI_UNCHECKED) WinSetOnTop("Test Browser", "", 0) EndIf If $CheckForUpdateAtStartupOptionsMenuItemValue="1" Then GUICtrlSetState($CheckForUpdateAtStartupOptionsMenuItem, $GUI_CHECKED) ;CheckForUpdate() ElseIf $CheckForUpdateAtStartupOptionsMenuItemValue="E" Then GUICtrlSetState($CheckForUpdateAtStartupOptionsMenuItem, $GUI_CHECKED) WinSetOnTop("Test Browser", "", 1) $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "CheckForUpdateAtStartup", "1") CheckForSaveError() ;CheckForUpdate() EndIf _HotKey_Assign(0x7A, "Fullscreen", 0, $GUI) _HotKey_Assign(0x08, "GoBack", 0, $GUI) While 1 Sleep(10) $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE _RFCalcWinPos() Exit Case $msg = $GUI_EVENT_MINIMIZE _RFCalcWinPos() GUISetState(@SW_MINIMIZE) Case $msg = $GUI_EVENT_RESTORE GUISetState(@SW_RESTORE) If $MaximizeRead<>"0" Then $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "Maximize", "0") CheckForSaveError() $MaximizeRead="0" EndIf Case $msg = $GUI_EVENT_MAXIMIZE GUISetState(@SW_MAXIMIZE) If $MaximizeRead<>"1" Then $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "Maximize", "1") CheckForSaveError() $MaximizeRead="1" EndIf Case $msg=$AlwaysOnTopOptionsMenuItem If BitAND(GUICtrlRead($AlwaysOnTopOptionsMenuItem), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($AlwaysOnTopOptionsMenuItem, $GUI_UNCHECKED) WinSetOnTop("Test Browser", "", 0) $AlwaysOnTopOptionsMenuItemValue="0" $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "AlwaysOnTop", "0") CheckForSaveError() Else GUICtrlSetState($AlwaysOnTopOptionsMenuItem, $GUI_CHECKED) WinSetOnTop("Test Browser", "", 1) $AlwaysOnTopOptionsMenuItemValue="1" $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "AlwaysOnTop", "1") CheckForSaveError() EndIf Case $msg=$CheckForUpdateAtStartupOptionsMenuItem If BitAND(GUICtrlRead($CheckForUpdateAtStartupOptionsMenuItem), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($CheckForUpdateAtStartupOptionsMenuItem, $GUI_UNCHECKED) $CheckForUpdateAtStartupOptionsMenuItemValue="0" $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "CheckForUpdateAtStartup", "0") CheckForSaveError() Else GUICtrlSetState($CheckForUpdateAtStartupOptionsMenuItem, $GUI_CHECKED) WinSetOnTop("Test Browser", "", 1) $CheckForUpdateAtStartupOptionsMenuItemValue="1" $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "CheckForUpdateAtStartup", "1") CheckForSaveError() EndIf Case $msg=$FullScreenOptionsMenuItem Fullscreen() Case $msg=$CheckForUpdateHelpMenuItem ;CheckForUpdate() Case $msg=$AboutHelpMenuItem ;GUISetState(@SW_DISABLE, $GUI) ;AboutGUI() EndSelect If _IsPressed("05") Then ; Wait until key is released. While _IsPressed("05") Sleep(250) WEnd GoBack() ElseIf _IsPressed("06") Then ; Wait until key is released. While _IsPressed("06") Sleep(250) WEnd GoForward() EndIf WEnd Func GoBack() _IEAction($object, "back") EndFunc Func GoForward() _IEAction($object, "forward") EndFunc Func Fullscreen() If $FullScreen=False Then _RFCalcWinPos() $NewArea = DllStructCreate("int;int;int;int") DllStructSetData($NewArea,1,0) DllStructSetData($NewArea,2,0) DllStructSetData($NewArea,3,@DesktopHeight) DllStructSetData($NewArea,4,@DesktopWidth) DllCall("user32.dll","int","SystemParametersInfo","int",0x2F,"int",0,"ptr",DllStructGetPtr($NewArea),"int",0) DllCall("user32.dll","int","SetWindowLong","hwnd",$GUI,"int",-16,"long",0x80) GUISetState(@SW_HIDE,$GUI) GUISetState(@SW_SHOW,$GUI) WinMove($GUI,"",0,0) GUISetState(@SW_MAXIMIZE,$GUI) GUISetState(@SW_SHOW,$GUI) $hMain = _GUICtrlMenu_GetMenu($GUI) GUICtrlDelete($OptionsMenu) GUICtrlDelete($HelpMenu) If $FullScreenOptionsMenuItemValue="0" Then $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "Fullscreen", "1") CheckForSaveError() EndIf $FullScreen=True ElseIf $FullScreen=True Then ; - 1. Getting handle of a window $xhandle = WinGetHandle($GUI) ; - 2. handling a window $xh = _GuiTarget($xhandle,1) $Style = 365887488 $ExStyle = -1 ; - 3. changing a window $result = _TargetStyle("set",1,$Style,$ExStyle,$xh) If $MaximizeRead="0" Then GUISetState(@SW_RESTORE) WinMove($GUI, "", $PosX, $PosY, $SizeWidth, $SizeHeight) EndIf CreateMenu() If $FullScreenOptionsMenuItemValue="1" Then $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "Fullscreen", "0") CheckForSaveError() EndIf $FullScreen=False EndIf EndFunc ;//Compile Current Window Position Func _RFCalcWinPos() $GetPos=WinGetPos($GUI) If $GetPos[0]=$PosX And $GetPos[1]=$PosY And $GetPos[2]=$SizeWidth And $GetPos[3]=$SizeHeight Then Return ;//Set the Focus on the RFCalculator Window WinActivate($GUI) If (BitAND(WinGetState($GUI), 32) = 32) Then If $MaximizeRead<>"1" Then $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "Maximize", "1") Else If $MaximizeRead<>"0" Then $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "Maximize", "0") ;//Capture the RFCalculator Window x y position Local $Handle = WinGetHandle($GUI, "") $RFScreenPos = WinGetPos($Handle, "") If UBound($RFScreenPos) = 4 Then ;//Width and Height are Constants $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "PosX", $RFScreenPos[0]) $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "PosY", $RFScreenPos[1]) $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "Width", $RFScreenPos[2]) $SaveKey=IniWrite(@ScriptDir & "/Settings.ini", "Settings", "Height", $RFScreenPos[3]) $PosX=$RFScreenPos[0] $PosY=$RFScreenPos[1] $SizeWidth=$RFScreenPos[2] $SizeHeight=$RFScreenPos[3] EndIf EndIf ; msgbox(0,"",$RFScreenPos[0]) ;//### Debug EndFunc ;==>_RFCalcWinPos Func CheckForSaveError() If $SaveKey=0 Then MsgBox(16 + 262144, "Error", "Settings was not successfully saved, make sure file is not Read-only!") Exit Else If Not FileExists(@ScriptDir&"/Settings.ini") Then MsgBox(16 + 262144, "Error", "Settings was not successfully saved!") Exit EndIf EndIf EndFuncIncludes:AnyGUIv2.8 -> https://www.dropbox.com/s/m41fq9oyubmji2j/ANYGUIv2.8.au3?mHotKey -> https://www.dropbox.com/s/et8thj17em6yn3y/HotKey.au3?mTell me if you need anything else! Edited July 4, 2012 by Olsm Link to comment Share on other sites More sharing options...
Olsm Posted July 7, 2012 Author Share Posted July 7, 2012 Over a hundred views and no replies?Can anyone help me please?I can't edit the main post, so I'll have to type this here:"3: The website in the browser sometimes becomes white when i maximize/restore/fullscreen, and I must mark with mouse or CTRL+A for content to become visible"It seems this was solved by adding exstyle $WS_EX_COMPOSITED to guicreate. Will that be the solution and will it work for all users?I also found out that _WinAPI_RedrawWindow function also solved this, if added after each maximize/restore and fullscreen. Should I use that instead?Or should I use both just in case? I still need help with 1 and 2, I have tried but I cannot figure out how to fix the flickering and how to chose what ie version to embed.Please respond, thanks in advance! Link to comment Share on other sites More sharing options...
Olsm Posted July 16, 2012 Author Share Posted July 16, 2012 Hello anyone here who can reply??? 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