Jump to content
Sign in to follow this  
n4rk0o

Resizing ActiveX object under Parent GUI

Recommended Posts

n4rk0o

Hello the AutoIT community,

I have a problem that is above my skills.

I would like to create a embedded GUI in another but the problem is that when I try to resize the parent GUI, the child GUI is disconnected from the parent.

The particularity is that the child GUI is an ActiveX object, an RDP session to be more explicit.

I past the code (a mix of 2 distincts code that I merged for the need):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Const $SM_CXFIXEDFRAME = 7
Local $oWINDOW = GUICreate("RDP", 1205, 801, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_CLIPSIBLINGS),$WS_EX_COMPOSITED); , $WS_EX_LAYERED) ; BitOR($WS_EX_TOOLWINDOW, $WS_EX_LAYERED))
  GUISetState(@SW_SHOW, $oWINDOW)
    Local $oBUTTON_1 = GUICtrlCreateButton('Connect me', 15, 40, 140, 20)
  GUICtrlSetResizing(-1,BitOr($Gui_DOCKTOP,$GUI_DOCKLEFT,$GUI_DOCKWIDTH,$GUI_DOCKHEIGHT))
  $wtitle = DllCall('user32.dll', 'int', 'GetSystemMetrics', 'int', $SM_CYCAPTION)
  $wtitle = $wtitle[0]
  $wside = DllCall('user32.dll', 'int', 'GetSystemMetrics', 'int', $SM_CXFIXEDFRAME)
  $wside = $wside[0]
  $childHt = (400 - 50)/2 - $wtitle - 2* $wside
  $childWid = 500/2 - 2 * $wside

Local $Child1_GUI = GUICreate("",1005,701,180,40,BitOR($WS_POPUP,$WS_POPUPWINDOW),$WS_EX_MDICHILD,$oWINDOW)
  DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($Child1_GUI), "hwnd", WinGetHandle($Child1_GUI))
  GUISetState(@SW_SHOW, $Child1_GUI)
  GUISwitch($oWINDOW)
  GUIRegisterMsg($WM_SIZE, "SetChildrenToBed")
  Opt("mousecoordmode", 2)
  $winact = ''
  GUISetState()
    GUISetState(@SW_SHOW)
    While 1
        Local $eMSG = GUIGetMsg()
        Switch $eMSG
   Case $oBUTTON_1
    GUISetState(@SW_SHOW,$Child1_GUI)
    RDP_Session ($Child1_GUI,1005,701)
   Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
Func RDP_Session ($GUI,$iGUIWINDOW_WIDTH,$iGUIWINDOW_HEIGHT)
Global $oRDP = ObjCreate("MsTscAx.MsTscAx.8")
$GUIActiveX = GUICtrlCreateObj($oRDP, 0, 0, $iGUIWINDOW_WIDTH, $iGUIWINDOW_HEIGHT)
GUICtrlSetResizing ($GUIActiveX,$GUI_DOCKAUTO)
$oRDP.Server = "server"
$oRDP.Domain = "domain"
$oRDP.UserName = "user"
$oRDP.Connect()
Opt("WinTitleMatchMode", 4)  ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("WinSearchChildren", 1)  ;0=no, 1=search children also
$sATLClass = ""
$aClasses = StringSplit(WinGetClassList($GUI,""),@LF)
For $i = 1 To $aClasses[0]
    If StringLeft($aClasses[$i],4) = "ATL:" Then
        $sATLClass = $aClasses[$i]
        ExitLoop
    EndIf
