Myicq Posted April 24, 2013 Share Posted April 24, 2013 I am developing a small application to change various parameters in a program.The parameters are numeric only and can be integer.I would like the fine-tuning of these parameters to be as simple as possible. Of course I can just let the operator type in replacement value, but this gets tedious with 4-5 digit parameter values.I have two different ideas / paths:when the field has focus, use some keys to change to next/previous value, like a spinner. Preferably up/down keys. Adobe designsoftware works like this, if you have tried them. Probably different controls though.have some general up/down buttons (or the Windows up/down control ?) that change value that just had / has focus.Only I am not really sure how to deal with the focus / focus-lost issue.My program is not using onevent mode.Thanks for any help I am just a hobby programmer, and nothing great to publish right now. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 24, 2013 Moderators Share Posted April 24, 2013 Myicq, Perhaps something like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $cInput = GUICtrlCreateInput("999", 10, 10, 200, 20) $hInput = GUICtrlGetHandle($cInput) $cButton = GUICtrlCreateButton("Focus Taker", 10, 100, 100, 30) $cUp = GUICtrlCreateDummy() $cDown = GUICtrlCreateDummy() GUISetState() ; Set GUIAccelerators for the dummy controlIDs Global $aAccelKeys[2][2] = [["{UP}", $cUp],["{DOWN}", $cDown]] GUISetAccelerators($aAccelKeys) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cUp If _WinAPI_GetFocus() = $hInput Then $iValue = GUICtrlRead($cInput) + 1 If $iValue = 1001 Then $iValue = 0 GUICtrlSetData($cInput, $iValue) EndIf Case $cDown If _WinAPI_GetFocus() = $hInput Then $iValue = GUICtrlRead($cInput) - 1 If $iValue = -1 Then $iValue = 1000 GUICtrlSetData($cInput, $iValue) EndIf EndSwitch WEnd I hope it is of use. 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...
Myicq Posted April 24, 2013 Author Share Posted April 24, 2013 M23, it did help me a long way, thanks. How can I make this code more generalized for use with 4-8 input boxes ? I have seen before that DummyControls have been used to "border off" other controls, like this $before = guictrlcreatedummy() $i1 = guictrlcreateinput(...) $i2 = guictrlcreateinput(...) ... $after = guictrlcreatedummy() then check the id of the control if it's between $before and $after. Just forgot how I am just a hobby programmer, and nothing great to publish right now. Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted April 24, 2013 Moderators Solution Share Posted April 24, 2013 (edited) Myicq, I would use an array like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPI.au3> ; Number of inputs Global $iCount = 3 ; Array to hold input ControlID and handle Global $aInput[$iCount + 1][2] = [[$iCount]] $hGUI = GUICreate("Test", 500, 500) For $i = 1 To $iCount ; Store the ControlID and handle $aInput[$i][0] = GUICtrlCreateInput("999", 10, 20 * $i, 200, 20) $aInput[$i][1] = GUICtrlGetHandle($aInput[$i][0]) Next $cButton = GUICtrlCreateButton("Focus Taker", 380, 10, 100, 30) $cUp = GUICtrlCreateDummy() $cDown = GUICtrlCreateDummy() GUISetState() ; Set GUIAccelerators for the dummy controlIDs Global $aAccelKeys[2][2] = [["{UP}", $cUp],["{DOWN}", $cDown]] GUISetAccelerators($aAccelKeys) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cUp ; Get handle of focused control $hFocus = _WinAPI_GetFocus() ; See if it is an input For $i = 1 To $iCount If $aInput[$i][1] = $hFocus Then ; Chnage the input $iValue = GUICtrlRead($aInput[$i][0]) + 1 If $iValue = 1001 Then $iValue = 0 GUICtrlSetData($aInput[$i][0], $iValue) ; No point in looping any more ExitLoop EndIf Next Case $cDown $hFocus = _WinAPI_GetFocus() For $i = 1 To $iCount If $aInput[$i][1] = $hFocus Then $iValue = GUICtrlRead($aInput[$i][0]) - 1 If $iValue = -1 Then $iValue = 1000 GUICtrlSetData($aInput[$i][0], $iValue) ExitLoop EndIf Next EndSwitch WEnd All clear? M23 Edited April 24, 2013 by Melba23 Copy paste error fixed Myicq 1 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...
Myicq Posted April 24, 2013 Author Share Posted April 24, 2013 M23, your thankful input inspired me to what I think will be the solution. Sort of along the way you suggest, but not quite. My solution was: Case $cUp for $i = $cInput1 to $cInput4 if _WinAPI_GetFocus() = GuiCtrlGetHandle($i) Then $iValue = GuiCtrlRead($i) +1 GuiCtrlSetData($i, $iValue) EndIf next That way I do not have to create variables for handle. Just need to make sure inputs are following each other in design. Similar for $cDown Thanks for your suggestions again, especially about the Accelerators ! That will come in handy many places. - myicq. I am just a hobby programmer, and nothing great to publish right now. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 24, 2013 Moderators Share Posted April 24, 2013 Myicq,I would suggest adding an ExitLoop before the EndIf as I did - why continue the loop if you have already identifed the focused input? 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...
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