Jump to content

Embedding 3rd Party app and 2 browsers in GUI - I'm THIS close.

Recommended Posts

I have a script that is calling 2 browser windows in my GUI and loading up the appropriate URLs.  Tested alone it works fine.  I also have another script that launches a 3rd party application in the GUI.  When I try to modify my 2nd script so that it includes the two browser windows along with the GUI, the GUI loads but not the browser windows.  Can someone get a second set of eyes on the script below and tell me where my brain jumped track please?  Many Thanks.

#include <GUIConstants.au3>
#include <Constants.au3>
#include <windowsconstants.au3>
#include <IE.au3>

Global $oIE_google = _IECreateEmbedded()
Global $oIE_autoit = _IECreateEmbedded()

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

$mainWindow = GUICreate("Embed Cmd", 1280, 780, 10, 10)
GUISetState (@SW_SHOW)
GUIRegisterMsg(0xF, "WM_PAINT")

; create a borderless window that is a child to the main window
$embedWindow = GUICREATE("", 700, 400, 15, 15, $WS_POPUP, -1, $mainWindow)
Global $google = GUICtrlCreateObj($oIE_google, 10, 10, 1000, 300)
Global $autoit = GUICtrlCreateObj($oIE_autoit, 800, 10, 500, 300)
_IENavigate($oIE_google, "http://www.google.com")
_IENavigate($oIE_autoit, "http://www.bing.com")

DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $embedWindow, "hwnd", $mainWindow)

; launch the command prompt (black on white, without the operating system message)
$pid = run("C:\Program Files (x86)\Cisco\Router Manager\Router Administration.exe")
ProcessWait ($pid)
; get the handle of the cmd window as i cannot be certain that there will be only one instance of the cmd running with the same window title or class
$cmdHandle = _ProcessGetHWnd($pid, 2)
$hWndChild = $cmdHandle[1][1]
; make the command prompt window a child to the earlier created borderless child window
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWndChild, "hwnd", $embedWindow)
; resize the command prompt window so that its bolder and title bar are outside the borderless child window
;  giving the appearance of a borderless command prompt
WinMove($hWndChild, '', 10, 500, 485, 206)
;WinMove($hWndChild, '', 10, 500)
WinSetState($hWndChild, '', @SW_SHOW)
WinSetState($embedWindow, '', @SW_SHOW)
WinSetState($oIE_google, '', @SW_SHOW)
WinSetState($oIE_autoit, '', @SW_SHOW)

; inifinite event loop
While 1

; sleep for 100 milliseconds (to not hog the cpu)

; end of event loop

Func CLOSEClicked()
; take care of things to do when exiting

Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0)
EndFunc  ;==>WM_PAINT

; Function Name:    _ProcessGetHWnd
; Description:      Returns the HWND(s) owned by the specified process (PID only !).
; Parameter(s):     $iPid        - the owner-PID.
;                    $iOption    - Optional : return/search methods :
;                        0 - returns the HWND for the first non-titleless window.
;                        1 - returns the HWND for the first found window (default).
;                        2 - returns all HWNDs for all matches.
;                   $sTitle        - Optional : the title to match (see notes).
;                    $iTimeout    - Optional : timeout in msec (see notes)
; Return Value(s):  On Success - returns the HWND (see below for method 2).
;                        $array[0][0] - number of HWNDs
;                        $array[x][0] - title
;                        $array[x][1] - HWND
;                   On Failure    - returns 0 and sets @error to 1.
; Note(s):            When a title is specified it will then only return the HWND to the titles
;                    matching that specific string. If no title is specified it will return as
;                    described by the option used.
;                    When using a timeout it's possible to use WinWaitDelay (Opt) to specify how
;                    often it should wait before attempting another time to get the HWND.
; Author(s):        Helge
Func _ProcessGetHWnd($iPid, $iOption = 1, $sTitle = "", $iTimeout = 2000)
    Local $aReturn[1][1] = [[0]], $aWin, $hTimer = TimerInit()

    While 1

    ; Get list of windows
        $aWin = WinList($sTitle)

    ; Searches thru all windows
        For $i = 1 To $aWin[0][0]

        ; Found a window owned by the given PID
            If $iPid = WinGetProcess($aWin[$i][1]) Then

            ; Option 0 or 1 used
                If $iOption = 1 OR ($iOption = 0 And $aWin[$i][0] <> "") Then
                    Return $aWin[$i][1]

            ; Option 2 is used
                ElseIf $iOption = 2 Then
                    ReDim $aReturn[UBound($aReturn) + 1][2]
                    $aReturn[0][0] += 1
                    $aReturn[$aReturn[0][0]][0] = $aWin[$i][0]
                    $aReturn[$aReturn[0][0]][1] = $aWin[$i][1]

    ; If option 2 is used and there was matches then the list is returned
        If $iOption = 2 And $aReturn[0][0] > 0 Then Return $aReturn

    ; If timed out then give up
        If TimerDiff($hTimer) > $iTimeout Then ExitLoop

    ; Waits before new attempt

