Jump to content
Sign in to follow this  
BruceCopperField

ClassNameNN Returned by ControlGetFocus()

Recommended Posts

BruceCopperField

A newbie question. ControlGetFocus() returns a ClassNameNN. How do we use it to uniquely identify which control is having the focus? It seems that if i have say 4 input control, their ClassNameNN are all 'Edit0'?

Share this post


Link to post
Share on other sites
k3v

I'd like to see "the right way" to do this as well, but in the mean time here's an idea...

I've gotten around this by getting the ClassNameNN at the time I build the GUI...

create the controls, give each one focus & get its ID into a variable, continue building the GUI.

#include <guiconstants.au3>
opt("GUIOnEventMode",1)
guicreate("TEST")
$input1 = GUICtrlCreateInput("",20,20,75,20)
$input2 = GUICtrlCreateInput("",20,50,75,20)
$input3 = GUICtrlCreateInput("",20,80,75,20)
$input4 = GUICtrlCreateInput("",20,110,75,20)
$button1 = GUICtrlCreateButton("focus input1",100,20,80,20)
$button2 = GUICtrlCreateButton("focus input2",100,50,80,20)
$button3 = GUICtrlCreateButton("focus input3",100,80,80,20)
$button4 = GUICtrlCreateButton("focus input4",100,110,80,20)

ControlFocus("TEST","",$input1);give focus to $input1
$id1 = ControlGetFocus("TEST");get $input1's ClassNameNN into a variable
ControlFocus("TEST","",$input2);rinse & repeat
$id2 = ControlGetFocus("TEST")
ControlFocus("TEST","",$input3)
$id3 = ControlGetFocus("TEST")
ControlFocus("TEST","",$input4)
$id4 = ControlGetFocus("TEST")

GUICtrlSetOnEvent($button1,"input1")
GUICtrlSetOnEvent($button2,"input2")
GUICtrlSetOnEvent($button3,"input3")
GUICtrlSetOnEvent($button4,"input4")
ControlFocus("TEST","",$input1);
guisetstate()
GUISetOnEvent($GUI_EVENT_CLOSE,"close")

while 1
    sleep(1000)
WEnd
func input1()
    ControlFocus("TEST","",$input1)
EndFunc
func input2()
    ControlFocus("TEST","",$input2)
EndFunc
func input3()
    ControlFocus("TEST","",$input3)
EndFunc
func input4()
    ControlFocus("TEST","",$input4)
EndFunc
func close()
    Exit
EndFunc

if i have say 4 input control, their ClassNameNN are all 'Edit0'

(I've not seen this happen before) Edited by k3v

Share this post


Link to post
Share on other sites
PsaltyDS

A newbie question. ControlGetFocus() returns a ClassNameNN. How do we use it to uniquely identify which control is having the focus? It seems that if i have say 4 input control, their ClassNameNN are all 'Edit0'?

No, if you have four INSTANCES of CLASS:Edit controls, their ClassNameNN's returned will be Edit1, Edit2, Edit3, or Edit4.

There is a dll cal you can make to get the ControlID number if you must:

$sClassNameNN = ControlGetFocus("", "")
$hCtrlFocus = ControlGetHandle("", "", $sClassNameNN)
$ctrlFocus = ControlGetID($hCtrlFocus)
MsgBox(64, "Results", "The control with current focus was:" & @CRLF & _
        @TAB & "ClassNameNN = " & $sClassNameNN & @CRLF & _
        @TAB & "HWND = " & $hCtrlFocus & @CRLF & _
        @TAB & "ID = " & $ctrlFocus)

Func ControlGetID($hWnd)
    $avRET = DllCall("User32.dll", "int", "GetDlgCtrlID", "hwnd", $hWnd)
    If @error or $avRET[0] = 0 then Return SetError(1, 0, 0)
    Return $avRET[0]
EndFunc

But if you already have the ClassNameNN, and you can get the handle from that with ControlGetHandle(), you usually don't need the ControlID.

:)


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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.