Jump to content
Sign in to follow this  
TommyDDR

Force creation of controls in a specific window

Recommended Posts

TommyDDR

Hello there,
I am confronted with a problem of window creation, associated with events (or GUI_EVENT_XXX WM_XXX).
Here's my problem:
A fairly heavy window (> ​​4000 controls) is created during an event, time of creation is "too long" and if during that time I get another event, then the second window is created, then the program returns to the first to finish his work, but there window "active" (where controls are created) changed. The new controls are created on the second window.

Is there a way to force the creation of a label, input, etc, specifying the window?

Here's an example of my problem (run the program and click fast on close) We see that "Label gui : 0" is on $gui[1]

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

Opt("MustDeclareVars", 1)
Opt("GuiOnEventMode", 1)

Global $gui[2]
Global $label[2]
Global $taille[2] = [200, 100]

CreateGui(0)

While(True)
    Sleep(10)
WEnd

Func CreateGui($guiNumber)
    $gui[$guiNumber] = GUICreate("", $taille[0], $taille[1], 500+$taille[0]*$guiNumber, 500)
    GUISetOnEvent($GUI_EVENT_CLOSE, "close", $gui)
    GUICtrlCreateLabel("Label", 10, 20)
    GUISetState(@SW_SHOW, $gui)
    For $i = 1 To 4000
        
        GUICtrlCreateLabel("simulation 4000 controls", $taille[0]+10, 0)
    Next
    GUICtrlCreateLabel("Label gui : " & $guiNumber, 10, 40+$guiNumber*20)
EndFunc

Func close()
    If(IsHWnd($gui[1])) Then
        Exit
    Else
        CreateGui(1)
    EndIf
EndFunc
Edited by TommyDDR

_GUIRegisterMsg (Register more than 1 time the same Msg), _Resize_Window (GUICtrlSetResizing for children windows), _GUICtrlSetOnHover (Link a function when mouse go on, left, clic down, clic up, on a control), _InputHeure (Create an input for hour contain), _GUICtrlCalendar (Make a complete calendar), _GUICtrlCreateGraphic3D (Create a 3D graph), _ArrayEx.au3 (Array management), _GUIXViewEx.au3 (List/Tree View management).

Share this post


Link to post
Share on other sites
Melba23

TommyDDR,

Setting GUISwitch to the first GUI should solve the problem: :)

Func close()
    If (IsHWnd($gui[1])) Then
        Exit
    Else
        CreateGui(1)
    EndIf
    GUISwitch($gui[0])
EndFunc   ;==>close
Although I would suggest that stopping OnEvent mode during the control creation cycle would probably be a better solution. ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
TommyDDR
Thank's for your answer.
 
I actually created a window when the TCP event "NewClient" appears, therefore I do not choose when they connect and I can not stop listening and miss connections.

GUISwitch works if you know the GUI to switch, but in my case I can't know it advance, Is there way to know the GUI that is being used to create the controls?
Otherwise, I can create a table by storing the window being created and switch at the end of creation if another preceding it.
Edited by TommyDDR

_GUIRegisterMsg (Register more than 1 time the same Msg), _Resize_Window (GUICtrlSetResizing for children windows), _GUICtrlSetOnHover (Link a function when mouse go on, left, clic down, clic up, on a control), _InputHeure (Create an input for hour contain), _GUICtrlCalendar (Make a complete calendar), _GUICtrlCreateGraphic3D (Create a 3D graph), _ArrayEx.au3 (Array management), _GUIXViewEx.au3 (List/Tree View management).

Share this post


Link to post
Share on other sites
Melba23

TommyDDR,

If you are going to create these (possibly infinite) recursive functions then you will have such problems. Can you not store the new connection and then process it once the control creation has ended? :huh:

Otherwise I would suggest storing the current GUI handle and then switching back when the new GUI is complete - like this:

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

Opt("MustDeclareVars", 1)
Opt("GuiOnEventMode", 1)

Global $gui[2]
Global $label[2]
Global $taille[2] = [200, 200]
Global $aActive[1] = [0]

CreateGui(0)

While (True)
    Sleep(10)
WEnd