; No matches
    Return 0
EndFunc  ;==>_ProcessGetHWnd

$StaticTxt = ControlGetText("Embed Cmd","",1007)
 MsgBox(1,"Static Text", $StaticTxt)

While GUIGetMsg() <> -3


Share this post

Link to post
Share on other sites

Are you experiencing a strange occurrence and that the window instead of being embedded is acting like an overlay? In other words, are you getting a window covering up another and can actually click and drag it out separating the two?

If so, I wonder about the DLL calls  you're making to make the parent/child windows. I could be wrong. But wouldn't something like this be more helpful:


$h_HWND = _IEPropertyGet($o_IE, "hwnd")
$hhwnd = WinGetProcess($hWnd)
_WinAPI_SetParent($h_HWND, [your GUI])
_WinAPI_MoveWindow($h_HWND, $0, $0, 1049, 550, False)

The two browser windows would be something like this:

$o_IE = ObjCreate("InternetExplorer.Application")
$o_IE.theatermode = True
$o_IE.fullscreen = True
$o_IE.statusbar = False
_IENavigate($o_IE, 'about:blank')

$o_IETwo = ObjCreate("InternetExplorer.Application")
$o_IETwo.theatermode = True
$o_IETwo.fullscreen = True
$o_IETwo.statusbar = False
_IENavigate($o_IETwo, 'about:blank')

I hope this helps. The other folks here can add more insights.

Share this post

Link to post
Share on other sites


You are overlaying your controls/windows and after the 2nd guicreate you do NOT do a GuiSetState() to show the gui...


edit: This is not launching the command processor...

; launch the command prompt (black on white, without the operating system message)
$pid = run("C:\Program Files (x86)\Cisco\Router Manager\Router Administration.exe")

Also, not sure if winsetstate is the same as guisetstate...

edit2: Output from the cmd window is not read with windows cmds/funcs, rather with stdoutread.  So I am not sure what you expect from creating a cmd window.

If you outline what you are trying to do there are probably examples available.

Edited by kylomas
additional info

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post

Link to post
Share on other sites

