anixon Posted March 28, 2011 Posted March 28, 2011 In the following code if you choose the dropdown value offered by the combo box the value is processed as proved by the 'Msgbox' in the Case for this input however if you input a value from the keyboard and then the Enter key the value is not processed. How do I get the Case to process on the basis of their being input in this field. I could not find a $msg = GUI_EVENT_....... for the Enter or Tab Keys expandcollapse popup#include <GUIConstantsEx.au3> ;//User GUI #include <WindowsConstants.au3> ;//User GUI ;//My Window _MyWindowGUI() ;//Create the Window Func _MyWindowGUI() ;//Create the Window While 1 ;//Width Height GUICreate("MyWindow", 300, 500, Default, Default) ;//Set Background Color GUISetBkColor(0xE0FFFF) ;//User Input Pulldown Option GUICtrlCreateLabel("Total Term:", 10, 132, 105, 20) $TermYrs = GUICtrlCreateCombo("", 130, 130, 40, 20) ; create first item GUICtrlSetData(-1, "1|2|3|4|5|6|10|15|20|25|30", "") ; add other item snd set a new default GUICtrlCreateLabel("Yrs", 175, 132, 55, 20) ; ;//Other Input and Buttons ; ;Exit the Window $Exit = GUICtrlCreateButton("Close", 10, 470, 60, 20) GUICtrlSetTip(-1, "Close the Window", "Help", 1) ;//Set the State GUISetState() While 1 ;//Read the Input Message $msg = GUIGetMsg() ;//Check for User Input Select ;//Exit the Application Case $msg = $GUI_EVENT_CLOSE Or $msg = $Exit GUIDelete() Exit Case $msg = $TermYrs Msgbox(0,"","Processed") ;//Do Something ExitLoop EndSelect WEnd WEnd EndFunc Help is always appreciated Ant..
Moderators Melba23 Posted March 29, 2011 Moderators Posted March 29, 2011 anixon,Use an Accelerator key to action a dummy control like this (look for the <<<<<< lines): expandcollapse popup#include <GUIConstantsEx.au3> ;//User GUI #include <WindowsConstants.au3> ;//User GUI ;//My Window _MyWindowGUI() ;//Create the Window Func _MyWindowGUI() ;//Create the Window While 1 ;//Width Height GUICreate("MyWindow", 300, 500, Default, Default) ;//Set Background Color GUISetBkColor(0xE0FFFF) ;//User Input Pulldown Option GUICtrlCreateLabel("Total Term:", 10, 132, 105, 20) $TermYrs = GUICtrlCreateCombo("", 130, 130, 40, 20) ; create first item GUICtrlSetData(-1, "1|2|3|4|5|6|10|15|20|25|30", "") ; add other item snd set a new default GUICtrlCreateLabel("Yrs", 175, 132, 55, 20) ; Create dummy control ; <<<<<<<<<<<<<<<<<<<<<<<< $Dummy_TermYrs = GUICtrlCreateDummy() ; ;//Other Input and Buttons ; ;Exit the Window $Exit = GUICtrlCreateButton("Close", 10, 470, 60, 20) GUICtrlSetTip(-1, "Close the Window", "Help", 1) ; Set accelerator for ENTER to action the dummy control ; <<<<<<<<<<<<<<<<<<<<<<<< Dim $AccelKeys[1][2]=[["{ENTER}", $Dummy_TermYrs]] GUISetAccelerators($AccelKeys) ;//Set the State GUISetState() While 1 ;//Read the Input Message $msg = GUIGetMsg() ;//Check for User Input Select ;//Exit the Application Case $msg = $GUI_EVENT_CLOSE Or $msg = $Exit GUIDelete() Exit ; The dummy actions the same code as the combo ; <<<<<<<<<<<<<<<<<<<<<<<< Case $msg = $TermYrs Or $msg = $Dummy_TermYrs MsgBox(0, "", "Processed") ;//Do Something ExitLoop EndSelect WEnd WEnd EndFunc ;==>_MyWindowGUIAll clear? 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
anixon Posted March 29, 2011 Author Posted March 29, 2011 anixon, Use an Accelerator key to action a dummy control like this (look for the <<<<<< lines): expandcollapse popup#include <GUIConstantsEx.au3> ;//User GUI #include <WindowsConstants.au3> ;//User GUI ;//My Window _MyWindowGUI() ;//Create the Window Func _MyWindowGUI() ;//Create the Window While 1 ;//Width Height GUICreate("MyWindow", 300, 500, Default, Default) ;//Set Background Color GUISetBkColor(0xE0FFFF) ;//User Input Pulldown Option GUICtrlCreateLabel("Total Term:", 10, 132, 105, 20) $TermYrs = GUICtrlCreateCombo("", 130, 130, 40, 20) ; create first item GUICtrlSetData(-1, "1|2|3|4|5|6|10|15|20|25|30", "") ; add other item snd set a new default GUICtrlCreateLabel("Yrs", 175, 132, 55, 20) ; Create dummy control ; <<<<<<<<<<<<<<<<<<<<<<<< $Dummy_TermYrs = GUICtrlCreateDummy() ; ;//Other Input and Buttons ; ;Exit the Window $Exit = GUICtrlCreateButton("Close", 10, 470, 60, 20) GUICtrlSetTip(-1, "Close the Window", "Help", 1) ; Set accelerator for ENTER to action the dummy control ; <<<<<<<<<<<<<<<<<<<<<<<< Dim $AccelKeys[1][2]=[["{ENTER}", $Dummy_TermYrs]] GUISetAccelerators($AccelKeys) ;//Set the State GUISetState() While 1 ;//Read the Input Message $msg = GUIGetMsg() ;//Check for User Input Select ;//Exit the Application Case $msg = $GUI_EVENT_CLOSE Or $msg = $Exit GUIDelete() Exit ; The dummy actions the same code as the combo ; <<<<<<<<<<<<<<<<<<<<<<<< Case $msg = $TermYrs Or $msg = $Dummy_TermYrs MsgBox(0, "", "Processed") ;//Do Something ExitLoop EndSelect WEnd WEnd EndFunc ;==>_MyWindowGUI All clear? M23 I never would have got to that. My lifes mission has always been to learn something new every day so M23 once again thank you for your valuable contribution. Ant..
Moderators Melba23 Posted March 29, 2011 Moderators Posted March 29, 2011 anixon, My pleasure! 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
Mat Posted March 29, 2011 Posted March 29, 2011 I think Melba's gone for his "hobbyist coder" workarounds again although a rather clever workaround that I wouldn't have thought of. As always I am in awe of your ability to always have an answer.I hasten to add that I do not have a perfect solution off the top of my head, but I would start with the bible: msdn, or if you want to perform an action when the user hits enter in a combo, then do it properly and use a button with the BS_DEFPUSHBUTTON style. The latter will have a similar effect to setting the dummy anyway, but is the right way to do it. AutoIt Project Listing
Moderators Melba23 Posted March 29, 2011 Moderators Posted March 29, 2011 Mat, I think Melba's gone for his "hobbyist coder" workarounds again [...] do it properly and use a button with the BS_DEFPUSHBUTTON style. The latter will have a similar effect to setting the dummy anyway, but is the right way to do it.So you have a visible control on the GUI rather than an invisible one? Do you consider that "better" or more "right"? I certainly do not. although a rather clever workaround that I wouldn't have thought of. As always I am in awe of your ability to always have an answer.But I will forgive you after that little encomium! 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
Mat Posted March 29, 2011 Posted March 29, 2011 I would say that using combo box notifications is a better way. What if another control has the focus and the user hits enter? It's not the same as the combo box value being changed. AutoIt Project Listing
Moderators Melba23 Posted March 29, 2011 Moderators Posted March 29, 2011 Mat,The same is true for your BS_DEFPUSHBUTTON solution. And if you use EN_CHANGE on the combo edit how do you tell if the user has finished? I think we need something clever here - so that lets me off the hook! But I will have a think about it anyway. M23P.S. Check your PMs. 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
Mat Posted March 29, 2011 Posted March 29, 2011 I can't read pms in school unfortunately, but I can give you a possible solution... Subclass the control and wait for the keyboard messages Somehow I don't think thats the solution that I would want to go for AutoIt Project Listing
Bowmore Posted March 29, 2011 Posted March 29, 2011 (edited) As I had a bit of time to spare I put together this basic example of how to move to the next control by pressing the enter key and at the same time processing the contents of the control. I've added some comments but if you have any questions the post here and I'll do my best to explain how it works. expandcollapse popup#include <GUIConstantsEx.au3> ;//User GUI #include <WindowsConstants.au3> ;//User GUI #include <Constants.au3> ;//User GUI #include <ComboConstants.au3> ;//User GUI #include <guiCombobox.au3> ;//User GUI #include <winapi.au3> ;//User GUI Global $MyWindowGUI = 0 Global $TermYrslbl = 0 Global $TermYrscbo = 0 Global $Termtotallbl = 0 Global $SelectedTermlbl = 0 Global $Otherlbl = 0 Global $Othercbo = 0 Global $Termtotallbl = 0 Global $Selectedotherlbl = 0 GUIRegisterMsg($WM_COMMAND, "_WM_CommandMsgCracker") ;//My Window _MyWindowGUI() ;//Create the Window Func _MyWindowGUI() ;//Create the Window ;//Width Height $MyWindowGUI = GUICreate("MyWindow", 300, 500, Default, Default) ;//Set Background Color GUISetBkColor(0xE0FFFF) ;//User Input Pulldown Option $Termtotallbl = GUICtrlCreateLabel("Total Term:", 10, 132, 105, 20) $TermYrscbo = GUICtrlCreateCombo("", 130, 130, 100, 20) ; create first item GUICtrlSetData($TermYrscbo, "1|2|3|4|5|6|10|15|20|25|30", "10") ; add other item snd set a new default $TermYrslbl = GUICtrlCreateLabel("Yrs", 235, 132, 55, 20) $otherlbl = GUICtrlCreateLabel("Other control:", 10, 157, 105, 20) $Othercbo = GUICtrlCreateCombo("", 130, 155, 100, 20) ; create first item GUICtrlSetData($Othercbo, "one|two|three|four|five|six|ten|fifteen|twenty|twentyfive|thirty", "two") ; add other item snd set a new default $SelectedTermlbl = GUICtrlCreateLabel("Selected Term: ", 10, 180, 250, 20) $SelectedOtherlbl = GUICtrlCreateLabel("Selected Other: ", 10, 205, 250, 20) ; ;//Other Input and Buttons ; ;Exit the Window $Exit = GUICtrlCreateButton("Close", 10, 470, 60, 20) GUICtrlSetTip(-1, "Close the Window", "Help", 1) ;//Set the State GUISetState() While 1 ;//Read the Input Message $msg = GUIGetMsg() ;//Check for User Input Switch $msg ;//Exit the Application Case $GUI_EVENT_CLOSE, $Exit GUIDelete() Exit Case $TermYrscbo GUICtrlSetData($SelectedTermlbl, "You Selected Term : " & guictrlread($TermYrscbo)) Case $Othercbo GUICtrlSetData($SelectedOtherlbl, "You Selected Term : " & guictrlread($Othercbo)) EndSwitch WEnd EndFunc ;==>_MyWindowGUI Func _WM_CommandMsgCracker($hWnd, $iMsg, $iwParam, $ilParam) Local $iNotification = 0 Local $iControlId = 0 Local $sTempContolValue = "" Switch $hWnd Case $MyWindowGUI $iNotification = BitShift($iwParam, 16); Hi Word $iControlId = BitAND($iwParam, 0xFFFF); Low Word switch $iControlId Case $IDOK ;Trap Enter key with $IDOK if no default button set otherwise use controlID of default button Switch ControlGetFocus($MyWindowGUI) Case "Edit1" ;<<< when editing a combobox the edit control has focus not the combobox itself if GUICtrlRead($TermYrscbo) <> "" Then _WinAPI_PostMessage($MyWindowGUI, $WM_NEXTDLGCTL, 0, 0) ; Set focus to next control Case "Edit2" ;<<< when editing a combobox the edit control has focus not the combobox itself if GUICtrlRead($Othercbo) <> "" Then _WinAPI_PostMessage($MyWindowGUI, $WM_NEXTDLGCTL, 0, 0) ; Set focus to next control EndSwitch Case $TermYrscbo Switch $iNotification Case $CBN_EDITCHANGE _GUICtrlComboBox_AutoComplete($TermYrscbo) Case $CBN_KILLFOCUS ;<====== This will catch Tabing out of control or clicking on another GUICtrlSetData($SelectedTermlbl, "You Selected Term : " & guictrlread($TermYrscbo)) EndSwitch Case $Othercbo Switch $iNotification Case $CBN_EDITCHANGE _GUICtrlComboBox_AutoComplete($Othercbo) Case $CBN_KILLFOCUS ;<====== This will catch Tabing out of control or clicking on another GUICtrlSetData($SelectedOtherlbl, "You Selected Other : " & guictrlread($Othercbo)) EndSwitch Case Else Return $GUI_RUNDEFMSG EndSwitch Case Else Return $GUI_RUNDEFMSG EndSwitch EndFunc ;==>_WM_CommandMsgCracker EDIT: Fixed processing selection from dropdown lists Edited March 29, 2011 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
anixon Posted March 29, 2011 Author Posted March 29, 2011 As I had a bit of time to spare I put together this basic example of how to move to the next control by pressing the enter key and at the same time processing the contents of the control. I've added some comments but if you have any questions the post here and I'll do my best to explain how it works. expandcollapse popup#include <GUIConstantsEx.au3> ;//User GUI #include <WindowsConstants.au3> ;//User GUI #include <Constants.au3> ;//User GUI #include <ComboConstants.au3> ;//User GUI #include <guiCombobox.au3> ;//User GUI #include <winapi.au3> ;//User GUI Global $MyWindowGUI = 0 Global $TermYrslbl = 0 Global $TermYrscbo = 0 Global $Termtotallbl = 0 Global $SelectedTermlbl = 0 Global $Otherlbl = 0 Global $Othercbo = 0 Global $Termtotallbl = 0 Global $Selectedotherlbl = 0 GUIRegisterMsg($WM_COMMAND, "_WM_CommandMsgCracker") ;//My Window _MyWindowGUI() ;//Create the Window Func _MyWindowGUI() ;//Create the Window ;//Width Height $MyWindowGUI = GUICreate("MyWindow", 300, 500, Default, Default) ;//Set Background Color GUISetBkColor(0xE0FFFF) ;//User Input Pulldown Option $Termtotallbl = GUICtrlCreateLabel("Total Term:", 10, 132, 105, 20) $TermYrscbo = GUICtrlCreateCombo("", 130, 130, 100, 20) ; create first item GUICtrlSetData($TermYrscbo, "1|2|3|4|5|6|10|15|20|25|30", "10") ; add other item snd set a new default $TermYrslbl = GUICtrlCreateLabel("Yrs", 235, 132, 55, 20) $otherlbl = GUICtrlCreateLabel("Other control:", 10, 157, 105, 20) $Othercbo = GUICtrlCreateCombo("", 130, 155, 100, 20) ; create first item GUICtrlSetData($Othercbo, "one|two|three|four|five|six|ten|fifteen|twenty|twentyfive|thirty", "two") ; add other item snd set a new default $SelectedTermlbl = GUICtrlCreateLabel("Selected Term: ", 10, 180, 250, 20) $SelectedOtherlbl = GUICtrlCreateLabel("Selected Other: ", 10, 205, 250, 20) ; ;//Other Input and Buttons ; ;Exit the Window $Exit = GUICtrlCreateButton("Close", 10, 470, 60, 20) GUICtrlSetTip(-1, "Close the Window", "Help", 1) ;//Set the State GUISetState() While 1 ;//Read the Input Message $msg = GUIGetMsg() ;//Check for User Input Switch $msg ;//Exit the Application Case $GUI_EVENT_CLOSE, $Exit GUIDelete() Exit Case $TermYrscbo ;//Do Something ExitLoop EndSwitch WEnd EndFunc ;==>_MyWindowGUI Func _WM_CommandMsgCracker($hWnd, $iMsg, $iwParam, $ilParam) Local $iNotification = 0 Local $iControlId = 0 Local $sTempContolValue = "" Switch $hWnd Case $MyWindowGUI $iNotification = BitShift($iwParam, 16); Hi Word $iControlId = BitAND($iwParam, 0xFFFF); Low Word switch $iControlId Case $IDOK ;Trap Enter key with $IDOK if no default button set otherwise use controlID of default button Switch ControlGetFocus($MyWindowGUI) Case "Edit1" ;<<< when editing a combobox the edit control has focus not the combobox itself if GUICtrlRead($TermYrscbo) <> "" Then _WinAPI_PostMessage($MyWindowGUI, $WM_NEXTDLGCTL, 0, 0) ; Set focus to next control Case "Edit2" ;<<< when editing a combobox the edit control has focus not the combobox itself if GUICtrlRead($Othercbo) <> "" Then _WinAPI_PostMessage($MyWindowGUI, $WM_NEXTDLGCTL, 0, 0) ; Set focus to next control EndSwitch Case $TermYrscbo Switch $iNotification Case $CBN_EDITCHANGE _GUICtrlComboBox_AutoComplete($TermYrscbo) Case $CBN_KILLFOCUS ;<====== This will catch Tabing out of control or clicking on another GUICtrlSetData($SelectedTermlbl, "You Selected Term : " & guictrlread($TermYrscbo)) EndSwitch Case $Othercbo Switch $iNotification Case $CBN_EDITCHANGE _GUICtrlComboBox_AutoComplete($Othercbo) Case $CBN_KILLFOCUS ;<====== This will catch Tabing out of control or clicking on another GUICtrlSetData($SelectedOtherlbl, "You Selected Other : " & guictrlread($Othercbo)) EndSwitch Case Else Return $GUI_RUNDEFMSG EndSwitch Case Else Return $GUI_RUNDEFMSG EndSwitch EndFunc ;==>_WM_CommandMsgCracker Thanks for that I am never ceased to be amazed about how what appears to be a simple problem has so many solutions. I tried your code and found that if you select a combo box value at 'Total Term' the routine simply exits. However if you input the value and then 'Enter' the input is correctly processed. Ant..
Bowmore Posted March 29, 2011 Posted March 29, 2011 @anixon I was concentrating on the difficult part and forgot the basics. See the code in my original post which I have now corrected by adding a couple of lines to the _MyWindowGui() function to handle selecting from the dropdown lists. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
anixon Posted March 29, 2011 Author Posted March 29, 2011 @anixonI was concentrating on the difficult part and forgot the basics. See the code in my original post which I have now corrected by adding a couple of lines to the _MyWindowGui() function to handle selecting from the dropdown lists.I copied the above code up to my system unfortunately I did not check hte changes but can report that it is still exiting the routine when using the combo box data as the input. Ant..
Bowmore Posted March 29, 2011 Posted March 29, 2011 You need to use the modified code in post #10 I've checked it and It only closes via the close button or the close window icon. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
anixon Posted March 29, 2011 Author Posted March 29, 2011 You need to use the modified code in post #10 I've checked it and It only closes via the close button or the close window icon.Thanks for that your help is very much appreciated. Ant..
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