IchBistTod Posted November 29, 2010 Share Posted November 29, 2010 How do I find what the active control is? aka the field the user currently has selected. [center][/center][center]=][u][/u][/center][center][/center] Link to comment Share on other sites More sharing options...
Tvern Posted November 29, 2010 Share Posted November 29, 2010 ControlGetFocus() works. I don't think there is a build in function that returns the CtrlID, but you could loop through all your controls for one with a matching CLASSNN, or loop through your controls with GUICtrlGetState() Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 29, 2010 Share Posted November 29, 2010 Use _WinAPI_GetDlgCtrlID() to retrieve a ControlID: #include <WinAPI.au3> Run("notepad.exe") Sleep(2000) $idFocus = _FocusCtrlID("Untitled - Notepad", "") MsgBox(64, "Result", "Focus ID = " & $idFocus & "; @error = " & @error) WinClose("Untitled - Notepad", "") Func _FocusCtrlID($hWnd, $sTxt = "") Local $hFocus = ControlGetHandle($hWnd, $sTxt, ControlGetFocus($hWnd, $sTxt)) If IsHWnd($hFocus) Then Return _WinAPI_GetDlgCtrlID($hFocus) Else Return SetError(1, 0, 0) EndIf EndFunc ;==>_FocusCtrlID Xandy 1 Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
IchBistTod Posted November 29, 2010 Author Share Posted November 29, 2010 The reason I ask this is because I have a series of input boxes next to one another and when one has been filled out I want to switch to the next. I know its gonna take some coding magic to make users be able to go back in the sequence and start from the point they selected(eg: they typed a wrong letter). Its a product key input GUI. I already have it verifying the product key algorithm and telling the user if input is invalid before allowing them to continue. [center][/center][center]=][u][/u][/center][center][/center] Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 29, 2010 Share Posted November 29, 2010 (edited) Registering WM_NOTIFY WM_COMMAND and watching the appropriate EN_CHANGE or other messages would be more direct if it's your own GUI.Edit: Oops, there I go trusting the swiss-cheese brain again. Edited November 29, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 29, 2010 Moderators Share Posted November 29, 2010 IchBistTod, Registering WM_NOTIFY and watching the appropriate EN_CHANGEI have use WM_COMMAND and $EN_UPDATE with success: #include <GUIConstantsEx.au3> Global $input_limit = 2 $gui = GUICreate("InputBox autofocus demo", 200, 100) $in1 = GUICtrlCreateInput("", 20, 20, 30, 20) GUICtrlSetLimit(-1, $input_limit) $in2 = GUICtrlCreateInput("", 80, 20, 30, 20) GUICtrlSetLimit(-1, $input_limit) $in3 = GUICtrlCreateInput("", 140, 20, 30, 20) GUICtrlSetLimit(-1, $input_limit) $btn = GUICtrlCreateButton("OK", 75, 60, 40, 25) GUIRegisterMsg(0x0111, "On_WM_COMMAND") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btn $str = GUICtrlRead($in1) & "-" & GUICtrlRead($in2) & "-" & GUICtrlRead($in3) MsgBox(0, "You have entered", $str) EndSwitch WEnd Func On_WM_COMMAND($hWnd, $Msg, $wParam, $lParam) $nNotifyCode = BitShift($wParam, 16) $nID = BitAnd($wParam, 0x0000FFFF) Switch $nNotifyCode Case 0x400 ;$EN_UPDATE If StringLen(GUICtrlRead($nID)) = $input_limit Then GUICtrlSetState($nID+1, $GUI_FOCUS) EndSwitch EndFunc 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...
IchBistTod Posted November 29, 2010 Author Share Posted November 29, 2010 IchBistTod, I have use WM_COMMAND and $EN_UPDATE with success: #include <GUIConstantsEx.au3> Global $input_limit = 2 $gui = GUICreate("InputBox autofocus demo", 200, 100) $in1 = GUICtrlCreateInput("", 20, 20, 30, 20) GUICtrlSetLimit(-1, $input_limit) $in2 = GUICtrlCreateInput("", 80, 20, 30, 20) GUICtrlSetLimit(-1, $input_limit) $in3 = GUICtrlCreateInput("", 140, 20, 30, 20) GUICtrlSetLimit(-1, $input_limit) $btn = GUICtrlCreateButton("OK", 75, 60, 40, 25) GUIRegisterMsg(0x0111, "On_WM_COMMAND") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btn $str = GUICtrlRead($in1) & "-" & GUICtrlRead($in2) & "-" & GUICtrlRead($in3) MsgBox(0, "You have entered", $str) EndSwitch WEnd Func On_WM_COMMAND($hWnd, $Msg, $wParam, $lParam) $nNotifyCode = BitShift($wParam, 16) $nID = BitAnd($wParam, 0x0000FFFF) Switch $nNotifyCode Case 0x400 ;$EN_UPDATE If StringLen(GUICtrlRead($nID)) = $input_limit Then GUICtrlSetState($nID+1, $GUI_FOCUS) EndSwitch EndFunc M23 wow that is amazing! I had no idea that the process could be simplified to such a small amount of code. I suppose i should really start to learn these GUIRegisterMsg(0x0111, "On_WM_COMMAND") and other "registermessage"'s any advice on where to look to learn more about them? [center][/center][center]=][u][/u][/center][center][/center] Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 30, 2010 Share Posted November 30, 2010 I suppose i should really start to learn these GUIRegisterMsg(0x0111, "On_WM_COMMAND") and other "registermessage"'s any advice on where to look to learn more about them?Go through the help file examples under most of the _GuiCtrl* UDF functions. Most of the handlers for non-AutoIt controls, for example _GuiCtrlButton_Create() instead of GuiCtrlCreateButton(), use this kind of message handling. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
JAFN Posted April 4, 2011 Share Posted April 4, 2011 IchBistTod, I have use WM_COMMAND and $EN_UPDATE with success: #include <GUIConstantsEx.au3> Global $input_limit = 2 $gui = GUICreate("InputBox autofocus demo", 200, 100) $in1 = GUICtrlCreateInput("", 20, 20, 30, 20) GUICtrlSetLimit(-1, $input_limit) $in2 = GUICtrlCreateInput("", 80, 20, 30, 20) GUICtrlSetLimit(-1, $input_limit) $in3 = GUICtrlCreateInput("", 140, 20, 30, 20) GUICtrlSetLimit(-1, $input_limit) $btn = GUICtrlCreateButton("OK", 75, 60, 40, 25) GUIRegisterMsg(0x0111, "On_WM_COMMAND") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btn $str = GUICtrlRead($in1) & "-" & GUICtrlRead($in2) & "-" & GUICtrlRead($in3) MsgBox(0, "You have entered", $str) EndSwitch WEnd Func On_WM_COMMAND($hWnd, $Msg, $wParam, $lParam) $nNotifyCode = BitShift($wParam, 16) $nID = BitAnd($wParam, 0x0000FFFF) Switch $nNotifyCode Case 0x400 ;$EN_UPDATE If StringLen(GUICtrlRead($nID)) = $input_limit Then GUICtrlSetState($nID+1, $GUI_FOCUS) EndSwitch EndFunc M23 I've had some results modifying this to my needs but I don't understand why it works. Specifically how the parameters got passed to the function. [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted April 4, 2011 Share Posted April 4, 2011 I've had some results modifying this to my needs but I don't understand why it works.Specifically how the parameters got passed to the function.Here's some reading for you:About Messages and Message Queues .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 4, 2011 Moderators Share Posted April 4, 2011 JAFN,I know you have read the GUIRegisterMsg tutorial in the Wiki - you said then you did not understand it. ;(Now you have seen a message handler in action, please read the tutorial again and ask about anything in it you do not understand. I wrote it to explain about Windows messages and message handlers at a pretty basic level, so if it does not explain well enough then I need to change it. 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