AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Get ClassNN from associated VarName of GUI control

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Sun Aug 27, 2006 4:46 pm    Post subject: Get ClassNN from associated VarName of GUI control Reply with quote

In complex GUI's it is hard to keep track of the ClassNN identifiers of controls: you have to count how many edit controls were created before, to know that the newly created one is, e.g. Edit3. This ClassNN is needed if you want to send keystrokes, like ^{End} to the corresponding control, to move the insertion point to the end. It was much easier if we could use the name of the associated variable of the GUI control, as Toralf suggested. Here is a simple trick to do it.

Only GuiControl/Get can use variable names to identify controls, therefore we need a way around: set the keyboard focus with "GuiControl Focus, VarName" to the desired control, and get the ClassNN value with "ControlGetFocus ClassNN". You only need to do this once after the GUI was created, the retrieved ClassNN values can be used later to identify the target control to receive keystrokes:
Code:
Gui Add, Edit
Gui Add, Edit, vLog r2 w200,Line1`nLine2`nLine3`nLine4
Gui Add, Edit, vInf w200
Gui Show
WinGet Gui_ID, ID, A

GuiControl Focus, Log
ControlGetFocus ClassLog, ahk_id %Gui_ID%

GuiControl Focus, Inf
ControlGetFocus ClassInf, ahk_id %Gui_ID%

ControlSend %ClassLog%, ^{End}, ahk_id %Gui_ID%
ControlSend %ClassInf%, %ClassLog% | %ClassInf%, ahk_id %Gui_ID%
Back to top
View user's profile Send private message
robiandi



Joined: 08 Aug 2006
Posts: 49

PostPosted: Sun Aug 27, 2006 5:06 pm    Post subject: Reply with quote

That is very nice!!
Back to top
View user's profile Send private message
Hardeep



Joined: 02 Jul 2006
Posts: 87

PostPosted: Sun Aug 27, 2006 5:15 pm    Post subject: Reply with quote

I prefer using GuiControlGet instead Smile
Here's your modified example:
Code:
Gui Add, Edit
Gui Add, Edit, vLog r2 w200
Gui Add, Edit, vInf w200
Gui Show
WinGet Gui_ID, ID, A

GuiControl Focus, Log
GuiControlGet,ClassLog,Focus

GuiControl Focus, Inf
GuiControlGet,ClassInf,Focus

ControlSend, %ClassLog%,I am %ClassLog%, ahk_id %Gui_ID%
ControlSend, %ClassInf%, I am %ClassInf%, ahk_id %Gui_ID%
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Sun Aug 27, 2006 5:29 pm    Post subject: Reply with quote

Hardeep wrote:
I prefer using GuiControlGet instead
Why? If you want less characters, you can use "ControlGetFocus ClassLog, A". Was GuiControlGet faster or more reliable?
Back to top
View user's profile Send private message
Hardeep



Joined: 02 Jul 2006
Posts: 87

PostPosted: Sun Aug 27, 2006 6:03 pm    Post subject: Reply with quote

Hi Laszlo,

Both the commands are equally fast & reliable. If you really are concerned about a few characters, GuiControlGet has the advantage when your LastFound window is something else..

I modified your example just to show that another command does the same job. I’m sorry... didn’t mean to offend you.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Sun Aug 27, 2006 6:25 pm    Post subject: Reply with quote

Hardeep wrote:
didn’t mean to offend you
You did not. I was just curious if one of the 2 commands is better.
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3910
Location: Bremen, Germany

PostPosted: Sun Aug 27, 2006 6:48 pm    Post subject: Reply with quote

@Chris:
Would it be possible to get a new sub-command "class" for GuiControlGet
"GuiControlGet, OutputVar , Class, ControlID"
Where for the subcommand Class the OutputVar is set to the class of the Control.

And maybe a HWND sub-command as well?

Thanks for listening.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10716

PostPosted: Sun Aug 27, 2006 9:05 pm    Post subject: Reply with quote

There is a plan to improve SendMessage/PostMessage and some of the control-targeting commands so that it's easier to work with GUI windows and their controls (perhaps by allowing control variable names in place of ClassNN).

As for HWND, here's a way to get control HWNDs that might be easier:
Code:
Gui +LastFound
GuiHwnd := WinExist()
FirstControlHwnd := DllCall("GetDlgItem", uint, GuiHwnd, int, 3)
In the above, the red 3 signifies the first control in the window. To get the second control, use 4; and for the third, use 5; and so on. The numbers of the controls are the order in which they were originally added.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group