AutoHotkey Community

It is currently May 27th, 2012, 9:29 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: August 27th, 2006, 5:46 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2006, 6:06 pm 
Offline

Joined: August 8th, 2006, 3:55 pm
Posts: 49
That is very nice!!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2006, 6:15 pm 
Offline

Joined: July 2nd, 2006, 7:59 pm
Posts: 87
I prefer using GuiControlGet instead :)
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%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2006, 6:29 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2006, 7:03 pm 
Offline

Joined: July 2nd, 2006, 7:59 pm
Posts: 87
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2006, 7:25 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Hardeep wrote:
didn’t mean to offend you
You did not. I was just curious if one of the 2 commands is better.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2006, 7:48 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
@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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2006, 10:05 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group