Next
$hUIContainerClass = ControlGetHandle($GUI, "", "[CLASS:UIContainerClass]")
$hUIMainClass = ControlGetHandle($GUI, "", "[CLASS:UIMainClass]")
$hATL = ControlGetHandle($GUI, "", "[CLASS:"&$sATLClass&"]")
ConsoleWrite("$hUIContainerClass (should not be 0 or blank):" & $hUIContainerClass & @crlf)
ConsoleWrite("$hUIMainClass (should not be 0 or blank):" & $hUIMainClass & @crlf)
ConsoleWrite("$hATL (should not be 0 or blank):" & $hATL & @crlf)
Const $WS_EX_NOPARENTNOTIFY = 0x4
Const $WS_EX_NOINHERITLAYOUT = 0x100000
$hUIContainerClassStyle = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_VISIBLE) ; 0x56000000
$hUIContainerClassStyleEx = BitOR($WS_EX_NOINHERITLAYOUT, $WS_EX_NOPARENTNOTIFY) ; 0x00100004
$hUIMainClassStyle = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_SYSMENU, $WS_VISIBLE) ; 0x56080000
$hUIMainClassStyleEx = 0x0
$hATLStyle = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_VISIBLE) ; 0x56000000
$hATLStyleEx = 0x0
$guiStyle = BitOR($WS_BORDER, $WS_CAPTION, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_DLGFRAME, $WS_GROUP, $WS_MAXIMIZE, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SYSMENU, $WS_TABSTOP, $WS_THICKFRAME, $WS_VISIBLE) ; 0x17CF0100
$guiStyleEx = $WS_EX_WINDOWEDGE ; 0x00000100
DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hUIContainerClass, "int", -16, "long", $hUIContainerClassStyle)
DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hUIContainerClass, "int", -20, "long", $hUIContainerClassStyleEx)
DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hUIMainClass, "int", -16, "long", $hUIMainClassStyle)
DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hUIMainClass, "int", -20, "long", $hUIMainClassStyleEx)
DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hATL, "int", -16, "long", $hATLStyle)
DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hATL, "int", -20, "long", $hATLStyleEx)
DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $gui, "int", -16, "long", $guiStyle)
DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $gui, "int", -20, "long", $guiStyleEx)
;~ AdlibRegister ( "checkconn", 1000)
;~ checkconn()
If $oRDP.Connected = 0 Then
$oRDP.Disconnect()
EndIf
Return 0
EndFunc
Func SetChildrenToBed($hWnd,$iMsg,$wparam,$lparam)
    Local $clientHt = BitAnd($lparam,0xffff)
    Local $clientWid = BitShift($lparam,16)
    WinMove($Child1_GUI,"",0,50,$clientHt/2,($clientWid-50)/2)
EndFunc

Thanks for your help.

Best regards

post-72243-0-53070100-1338458609_thumb.p

Share this post


Link to post
Share on other sites
stormbreaker

An example of embedding a child window in parent window:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Img_Path = @SystemDir & "Setup.bmp"

$Main_GUI = GuiCreate("Wizard Demo!", 400, 300, 0, 0, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS))
GuiSetBkColor(0xffffff)
_GuiCtrlCreateSeperator(0, 2, 265, 3, 396)

$Back_Button = GUICtrlCreateButton("<<Back", 170, 270, 60)
GUICtrlSetState(-1, $GUI_DISABLE)
$Next_Button = GUICtrlCreateButton("Next>>", 240, 270, 60)

$Exit_Button = GUICtrlCreateButton("Exit", 325, 270, 60)


$ChildGui_1 = GuiCreate("Child window 1", 400, 260, 5, 5)
$LabelGui1 = GUICtrlCreatePic($Img_Path, 2, 2, 160, 250, $SS_SUNKEN, $WS_EX_STATICEDGE+$WS_EX_CLIENTEDGE)
GUICtrlCreateLabel("Wellcome!", 240, 20, 150)
GUICtrlSetFont(-1, 12, 800)

DllCall("user32.dll", "int", "SetParent", "hwnd", $ChildGui_1, "hwnd", $Main_GUI)

GUISetState(@SW_SHOW, $Main_GUI)
GUISetState(@SW_SHOW, $ChildGui_1)

While 1
    $Msg = GUIGetMsg(1)
    Switch $Msg[0]
        Case $GUI_EVENT_CLOSE, $Exit_Button
            If $Msg[0] = $Exit_Button And Not _WinIsVisible($ChildGui_1) Then
                $Ask = _MsgBox(256+52, "Attention", "Are you sure you want to exit the Wizard now?", $Msg[1])
                If $Ask <> 6 Then ContinueLoop
            EndIf

            If $Msg[1] = $Main_GUI Then Exit
    EndSwitch
WEnd

