hiimjoey11 Posted November 11, 2014 Share Posted November 11, 2014 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? expandcollapse popup#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 Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted November 11, 2014 Moderators Solution Share Posted November 11, 2014 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
hiimjoey11 Posted November 11, 2014 Author Share Posted November 11, 2014 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 11, 2014 Moderators Share Posted November 11, 2014 hiimjoey11,Glad I could help. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Zedna Posted November 15, 2014 Share Posted November 15, 2014 There is second optional parameter in GUISetAccelerators() where you can put handle to your GUI returned by GUICreate() Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
pixelsearch Posted September 5, 2020 Share Posted September 5, 2020 (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 ? expandcollapse popup#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 September 14, 2020 by pixelsearch Slightly modified code to reflect the image below Link to comment Share on other sites More sharing options...
pixelsearch Posted September 14, 2020 Share Posted September 14, 2020 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) Letraindusoir 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now