Sign in to follow this  
Followers 0
Nevercom

How to make AutoIt GUI child of another Window ?

8 posts in this topic

#1 ·  Posted (edited)

I wanna make a GUI in AutoIt and make it REAL child of my project window (It's not an AutoIt GUI)

I searched the forum and found this on making child window:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Main GUI", 300, 200)
GUISetState(@SW_SHOW, $hGUI)

$hGUI_Child = GUICreate("Child GUI", 200, 100, -1, -1, -1, $WS_EX_TOPMOST, $hGUI)

GUIRegisterMsg($WM_ACTIVATE, "WM_ACTIVATE")

GUISetState(@SW_SHOW, $hGUI_Child)

GUISetState(@SW_DISABLE, $hGUI)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_ACTIVATE($hWnd, $Msg, $wParam, $lParam)
    Local $wActive = BitAND($wParam, 0x0000FFFF)
   
    Switch $hWnd
        Case $hGUI_Child
            If Not $wActive Then
                WinActivate($hGUI)
                WinActivate($hGUI_Child)
            EndIf
    EndSwitch
   
    Return $GUI_RUNDEFMSG
EndFunc

It works perfect, Now I want to use this code to make AutoIt GUI child of my project window, I tried This after some try and error:

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

if @Compiled AND $CmdLine[0] == 0 then
    MsgBox(16,"Error","Missing cmd parameters!")
    Exit
endif

if @Compiled then
    $title = $CmdLine[1]; Get window title from CMD
Else
    $title = "Welcome!"; only for debugging
endif
$Parent = WinGetHandle($title)
;GUISetState(@SW_DISABLE, $Parent)
WinSetState($title,"",@SW_DISABLE)
if @error Then
    MsgBox(48,"","Can't find window with title " & $title)
    exit
endif
#Region ### START Koda GUI section ### Form=
$hGUI_Child = GUICreate("Child GUI", 200, 100, -1, -1, -1, $WS_EX_TOPMOST, $Parent)
;Label1 = GUICtrlCreateLabel("This is About Box.", 48, 24, 89, 17)
;$Button1 = GUICtrlCreateButton("Button1", 128, 50, 52, 30, 0)
GUIRegisterMsg($WM_ACTIVATE, "WM_ACTIVATE")

GUISetState(@SW_SHOW, $hGUI_Child)



Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE 
WinSetState($title,"",@SW_ENABLE)

Func WM_ACTIVATE($hWnd, $Msg, $wParam, $lParam)
    Local $wActive = BitAND($wParam, 0x0000FFFF)
   
    Switch $hWnd
        Case $hGUI_Child
            If Not $wActive Then
                WinSetState($title,"",@SW_ENABLE)
                WinActivate($hGUI_Child)
            EndIf
    EndSwitch
   
    Return $GUI_RUNDEFMSG
EndFunc

but its not gonna work for me as the Original code does on AutoIt GUI (Parent).

I want my Parent window to be disabled (And could not get focus) till the AutoIt GUI(Child Window) is running

Could you please help me about how to do this ?

Thanks.

Edited by Nevercom

[left] [/left]

Share this post


Link to post
Share on other sites



No hope to do this ???? :D


[left] [/left]

Share this post


Link to post
Share on other sites

You can only make a child gui for a gui created in autoit, but why did you want to? There may be another way.


The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

You could make a gui with a loop that if the other window is activated that the gui pulls itself to the front. Than in your gui use winsetstate to disable the other window while your gui is active.


Giggity

Share this post


Link to post
Share on other sites

Thanks for reply,

I don't know much about AutoIt, I'm new here.

As I said, i have found that code and changed it a bit but it's not what really i want, it disables the parent window, but not completely, Parent window can get focus sometimes, what i want is to make a GUI in AutoIt and make it REALLY a child of my parent window which is not created by AutoIt, i mean parent window should be disabled till the child is closed.

but i don't know how....

Thanks anyway


[left] [/left]

Share this post


Link to post
Share on other sites

As far as I know, this is impossible. You can make a gui it close when another window closes, you can center it over another window, etc, but you cannot make it actually a child of that window. There may be a way to disable the other window while the gui exists if that is all you need, I'll try a few things.


The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

i mean parent window should be disabled till the child is closed.

This works for me
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$class = "[CLASS:Notepad]"

If Not WinExists($class) Then $pid = Run("notepad.exe")
WinWait($class)
WinActivate($class)
WinWaitActive($class)
$hParent = WinGetHandle($class)
$hChild = GUICreate("Child GUI", 200, 100, -1, -1, -1, $WS_EX_TOPMOST, $hParent)
GUISetState()
WinSetState($hParent, "", @SW_DISABLE)

Do
    Sleep(10)
    If Not ProcessExists($pid) then 
        GUIDelete($hChild)
        Exit
    EndIf
    
Until GUIGetMsg() = $GUI_EVENT_CLOSE

WinSetState($hParent, "", @SW_ENABLE)

Share this post


Link to post
Share on other sites

Thanks ResNullius,

It works like a charm !! :wink:


[left] [/left]

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