Jump to content

GuiCtrlCreateDummy with Child window not working


Go to solution Solved by Melba23,

Recommended Posts

Posted

I am trying to understand child windows and dummy controls, and this code works great if i take out the child window code, but as soon as i want to add a child window my code breaks.  Any idea how to get around this?

#include <GUIConstantsEx.au3>

; Create parent
$hGUI = GUICreate("Parent", 100, 200)

$hButton_Child = GUICtrlCreateButton("Child", 10, 100, 80, 30)
$hButton_Test  = GUICtrlCreateButton("", 10, 50, 80, 30)
$input = GUICtrlCreateInput("", 10, 10, 80, 30)
$ButtonDummy = GUICtrlCreateDummy()
GUISetState()

; Create child
$hGUI_Child = GUICreate("Child", 200, 200)

GUISetState(@SW_HIDE)

Dim $EnterArray[1][2] = [["{ENTER}", $ButtonDummy]]
GUISetAccelerators($EnterArray)


While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton_Test
            MsgBox(0, "Test", "You pressed the button!")
        Case $hButton_Child
            GUISetState($GUI_DISABLE, $hGUI)
            GUISetState(@SW_SHOW, $hGUI_Child)
            While 1

                Switch GUIGetMsg()
                    Case $GUI_EVENT_CLOSE
                        GUISetState(@SW_HIDE, $hGUI_Child)
                        GUISetState($GUI_ENABLE, $hGUI)
                        ExitLoop
                EndSwitch
            WEnd
        Case $ButtonDummy
            EnterPressed()
    EndSwitch

WEnd

Func EnterPressed()

    ;When they press Enter after typing in the coop, fill out all the buttons with the appropriate information
    $coop = GUICtrlRead($Input)
    GUICtrlSetData($hButton_Test, "TESTING")
    GUICtrlSetState($Input, $GUI_FOCUS)
EndFunc   ;==>Enter
  • Moderators
  • Solution
Posted

hiimjoey11,

Accelerator keys are linked to the last created GUI - in your code as posted that is the child. So move the GUISetAccelerators section to before the child GUI creation and all should work as you expect. ;)

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

 

Posted

hiimjoey11,

Accelerator keys are linked to the last created GUI - in your code as posted that is the child. So move the GUISetAccelerators section to before the child GUI creation and all should work as you expect. ;)

M23

Worked like a charm! Thanks for the quick response :D

  • Moderators
Posted

hiimjoey11,

Glad I could help. :)

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

 

  • 5 years later...
Posted (edited)

Hi all :)
Though this topic is old, I would like to resurrect it and ask a very related question.
The "child" window discussed in the precedent comments didn't have a $WS_CHILD style, but what would happen if it had it ?

Melba23 wrote above :

On 11/11/2014 at 2:56 PM, Melba23 said:

Accelerator keys are linked to the last created GUI [...]

But the script below doesn't allow to link any Accelerator key to a "child with style" window (i.e a child window created with $WS_CHILD style) even if the Accelerator key (Enter) is defined just after the child window is created.

In the script below, trying to key Enter doesn't trigger anything.
So does it mean that you can't link any Accelerator key to a child window created with $WS_CHILD style ?

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

$hGUI1 = GUICreate("Parent", 600, 300, -1, -1, -1, $WS_EX_WINDOWEDGE)

$hGUI2 = GUICreate("Child (style $WS_CHILD)", 400, 200, 100, 40, _
    BitOR($WS_CHILD, $WS_OVERLAPPEDWINDOW), -1, $hGUI1)
GUISetBkColor($COLOR_BLUE, $hGUI2)

$idDummy_Enter = GUICtrlCreateDummy()
Global $aAccelKeys[1][2] = [["{ENTER}", $idDummy_Enter]]
GUISetAccelerators($aAccelKeys)
; GUISetAccelerators($aAccelKeys, $hGUI2)
; GUISetAccelerators($aAccelKeys, $hGUI1)

GUISetState(@SW_SHOW, $hGUI1)
GUISetState(@SW_SHOW, $hGUI2)

WinActivate($hGUI2)
Sleep(250)
If Not WinActive($hGUI2) Then ; 0 if not active, its handle if active
    MsgBox($MB_TOPMOST, "Note", "Child GUI2 not Active")
EndIf

$iInc = 0 ; counter used when we click inside blue GUI2, to ConsoleWrite...

While 1
    $aMsg = GUIGetMsg($GUI_EVENT_ARRAY)

    Switch $aMsg[1]
        Case $hGUI1
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    _Exit()
            EndSwitch

        Case $hGUI2
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hGUI2)

                Case $GUI_EVENT_PRIMARYDOWN
                    $iInc += 1
                    ConsoleWrite("Click in GUI2 => " & $iInc & @lf)

                Case $idDummy_Enter ; will never happen when Accelerators are linked to GUI2
                    MsgBox($MB_TOPMOST, "Ok", "Enter was pressed")
            EndSwitch
    EndSwitch
WEnd

;===========
Func _Exit()
    GUIDelete($hGUI2)
    GUIDelete($hGUI1)
    Exit
EndFunc

 

Edited by pixelsearch
Slightly modified code to reflect the image below

"I think you are searching a bug where there is no bug... don't listen to bad advice."

  • 2 weeks later...
Posted
On 9/5/2020 at 10:17 PM, pixelsearch said:

So does it mean that you can't link any Accelerator key to a child window created with $WS_CHILD style ?

Just wanted to share with you an explanation I just found at Microsoft's :

"Only a top-level window can be an active window. When the user is working with a child window, the system activates the top-level parent window associated with the child window."

https://docs.microsoft.com/en-us/windows/win32/winmsg/window-features

So if the child window can never be the Active window, then it seems to me that Accelerators keys should always be linked to the parent window. That's why the Enter Key can't be triggered in the script above (as it is linked to the child window)

980756724_Childwindownotactive.png.337ce208b820e22cccfb47e9112c475d.png

"I think you are searching a bug where there is no bug... don't listen to bad advice."

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...