Jump to content

Get handle of active input control


Go to solution Solved by FireFox,

Recommended Posts

Posted

Hi everyone,

Simple question but cant find an answer anywhere:

On a user created GUI, how can I determine the handle of the input control that's currently has focus?

TIA,

Sandy

----[ SandyD ]---
  • Solution
Posted

Hi,
Here you go:

#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
 
Global $_iInputFocused = -1
 
GUICreate("MyGUI")
 
Local $iInput1 = 0
For $i = 1 To 3
    $iInput1 = GUICtrlCreateInput("", 10, 10 + 25 * $i)
    GUICtrlSetData($iInput1, "My id: " & $iInput1)
Next
 
Local $iBtn1 = GUICtrlCreateButton("Which has focus?", 10, 150)
 
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetState(@SW_SHOW)
 
While 1
    Sleep(10)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $iBtn1
            MsgBox($MB_SYSTEMMODAL, "", "input id focused: " & $_iInputFocused)
    EndSwitch
WEnd
 
GUIDelete()
 
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iCode = BitShift($iwParam, 16)
    Local $iIDFrom = BitAND($iwParam, 0x0000FFFF)
 
    Switch $iCode
        Case $EN_SETFOCUS
            $_iInputFocused = $iIDFrom
    EndSwitch
 
    Return $GUI_RUNDEFMSG
EndFunc
Br, FireFox.
Posted

The best answer is to redirect people to what solved the topic, if you mark your post as the answer actually it's not.

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
×
×
  • Create New...