Sign in to follow this  
Followers 0
IchBistTod

get active control

11 posts in this topic

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]

Share this post


Link to post
Share on other sites



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()

Share this post


Link to post
Share on other sites

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

:graduated:

1 person likes this

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

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

#5 ·  Posted (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.

:graduated:

Edited 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

Share this post


Link to post
Share on other sites

IchBistTod,

Registering WM_NOTIFY and watching the appropriate EN_CHANGE

I have use WM_COMMAND and $EN_UPDATE with success: :graduated:

#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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

IchBistTod,

I have use WM_COMMAND and $EN_UPDATE with success: :graduated:

#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]

Share this post


Link to post
Share on other sites

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.

:graduated:


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

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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

:)

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0