@kylomas put simply I'm just trying to embed 2 browser windows and the router application.  We are doing web testing and want to watch the front end in one browser window, the back end in the other browser window, and the router in the 3rd.  This will be distributed to a few of our offices so it needs to be a standard GUI that encompasses both browsers and the router GUI in one AutoIT GUI.

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By matwachich
      Hi AutoIters!
      Here is my new UDF about GUIs: it's an enhanced mixture of Advanced InputBox (deprecated) and KODA Parser (deprecated), with additional functions.
      What you can do with it:
      Parse KODA files and directly create GUIs (_GUIUtils_CreateFromKODA) Parse a simple JSON form definition to simply create advanced InputBoxes with any amount/type of input controls (_GUIUtils_CreateFromJSON) Created GUIs are returned as Scripting.Dictionary objects, and you have helper functions to access GUIs controls by their names (_GUIUtils_HWnd, _GUIUtils_CtrlID, _GUIUtils_HCtrl ...) A function that can make a GUI created from KODA/JSON (defined by it's $oForm object) and make it a modal InputDialogBox (just like InputBox, but returns all entered data as Scripting.Dictionary object) Functions are documented, and there are some examples.
      Consider this UDF as beta, but since I'm currently using it in a small commercial project, it should become production ready in near future.
      To always get the latest code version, get it from Github (more up to date than this topic).
      Update 04/02/2020:
      New simple application example Fixed focused control handling in _GUIUtils_InputDialog Reset input values before returning from _GUIUtils_InputDialog Fixed CloseOnEsc in _GUIUtils_InputDialog Fixed Input not reset Fixed all ListBox items are selected Project now on GitHub https://github.com/matwachich/autoit-guiutils/
      Update 05/02/2020:
      Support for nodate for Date and Time input controls (pass null value) New handling of focused control _GUIUtils_InputDialog: Now, you can specify the focused control in $oInitialData by setting "controlName:focus" = True Updated documentation of _GUIUtils_InputDialog Update 07/02/2020:
      Bug corrected when setting Data input control Added: abillity to read a single input control New functions (_GUIUtils_GetInputs, _GUIUtils_WriteInputs), documentation completion. Readme file and screenshots on Github Page  
    • By antonioj84
      I am not able to use the $GUI_READ_EXTENDED with the  Metro UDF,  any work around ?
      Local $aPos[2] = [$Radio1, $Radio2] For $Radio In $aPos If GUICtrlRead($Radio) = $GUI_UNCHECKED Then ContinueLoop IniWrite($sGUIstate_IniFile, "Data", "POS", GUICtrlRead($Radio, $GUI_READ_EXTENDED)) ;; return the text of the menu item ExitLoop Next  
    • By _Vlad
      Hello forum,
      I want to create a program with multiple menus and many elements inside. The problem is my way of doing this and below I have an example of how I do these menus.
      I know it's a bad way of doing them as using this method for more elements and menus cause big flickering.
      Can someone please help me with some tips of optimizing this or tell me another way of creating that menus with many elements without cause flickering? From a long time ago I still try to solve this but without any results, just small improvements.
      Many thanks for everyone.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $MENU_HOVER = '' Global $MENU_SELECTED = '' Global $COLOR_STANDARD = 0x94A5E9 Global $COLOR_HOVER = 0x8292d1 Global $COLOR_SELECTED = 0x7584bf $MENU = GUICreate("Menu", 615, 437, -1, -1, -1, -1, 0) GUISetFont(10, 400, 0, "Arial") $MENU_1 = GUICtrlCreateLabel("Menu 1", 8, 24, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE)) $MENU_2 = GUICtrlCreateLabel("Menu 2", 8, 56, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE)) $MENU_3 = GUICtrlCreateLabel("Menu 3", 8, 88, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE)) ;MENU 1 ELEMENTS $MENU_1_ELEMENT_1 = GUICtrlCreateButton("Menu1 Button", 128, 24, 147, 25) ;MENU 2 ELEMENTS $MENU_2_ELEMENT_1 = GUICtrlCreateButton("Menu2 Button", 128, 24, 147, 25) $MENU_2_ELEMENT_2 = GUICtrlCreateLabel("Another element", 128, 64, 99, 20) _Design() _Hide_All() GUISetState(@SW_SHOW, $MENU) While 1 $Cursor = GUIGetCursorInfo($MENU) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $MENU_1 _Previous_Selected_Cancel() $MENU_SELECTED = 'Menu1' GUICtrlSetBkColor($MENU_1, $COLOR_SELECTED) _Show('Menu1') Case $MENU_2 _Previous_Selected_Cancel() $MENU_SELECTED = 'Menu2' GUICtrlSetBkColor($MENU_2, $COLOR_SELECTED) _Show('Menu2') Case $MENU_3 _Previous_Selected_Cancel() $MENU_SELECTED = 'Menu3' GUICtrlSetBkColor($MENU_3, $COLOR_SELECTED) _Show('Menu3') EndSwitch If $Cursor[4] = $MENU_1 Then If $MENU_HOVER <> 'Menu1' And $MENU_SELECTED <> 'Menu1' Then _Previous_Hover_Cancel() GUICtrlSetBkColor($MENU_1, $COLOR_HOVER) $MENU_HOVER = 'Menu1' EndIf ElseIf $Cursor[4] = $MENU_2 Then If $MENU_HOVER <> 'Menu2' And $MENU_SELECTED <> 'Menu2' Then _Previous_Hover_Cancel() GUICtrlSetBkColor($MENU_2, $COLOR_HOVER) $MENU_HOVER = 'Menu2' EndIf ElseIf $Cursor[4] = $MENU_3 Then If $MENU_HOVER <> 'Menu3' And $MENU_SELECTED <> 'Menu3' Then _Previous_Hover_Cancel() GUICtrlSetBkColor($MENU_3, $COLOR_HOVER) $MENU_HOVER = 'Menu3' EndIf Else _Previous_Hover_Cancel() $MENU_HOVER = 'Idle' EndIf WEnd Func _Design() GUICtrlSetColor($MENU_1, 0xFFFFFF) GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD) GUICtrlSetCursor($MENU_1, 0) GUICtrlSetColor($MENU_2, 0xFFFFFF) GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD) GUICtrlSetCursor($MENU_2, 0) GUICtrlSetColor($MENU_3, 0xFFFFFF) GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD) GUICtrlSetCursor($MENU_3, 0) EndFunc ;==>_Design Func _Hide_All() GUICtrlSetState($MENU_1_ELEMENT_1, $GUI_HIDE) GUICtrlSetState($MENU_2_ELEMENT_1, $GUI_HIDE) GUICtrlSetState($MENU_2_ELEMENT_2, $GUI_HIDE) EndFunc ;==>_Hide_All Func _Show($MENU_SHOW) _Hide_All() If $MENU_SHOW = 'Menu1' Then GUICtrlSetState($MENU_1_ELEMENT_1, $GUI_SHOW) ElseIf $MENU_SHOW = 'Menu2' Then GUICtrlSetState($MENU_2_ELEMENT_1, $GUI_SHOW) GUICtrlSetState($MENU_2_ELEMENT_2, $GUI_SHOW) ElseIf $MENU_SHOW = 'Menu3' Then EndIf EndFunc ;==>_Show Func _Previous_Hover_Cancel() If $MENU_HOVER = 'Menu1' Then If $MENU_SELECTED <> 'Menu1' Then GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD) ElseIf $MENU_HOVER = 'Menu2' Then If $MENU_SELECTED <> 'Menu2' Then GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD) ElseIf $MENU_HOVER = 'Menu3' Then If $MENU_SELECTED <> 'Menu3' Then GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD) EndIf EndFunc ;==>_Previous_Hover_Cancel Func _Previous_Selected_Cancel() If $MENU_SELECTED = 'Menu1' Then GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD) If $MENU_SELECTED = 'Menu2' Then GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD) If $MENU_SELECTED = 'Menu3' Then GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD) EndFunc ;==>_Previous_Selected_Cancel  
    • By Tony007
      is it possible to export only the area "$idOutput" with the TEXT as a PNG?
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Example() Func Example() Local $hGUI = GUICreate("Test", 700, 700, -1, -1) Local $input1 = GUICtrlCreateInput("", 10, 10, 150, 20) Local $idButtonStart = GUICtrlCreateButton("Start", 200, 10, 50, 30) Local $idButtonClear = GUICtrlCreateButton("Clear", 260, 10, 50, 30) Local $idButtonExport = GUICtrlCreateButton("Export", 320, 10, 50, 30) Local $idOutput = GUICtrlCreateLabel("TEXT", 10, 50, 500, 500, BitOR($BS_PUSHLIKE, $SS_CENTER)) GUICtrlSetFont($idOutput, 45, 800, "", "Impact") GUISetState(@SW_SHOW, $hGUI) ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButtonStart $ContentInput1 = GUICtrlRead($input1) GUICtrlSetData($idOutput, $ContentInput1) Case $idButtonClear GUICtrlSetData($input1, "") GUICtrlSetData($idOutput, "") Case $idButtonExport EndSwitch WEnd GUIDelete($hGUI) Exit EndFunc ;==>Example  
    • By muchki
      i am more or less happy with my code
      only the X button does not exit
      what can i do?
      I made an 'exit' button and it works
      pressing Esc works
      just the X button not working
      here's my code:
      URLTrimmer 1.5.2 12 21 2019.txt
  • Create New...