Func _GuiCtrlCreateSeperator($Direction, $Left, $Top, $Width=3, $Lenght=25)
    Switch $Direction
        Case 0
            GUICtrlCreateLabel("", $Left, $Top, $Lenght, $Width, $SS_SUNKEN)
        Case 1
            GUICtrlCreateLabel("", $Left, $Top, $Width, $Lenght, $SS_SUNKEN)
    EndSwitch
EndFunc

Func _MsgBox($MsgBoxType, $MsgBoxTitle, $MsgBoxText, $MainGUI=0)
    Local $iRet = DllCall ("user32.dll", "int", "MessageBox", _
            "hwnd", $MainGUI, _
            "str", $MsgBoxText , _
            "str", $MsgBoxTitle, _
            "int", $MsgBoxType)
    Return $iRet[0]
EndFunc

Func _WinIsVisible($hWnd)
    Return BitAND(WinGetState($hWnd), 2)
EndFunc

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Share this post


Link to post
Share on other sites
n4rk0o

Hello,

Thank you for you example.

I have a problem about resizing the child GUI because it is an activeX object in this GUI.

What I want to do is to resizing the parent GUI and the child GUI simultaneous.

The problem is that when I try this, The child GUI is not embedded.

Try the code posted below if you want ;)

Best regards

Share this post


Link to post
Share on other sites
n4rk0o

Your trick didn't solved my problem.

Thank you for your help.

Share this post


Link to post
Share on other sites
stormbreaker

So, you want to resize a control? Then the modified example is here:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $Img_Path = @SystemDir & "Setup.bmp"
$Main_GUI = GuiCreate("Wizard Demo!", 400, 300, 0, 0, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS))
GuiSetBkColor(0xffffff)
_GuiCtrlCreateSeperator(0, 2, 265, 3, 396)
$Back_Button = GUICtrlCreateButton("<<Back", 170, 270, 60)
GUICtrlSetState(-1, $GUI_DISABLE)
$Next_Button = GUICtrlCreateButton("Next>>", 240, 270, 60)
$Exit_Button = GUICtrlCreateButton("Exit", 325, 270, 60)

$ChildGui_1 = GuiCreate("Child window 1", 400, 260, 5, 5, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS))
$LabelGui1 = GUICtrlCreatePic($Img_Path, 2, 2, 160, 250, $SS_SUNKEN, $WS_EX_STATICEDGE+$WS_EX_CLIENTEDGE)
GUICtrlSetResizing ($LabelGui1,$GUI_DOCKAUTO)
GUICtrlCreateLabel("Wellcome!", 240, 20, 150)
GUICtrlSetFont(-1, 12, 800)
DllCall("user32.dll", "int", "SetParent", "hwnd", $ChildGui_1, "hwnd", $Main_GUI)
GUISetState(@SW_SHOW, $Main_GUI)
GUISetState(@SW_SHOW, $ChildGui_1)
While 1
    $Msg = GUIGetMsg(1)
    Switch $Msg[0]
        Case $GUI_EVENT_CLOSE, $Exit_Button
            If $Msg[0] = $Exit_Button And Not _WinIsVisible($ChildGui_1) Then
                $Ask = _MsgBox(256+52, "Attention", "Are you sure you want to exit the Wizard now?", $Msg[1])
                If $Ask <> 6 Then ContinueLoop
            EndIf
           
            If $Msg[1] = $Main_GUI Then Exit
    EndSwitch
WEnd
Func _GuiCtrlCreateSeperator($Direction, $Left, $Top, $Width=3, $Lenght=25)
    Switch $Direction
        Case 0
            GUICtrlCreateLabel("", $Left, $Top, $Lenght, $Width, $SS_SUNKEN)
        Case 1
            GUICtrlCreateLabel("", $Left, $Top, $Width, $Lenght, $SS_SUNKEN)
    EndSwitch
EndFunc
Func _MsgBox($MsgBoxType, $MsgBoxTitle, $MsgBoxText, $MainGUI=0)
    Local $iRet = DllCall ("user32.dll", "int", "MessageBox", _
            "hwnd", $MainGUI, _
            "str", $MsgBoxText , _
            "str", $MsgBoxTitle, _
            "int", $MsgBoxType)
    Return $iRet[0]
EndFunc
Func _WinIsVisible($hWnd)
    Return BitAND(WinGetState($hWnd), 2)
EndFunc

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

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
Sign in to follow this  

×