Jump to content
Sign in to follow this  
kev51773

Use an applications window within your gui

Recommended Posts

kev51773

I'll probably describe this badly, so bear with me.

Does anyone know of a way (using dll's or whatever if required) to launch an application from within my script, but to display that application within my gui window rather than in its own window.

A simple example would be to create a tabbed gui that for example had notepad running in one tab and calc running in another. Preferably neither of them being visible on the task bar?

Hopefully that makes sense.

Share this post


Link to post
Share on other sites
Zedna

Base idea & concept:

#include <GUIConstants.au3>

AutoItSetOption("WinTitleMatchMode", 4)

$gui = GUICreate("My GUI", 300, 200,0,0,BitOr($GUI_SS_DEFAULT_GUI,$WS_CLIPCHILDREN,$WS_SIZEBOX))
GUISetState (@SW_SHOW) 
      $pid = Run("notepad.exe", "", @SW_MAXIMIZE)
WinWaitActive("[CLASS:Notepad]")
$child = WinGetHandle("[CLASS:Notepad]")
_SetParent($child,$gui) 

While 1
    $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend


Func _SetParent($id_child, $h_parent)
    If Not IsHWnd($h_parent) Then $h_parent = HWnd($h_parent)
    If Not IsHWnd($id_child) Then $id_child = GUICtrlGetHandle($id_child)
    If DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $id_child, "hwnd", $h_parent) <> 0 Then
        Return 1
    Else
        seterror(1)
        Return 0
    EndIf
EndFunc

Share this post


Link to post
Share on other sites
kev51773

Base idea & concept:

#include <GUIConstants.au3>

AutoItSetOption("WinTitleMatchMode", 4)

$gui = GUICreate("My GUI", 300, 200,0,0,BitOr($GUI_SS_DEFAULT_GUI,$WS_CLIPCHILDREN,$WS_SIZEBOX))
GUISetState (@SW_SHOW) 
      $pid = Run("notepad.exe", "", @SW_MAXIMIZE)
WinWaitActive("[CLASS:Notepad]")
$child = WinGetHandle("[CLASS:Notepad]")
_SetParent($child,$gui) 

While 1
    $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend


Func _SetParent($id_child, $h_parent)
    If Not IsHWnd($h_parent) Then $h_parent = HWnd($h_parent)
    If Not IsHWnd($id_child) Then $id_child = GUICtrlGetHandle($id_child)
    If DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $id_child, "hwnd", $h_parent) <> 0 Then
        Return 1
    Else
        seterror(1)
        Return 0
    EndIf
EndFunc
Thanks, that's exactly what I was looking for.

Share this post


Link to post
Share on other sites
kev51773

I'm having problems implementing that method.

I'm basically trying to create a window containing multiple instances of radmin viewer.

Grabbing 1 instance works fine. When I get my second instance, it causes the first one to be displayed in the taskbar even though it is still confined to the gui window.

Basically, all but the last instance are displayed on the taskbar.

CODE
#include <GUIConstants.au3>

#include <Array.au3>

AutoItSetOption("WinTitleMatchMode", 4)

$aPids = _ArrayCreate(0)

$aHandles = _ArrayCreate(0)

$gui = GUICreate("My GUI", @DesktopWidth - 6, @DesktopHeight - 63,0,0,BitOr($GUI_SS_DEFAULT_GUI,$WS_CLIPCHILDREN,$WS_SIZEBOX))

GUISetState (@SW_SHOW)

$sRadminDir = (@ProgramFilesDir & "/Radmin")

FileChangeDir($sRadminDir)

_AddMachine("pc1","password")

_AddMachine("pc2","password")

_AddMachine("pc3","password")

While 1

$msg = GUIGetMsg()

Switch $msg

Case $GUI_EVENT_CLOSE

For $i = 1 to $aPids[0]

ProcessClose($aPids[$i])

Next

Exit

EndSwitch

Wend

Func _AddMachine($pcname,$password)

$pid = Run("radmin.exe /noinput /connect:" & $pcname & ":" & "4899", $sRadminDir, @SW_MAXIMIZE)

_ArrayAdd($aPids,$pid)

$aPids[0] = $aPids[0] + 1

WinWaitActive("Enter password for " & $pcname)

ControlSend("Enter password for " & $pcname,"","[iD:1048]",$password,1)

ControlClick("Enter password for " & $pcname,"","[iD:120]")

WinWaitActive($pcname)

$child = WinGetHandle($pcname)

$aHandles[0] = $aHandles[0] + 1

_ArrayAdd($aHandles,$child)

$iWidth = 0

$iHeight = 0

While $iHeight < 200

Sleep(50)

$aWinPos = WinGetPos($pcname)

If IsArray($aWinPos) Then

$iHeight = $aWinPos[3]

Endif

Wend

MouseClick("left",$aWinPos[0] + 10,$aWinPos[1] + 10,1,0)

Send("{DOWN 9}")

Send("{ENTER}")

_SetParent($child,$gui)

EndFunc

Func _SetParent($id_child, $h_parent)

msgbox(0,"","adding " & $id_child)

If Not IsHWnd($h_parent) Then $h_parent = HWnd($h_parent)

If Not IsHWnd($id_child) Then $id_child = GUICtrlGetHandle($id_child)

If DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $id_child, "hwnd", $h_parent) <> 0 Then

Return 1

Else

seterror(1)

Return 0

EndIf

EndFunc

Share this post


Link to post
Share on other sites
Pauletp

I am a newbie and also interested in showing an application running in a GUI.

I tried to run the code you posted but the result is just an emtpy GUI and the script has paused.

Do you have an idea how to test to make it work on my XP machine?

--------

Base idea & concept:

#include <GUIConstants.au3>

AutoItSetOption("WinTitleMatchMode", 4)

$gui = GUICreate("My GUI", 300, 200,0,0,BitOr($GUI_SS_DEFAULT_GUI,$WS_CLIPCHILDREN,$WS_SIZEBOX))
GUISetState (@SW_SHOW) 
      $pid = Run("notepad.exe", "", @SW_MAXIMIZE)
WinWaitActive("[CLASS:Notepad]")
$child = WinGetHandle("[CLASS:Notepad]")
_SetParent($child,$gui) 

While 1
    $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend


Func _SetParent($id_child, $h_parent)
    If Not IsHWnd($h_parent) Then $h_parent = HWnd($h_parent)
    If Not IsHWnd($id_child) Then $id_child = GUICtrlGetHandle($id_child)
    If DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $id_child, "hwnd", $h_parent) <> 0 Then
        Return 1
    Else
        seterror(1)
        Return 0
    EndIf
EndFunc

Share this post


Link to post
Share on other sites
AzKay

Works fine here.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Notepad", 633, 454, 193, 125, $WS_CLIPCHILDREN)
GUISetState(@SW_SHOW)

Run("notepad")
WinWaitActive("Untitled - Notepad")
$Notepad = WinGetHandle("Untitled - Notepad")
_SetParent($Notepad, $hGUI)
WinSetState($Notepad, "", @SW_MAXIMIZE)

While 1
    
WEnd

Func _SetParent($id_child, $h_parent)
    If Not IsHWnd($h_parent) Then $h_parent = HWnd($h_parent)
    If Not IsHWnd($id_child) Then $id_child = GUICtrlGetHandle($id_child)
    If DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $id_child, "hwnd", $h_parent) <> 0 Then
        Return 1
    Else
        seterror(1)
        Return 0
    EndIf
EndFunc

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

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  

×