Func CreateGui($guiNumber)
    $gui[$guiNumber] = GUICreate("", $taille[0], $taille[1], 500 + $taille[0] * $guiNumber, 500)
    GUISetOnEvent($GUI_EVENT_CLOSE, "close", $gui)
    GUICtrlCreateLabel("Label", 10, 10)
    GUISetState(@SW_SHOW, $gui)

        For $i = 1 To 50
            GUICtrlCreateLabel($i, 20, $i + 20)
            Sleep(100)
        Next
    GUICtrlCreateLabel("Label gui : " & $guiNumber, 10, 40)
    ; Is there another GUI waiting to complete?
    If UBound($aActive) > 1 Then
        ; Switch to it
        GUISwitch($aActive[$aActive[0]])
        ; And remove it from the array
        ReDim $aActive[$aActive[0]]
        $aActive[0] -= 1
    EndIf
EndFunc   ;==>CreateGui

Func close()
    If (IsHWnd($gui[1])) Then
        Exit
    Else
        ; Get the current creation GUI
        Local $hCurrent_GUI = GUISwitch(WinGetHandle(AutoItWinGetTitle()))
        ; And store it
        $aActive[0] += 1
        ReDim $aActive[$aActive[0] + 1]
        $aActive[$aActive[0]] = $hCurrent_GUI
        ; Now create the new one
        CreateGui(1)
    EndIf
    GUISwitch($gui[0])
EndFunc   ;==>close
That seems to work - as long as you can accept the delay in completing the interrupted GUI. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
TommyDDR

GUISwitch(WinGetHandle(AutoItWinGetTitle())) is exactly what i want, thank you Melba


_GUIRegisterMsg (Register more than 1 time the same Msg), _Resize_Window (GUICtrlSetResizing for children windows), _GUICtrlSetOnHover (Link a function when mouse go on, left, clic down, clic up, on a control), _InputHeure (Create an input for hour contain), _GUICtrlCalendar (Make a complete calendar), _GUICtrlCreateGraphic3D (Create a 3D graph), _ArrayEx.au3 (Array management), _GUIXViewEx.au3 (List/Tree View management).

Share this post


Link to post
Share on other sites
Melba23

TommyDDR,

My pleasure. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
TommyDDR

After several tests, it seems that GUISwitch fail (and return 0x000000000) on

WinGetHandle(AutoItWinGetTitle())
We should not have the access for switching on it. Your script works thanks to

GUISwitch($gui[0])
of the close function .

The solution (not clean) is to create a "ghost" GUI for switching on.

 

If you have a better solution...

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

Opt("MustDeclareVars", 1)
Opt("GuiOnEventMode", 1)

Global $gui[2]
Global $label[2]
Global $taille[2] = [200, 200]
Global $aActive[1] = [0]
Global $guiGhost = GUICreate("")

CreateGui(0)

While (True)
    Sleep(10)
WEnd

Func CreateGui($guiNumber)
    $gui[$guiNumber] = GUICreate("", $taille[0], $taille[1], 500 + $taille[0] * $guiNumber, 500)
    GUISetOnEvent($GUI_EVENT_CLOSE, "close", $gui)
    GUICtrlCreateLabel("Label", 10, 10)
    GUISetState(@SW_SHOW, $gui)

        For $i = 1 To 20
            GUICtrlCreateLabel($i, 20, $i + 20)
            Sleep(100)
        Next
    GUICtrlCreateLabel("Label gui : " & $guiNumber, 10, 40)
    ; Is there another GUI waiting to complete?
    If UBound($aActive) > 1 Then
        ; Switch to it
        GUISwitch($aActive[$aActive[0]])
        ; And remove it from the array
        ReDim $aActive[$aActive[0]]
        $aActive[0] -= 1
    EndIf
EndFunc   ;==>CreateGui

Func close()
    If (IsHWnd($gui[1])) Then
        Exit
    Else
        ; Get the current creation GUI
        Local $hCurrent_GUI = GUISwitch($guiGhost)
        ; And store it
        $aActive[0] += 1
        ReDim $aActive[$aActive[0] + 1]
        $aActive[$aActive[0]] = $hCurrent_GUI
        ; Now create the new one
        CreateGui(1)
    EndIf
EndFunc   ;==>close
Edited by TommyDDR

_GUIRegisterMsg (Register more than 1 time the same Msg), _Resize_Window (GUICtrlSetResizing for children windows), _GUICtrlSetOnHover (Link a function when mouse go on, left, clic down, clic up, on a control), _InputHeure (Create an input for hour contain), _GUICtrlCalendar (Make a complete calendar), _GUICtrlCreateGraphic3D (Create a 3D graph), _ArrayEx.au3 (Array management), _GUIXViewEx.au3 (List/Tree View management).

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  

×