Jump to content

get active control


Recommended Posts

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:

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

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

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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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]

Link to comment
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
Link to comment
Share on other sites

  • 4 months later...

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

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

:)

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...