TheAutomator Posted February 2, 2014 Posted February 2, 2014 (edited) Hello can someone help me please with this problem? #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $ParentForm = GUICreate("Example", 460, 260) Global $ChildForm1 = GUICreate("", 460, 260,0,0,$WS_CHILD,-1,$ParentForm) Global $GoTo_ChildForm2 = GUICtrlCreateButton("Next Page", 320, 20, 120, 40) GUISetState(@SW_SHOW) Global $ChildForm2 = GUICreate("", 460, 260,0,0,$WS_CHILD,-1,$ParentForm) Global $THIS_MUST_REACT_TO_ENTER_KEY = GUICtrlCreateButton("THIS BUTTON IS THE DEFAULT ONE, PRESS ENTER TO SEE IF IT WORKS...", 20, 200, 421, 41, $BS_DEFPUSHBUTTON);<- $BS_DEFPUSHBUTTON not pushed when I press the ENTER key. Global $Label = GUICtrlCreateLabel("TEXT CHANGES WHEN BUTTON IS PRESSED", 20, 80, 414, 28) GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif") GUISwitch($ParentForm) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GoTo_ChildForm2 GUISetState(@SW_HIDE,$ChildForm1) GUISetState(@SW_SHOW,$ChildForm2) Case $THIS_MUST_REACT_TO_ENTER_KEY GUICtrlSetData($Label,'IF YOU PRESSED ENTER IT WORKS!') EndSwitch WEnd In a normal form pressing enter is the same as pushing the button if the button is the "$BS_DEFPUSHBUTTON" I tried to do it with HotKeySet('{ENTER}','function') but then you have to code it so that if the form is out of focus, the hot-key must be disabled and I think that is not the best solution to... Thanks in advance! Edited February 2, 2014 by TheAutomator Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone
Moderators Solution Melba23 Posted February 2, 2014 Moderators Solution Posted February 2, 2014 TheAutomator,Child GUIs are funny beasts in AutoIt and quite often do not behave as you expect. I would add the $WS_EX_CONTROLPARENT extended style to the second child and then use an accelerator key like this:#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $ParentForm = GUICreate("Example", 460, 260) GUISetState(@SW_SHOW) Global $ChildForm1 = GUICreate("", 460, 260, 0, 0, $WS_CHILD, Default, $ParentForm) Global $GoTo_ChildForm2 = GUICtrlCreateButton("Next Page", 320, 20, 120, 40) GUISetState(@SW_SHOW) Global $ChildForm2 = GUICreate("", 460, 260, 0, 0, $WS_CHILD, $WS_EX_CONTROLPARENT, $ParentForm) Global $THIS_MUST_REACT_TO_ENTER_KEY = GUICtrlCreateButton("THIS BUTTON IS THE DEFAULT ONE, PRESS ENTER TO SEE IF IT WORKS...", 20, 200, 421, 41);<- $BS_DEFPUSHBUTTON not pushed when I press the ENTER key. Global $Label = GUICtrlCreateLabel("TEXT CHANGES WHEN BUTTON IS PRESSED", 20, 80, 414, 28) GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif") GUISetState(@SW_HIDE) Global $aAccelKeys[1][2] = [["{ENTER}", $THIS_MUST_REACT_TO_ENTER_KEY]] GUISetAccelerators($aAccelKeys, $ParentForm) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GoTo_ChildForm2 GUISetState(@SW_HIDE, $ChildForm1) GUISetState(@SW_SHOW, $ChildForm2) Case $THIS_MUST_REACT_TO_ENTER_KEY GUICtrlSetData($Label, 'IF YOU PRESSED ENTER IT WORKS!') EndSwitch WEndPlease ask if you have any questions - although I cannot explain why the original script did not work. 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
TheAutomator Posted February 2, 2014 Author Posted February 2, 2014 Melba23, Thanks for the help, I hope it's not a serious bug or something GUISetAccelerators did the trick for me kind regards, TheAutomator Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone
Moderators Melba23 Posted February 2, 2014 Moderators Posted February 2, 2014 TheAutomator,If you were to use a more conventional way of passing from one GUI to another rather than using that complicated "child" mode then you would not need any workarounds:#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Example", 460, 260) Global $GoTo_Form2 = GUICtrlCreateButton("Next Page", 320, 20, 120, 40) GUISetState(@SW_SHOW) Global $Form2 = GUICreate("", 460, 260) Global $THIS_MUST_REACT_TO_ENTER_KEY = GUICtrlCreateButton("THIS BUTTON IS THE DEFAULT ONE, PRESS ENTER TO SEE IF IT WORKS...", 20, 200, 421, 41, $BS_DEFPUSHBUTTON) Global $Label = GUICtrlCreateLabel("TEXT CHANGES WHEN BUTTON IS PRESSED", 20, 80, 414, 28) GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif") GUISetState(@SW_HIDE) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GoTo_Form2 GUISetState(@SW_HIDE, $Form1) GUISetState(@SW_SHOW, $Form2) Case $THIS_MUST_REACT_TO_ENTER_KEY GUICtrlSetData($Label, 'IF YOU PRESSED ENTER IT WORKS!') EndSwitch WEndSimple really. 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
TheAutomator Posted February 2, 2014 Author Posted February 2, 2014 (edited) Melba23, I know your solution is good if the form stays on the same place but I want the form(s) to stay at the same place if I drag them around and switch between them. That's why I use that "child" mode. Apparently using child mode does not require GUISwitch($ParentForm) or am I wrong? The help-file uses it in an example, that's why I ask.. TheAutomator Edited February 2, 2014 by TheAutomator Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone
Moderators Melba23 Posted February 2, 2014 Moderators Posted February 2, 2014 TheAutomator, I want the form(s) to stay at the same place if I drag them around and switch between themThat is easy to do:expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Example", 460, 260) Global $GoTo_Form2 = GUICtrlCreateButton("Next Page", 320, 20, 120, 40) GUISetState(@SW_SHOW) Global $Form2 = GUICreate("", 460, 260) Global $THIS_MUST_REACT_TO_ENTER_KEY = GUICtrlCreateButton("THIS BUTTON IS THE DEFAULT ONE, PRESS ENTER TO SEE IF IT WORKS...", 20, 200, 421, 41, $BS_DEFPUSHBUTTON) Global $Label = GUICtrlCreateLabel("TEXT CHANGES WHEN BUTTON IS PRESSED", 20, 80, 414, 28) GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif") GUISetState(@SW_HIDE) GUIRegisterMsg($WM_MOVE, "_WM_MOVE") ; Register the move message While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GoTo_Form2 GUISetState(@SW_HIDE, $Form1) GUISetState(@SW_SHOW, $Form2) Case $THIS_MUST_REACT_TO_ENTER_KEY GUICtrlSetData($Label, 'IF YOU PRESSED ENTER IT WORKS!') EndSwitch WEnd Func _WM_MOVE($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $lParam Switch $hWnd Case $Form1 $aPos = WinGetPos($Form1) ; Wherever $Formi is WinMove($Form2, "", $aPos[0], $aPos[1]) ; Move $Form2 there Case $Form2 $aPos = WinGetPos($Form2) ; And vice versa WinMove($Form1, "", $aPos[0], $aPos[1]) EndSwitch EndFuncAll clear? You only need to use GUISwitch if you are creating additional controls in a GUI when more than one have been created - otherwise AutoIt defaults to the last one referenced. 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
TheAutomator Posted February 2, 2014 Author Posted February 2, 2014 (edited) Melba23, All clear? All clear TheAutomator Edited February 2, 2014 by TheAutomator Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone
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