Jump to content

ControlGetFocus ---- ID


Recommended Posts

ControlGetHandle() using the return value of ControlGetFocus() will give you the handle.

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

Is it possible to get the ID or maybe the handle, preferably the ID, of a control that has focus?

In many ways (not all) a control is just a small window on top of a larger one. Many of the _WinAPI_* functions work on a control as well as window. One of these can be used to retrieve the ControlID after you determine the handle:
#Include <WinAPI.au3>
#include <Constants.au3>

$hGui = GUICreate("Test", 400, 240)
$ctrlLabel = GUICtrlCreateLabel("", 10, 10, 380, 180)
$ctrlButton = GUICtrlCreateButton("Quit", 150, 200, 100, 30)
GUISetState()

Sleep(500)

$sFocus = ControlGetFocus($hGui)
$hButton = ControlGetHandle($hGui, "", $ctrlButton)
$iButton = _WinAPI_GetWindowLong($hButton, $GWL_ID)

ControlSetText($hGui, "", $ctrlLabel, "ControlID = " & $ctrlButton & @CRLF & _
        "Focused ID = " & $sFocus & @CRLF & _
        "Handle = " & $hButton & @CRLF & _
        "Retreived ID = " & $iButton)
        
Do
    Sleep(10)
Until GUIGetMsg() = $iButton

;)

Edit: Improved demo to show a usage for the retrieved ControlID.

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

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...