Sign in to follow this  
Followers 0
dieterhatn

Run Program inside GUI

13 posts in this topic

Hi there, Is there a way to run an external program inside my Autoit GUI? Or even two programs in one GUI? thanks

Share this post


Link to post
Share on other sites



You mean like creating a button and on pressing it, it will run another program?


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

 

You mean like creating a button and on pressing it, it will run another program?

 

I meant if you run a program within your script, the window will be attached to your gui.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

It would have to be attached manually by you through parent - child settings. I'm positive though if you just ran a random program from inside the GUI like notepad, it will not be attached to the GUI automatically, but using something like this:

$Form1 = GUICreate("Attached window!", 629, 437, 314, 132, default,default, WinGetHandle("AutoIt Help")) ; as you can see we get the handle and attach it as the parent to the created GUI window -- essentially making our GUI created a child GUI
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

It would have to be attached manually by you through parent - child settings. I'm positive though if you just ran a random program from inside the GUI like notepad, it will not be attached to the GUI automatically, but using something like this:

$Form1 = GUICreate("Attached window!", 629, 437, 314, 132, default,default, WinGetHandle("AutoIt Help")) ; as you can see we get the handle and attach it as the parent to the created GUI window -- essentially making our GUI created a child GUI

Isn't it exactly vice-versa? The doc says that if you define a Window Handle, the autoit GUI will become a child of the window you define.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Yes, it is somewhat the other way around, my apologies. :sweating:

Here is something that can the right way round:

#include <WinAPI.au3>

_WinAPI_SetParent(WinGetHandle("whatever window you want to make a child here", $hWnd) ; first param is the child window or the window we want to make a child and the second param is our created GUI
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

That somewhat does what i want, but im experiencing some problems.

Im trying arround with a simple GUI and a notepad window i want to attach, but whenever I set the parent the notepad window just disappears.

The process is still running but its not visible anymore.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

works for me with this script:

#include <WinAPI.au3>
#include <GUIConstants.au3>

Local $msg, $hwnd, $Nhandle

$hwnd = GUICreate("hello")
GUISetState()
Run("notepad")

$Nhandle = WinGetHandle("Notepad")

_WinAPI_SetParent($Nhandle, $hwnd)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

works for me with this script:

#include &lt;WinAPI.au3&gt;#include &lt;GUIConstants.au3&gt;Local $msg, $hwnd, $Nhandle$hwnd = GUICreate("hello")GUISetState()Run("notepad")$Nhandle = WinGetHandle("Notepad")_WinAPI_SetParent($Nhandle, $hwnd)While 1&nbsp;&nbsp; &nbsp;$msg = GUIGetMsg()&nbsp;&nbsp; &nbsp;Switch $msg&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Case $GUI_EVENT_CLOSE&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Exit&nbsp;&nbsp; &nbsp;EndSwitchWEnd

What exactly happens when you run this code? for me nothing happens :/

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

#include <WinAPI.au3>
#include <GUIConstants.au3>

Local $msg, $hwnd, $Nhandle

$hwnd = GUICreate("hello")
GUISetState()
$pid = Run("notepad", "", @SW_HIDE)
ProcessWait($pid)
$Nhandle = WinGetHandle("Untitled - Notepad")

_WinAPI_SetParent($Nhandle, $hwnd)
_WinAPI_SetWindowLong($Nhandle, $GWL_STYLE, $WS_POPUP + $WS_VISIBLE)
WinMove($Nhandle, "", 0, 0)

While ProcessExists($pid)
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ProcessClose($pid)
    EndSwitch
WEnd

Edited by JohnOne
1 person likes this

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

What exactly happens when you run this code? for me nothing happens :/

You have not formatted it..

 

#include <WinAPI.au3>
#include <GUIConstants.au3>

Local $msg, $hwnd, $Nhandle

$hwnd = GUICreate("hello")
GUISetState()
$pid = Run("notepad", "", @SW_HIDE)
ProcessWait($pid)
$Nhandle = WinGetHandle("Untitled - Notepad")

_WinAPI_SetParent($Nhandle, $hwnd)
_WinAPI_SetWindowLong($Nhandle, $GWL_STYLE, $WS_POPUP + $WS_VISIBLE)
WinMove($Nhandle, "", 0, 0)

While ProcessExists($pid)
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ProcessClose($pid)
    EndSwitch
WEnd

 

Very cool. Just to understand you made the notepad window a pop-up and put it inside the GUI created? I like this.


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

I think it's better than what OP wanted ;)


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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  
Followers 0