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 

Control names

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
spiderman



Joined: 08 Sep 2007
Posts: 11

PostPosted: Tue Nov 06, 2007 8:22 am    Post subject: Control names Reply with quote

Hi All,

Is there a way to figure out a controlname instead of it's classname.
I mean, when i build a form in VB.NET I give controls a name like txtFirstName and txtLastName (where txt stands for textbox).
After I compile the program and use AHK to read the controls, I must use Edit1 and Edit2.

Is there a way to get it's original names like it was before it was compiled?


P.S. I asked this question a will ago but didn't get a satisfying answer (http://www.autohotkey.com/forum/viewtopic.php?t=25065&highlight=)


Thanks in advance
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Tue Nov 06, 2007 9:28 am    Post subject: Re: Control names Reply with quote

spiderman wrote:
I mean, when i build a form in VB.NET I give controls a name like txtFirstName and txtLastName (where txt stands for textbox).
After I compile the program and use AHK to read the controls, I must use Edit1 and Edit2.

Is there a way to get it's original names like it was before it was compiled?
Let me get this straight... you want to - from AHK - get the names that you gave controls in VB.NET? .NET applications give controls weird ClassNNs like WindowsForms10.EDIT.app.0.378734a3. Since you mentioned "Edit1 and Edit2", it seems you aren't trying to interact with VB.NET.

If you are, the answer is no, it is not any more possible than it is possible to retrieve the values of variables of some external .NET application (which is exactly what you'd need to do.)

If not, do you mean a compiled script?
Back to top
View user's profile Send private message
spiderman



Joined: 08 Sep 2007
Posts: 11

PostPosted: Tue Nov 06, 2007 10:14 am    Post subject: Reply with quote

Hi lexikos,

Thank for youre answer.

I'm indeed not tring to get the controlnames from a VB.NET application.
I'm use AHK to handle controls in a application with the name Clarify.
The main issue I have is that controls in Clarify are painted when the program needs them.

So some controls are painted (for example) after pressing a button, or clicking on a tabpage.
This means that a control with the name Edit2 (Lastname) after clicking on a button can become Edit3, because Clarify painted an extra textbox.

For example.
BEFORE clicking some buttons
[Edit11]
X-pos=221
Y-pos=787
Width=89
Height=19

[Edit12]
X-pos=297
Y-pos=944
Width=107
Height=19
Text=Please Specify

[Edit13]
X-pos=404
Y-pos=944
Width=137
Height=19
Text=Specify a Reason

[Edit14]
X-pos=541
Y-pos=944
Width=113
Height=19
Text=Specify a Result[/list]

AFTER clicking some buttons
[Edit19]
X-pos=221
Y-pos=787
Width=89
Height=19

[Edit20]
X-pos=297
Y-pos=944
Width=107
Height=19
Text=Please Specify

[Edit21]
X-pos=404
Y-pos=944
Width=137
Height=19
Text=Specify a Reason

[Edit22]
X-pos=541
Y-pos=944
Width=113
Height=19
Text=Specify a Result

As you can see, the controls are at the same location, with in some cases the same text (if any text), but the classnames are diffrent Evil or Very Mad

So I need a way alway identify the right control.
Hope this makes the problem more clear.
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Tue Nov 06, 2007 10:56 am    Post subject: Reply with quote

Perhaps you could identify them by relative position.
Code:
WinGet, OutputVar, ControlList, WinTitle
Use this to get a list of controls, then use a parsing loop (`n is the delimiter) to check the location of each control relative to the last. For instance [Edit11/19] will always (I suppose) be the highest. You might also be able to identify them by the order they appear in the list:
Quote:
Controls are sorted according to their Z-order, which is usually the same order as TAB key navigation if the window supports tabbing.
You may need to filter out hidden controls. (If so, use ControlGet,..,Visible,..)
Back to top
View user's profile Send private message
spiderman



Joined: 08 Sep 2007
Posts: 11

PostPosted: Tue Nov 06, 2007 11:34 am    Post subject: Reply with quote

Hi lexikos,

I'm already started with the WinGet, OutputVar ControlList, WinTitle and try to find some way to identify all the controls. The main issue in this is that we need to use AHK to be used with diffrent users (with diffrent window settings Crying or Very sad ).

I'm now trying to create some kind of INI file with all the controls. The problem is that there are a lot of screens, with a lot of controls. So this is a very very lot of work, that needs to be done for each user Evil or Very Mad.

So if there is some other way to get always the right control nomatter where it is located or what classname# it has, it would be more then welcome.
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Tue Nov 06, 2007 12:36 pm    Post subject: Reply with quote

spiderman wrote:
The main issue in this is that we need to use AHK to be used with diffrent users (with diffrent window settings Crying or Very sad ).
Yes, that's why I suggested relative position. Wink i.e. "second control from top" vs "control at xyz location."
Quote:
So if there is some other way to get always the right control nomatter where it is located or what classname# it has, it would be more then welcome.
Since they're Edit controls, I assume identifying them by text content wouldn't be feasible. What about identifying by z-order (usually tab-order)? Seams feasible to me, unless the controls change z-order when focused (they wouldn't normally.)

If you have a look at the control list as a whole, it should be clear whether identifying by z-order is feasible. (You may need to filter out hidden controls, though.)
Back to top
View user's profile Send private message
spiderman



Joined: 08 Sep 2007
Posts: 11

PostPosted: Tue Nov 06, 2007 2:03 pm    Post subject: Reply with quote

Hi lexikos,


I will create a function that can get the classname# from a control that's located 'x' controls next to another control (for example a label).

The functions will be something like

Code:
GetNextControlTo(FixedControl, LookForClassname, Index)

This function will return the classname from the control that is located 'Index' controls next to FixedControl.


Thanks for you input.
Back to top
View user's profile Send private message
AHKnow



Joined: 03 Jul 2004
Posts: 118

PostPosted: Tue Dec 04, 2007 7:13 am    Post subject: Reply with quote

Interesting....
Back to top
View user's profile Send private message
interiot



Joined: 06 Nov 2005
Posts: 64

PostPosted: Wed Apr 23, 2008 9:38 pm    Post subject: Reply with quote

Lexikos wrote:
What about identifying by z-order (usually tab-order)? Seams feasible to me, unless the controls change z-order when focused (they wouldn't normally.)

Yup, I've done this sometimes. It's useful as a last-resort (z-order may not stay the same across application versions).

Winspector is useful for seeing the hierarchy of windows that you have to navigate.

Code:
; navigate windows based on their z-order / tab-order
GetLastSibling(hwnd)
{
   return,DllCall("GetWindow","uint",hwnd,"uint",GW_HWNDLAST:=1)
}
GetFirstSibling(hwnd)
{
   return,DllCall("GetWindow","uint",hwnd,"uint",GW_HWNDFIRST:=0)
}
GetPrevSibling(hwnd)
{
   return,DllCall("GetWindow","uint",hwnd,"uint",GW_HWNDPREV:=3)
}
GetNextSibling(hwnd)
{
   return,DllCall("GetWindow","uint",hwnd,"uint",GW_HWNDNEXT:=2)
}
GetParentWindow(hwnd)
{
   return,DllCall("GetWindow","uint",hwnd,"uint",GW_OWNER:=4)
}
GetFirstChild(hwnd)
{
   return,DllCall("GetWindow","uint",hwnd,"uint",GW_CHILD:=5)
}

; p_hw_parent=0:  search starting from the desktop window
; p_hw_child=0:  start with the first child of p_hw_parent
; p_hw_child!=0:  start with the next sibling of p_hw_child
FindWindowEx( p_hw_parent, p_hw_child, p_class, p_title=0 )
{
   if ( p_title = 0 )
      type_title = uint
   else
      type_title = str

   return, DllCall( "FindWindowEx"
                  , "uint", p_hw_parent
                  , "uint", p_hw_child
                  , "str", p_class
                  , type_title, p_title )
}
Back to top
View user's profile Send private message
Oberon



Joined: 18 Feb 2008
Posts: 458

PostPosted: Wed Apr 23, 2008 10:35 pm    Post subject: Re: Control names Reply with quote

spiderman wrote:
when i build a form in VB.NET
.NET controls are not designed to respond to standard Windows messages so DllCall stuff won't work. You can however expose custom methods (don't need to use COM) for manual text selection via AutoHotkey.
Back to top
View user's profile Send private message
SomeGuy



Joined: 21 Apr 2008
Posts: 96
Location: somewhere

PostPosted: Thu Apr 24, 2008 12:33 am    Post subject: Re: Control names Reply with quote

Oberon wrote:
spiderman wrote:
when i build a form in VB.NET
...You can however expose custom methods (don't need to use COM) for manual text selection via AutoHotkey.

Example?????
Back to top
View user's profile Send private message
Oberon



Joined: 18 Feb 2008
Posts: 458

PostPosted: Thu Apr 24, 2008 1:01 am    Post subject: Reply with quote

There are examples posted on this forum and technical details on msdn if you care to search.
Back to top
View user's profile Send private message
SomeGuy



Joined: 21 Apr 2008
Posts: 96
Location: somewhere

PostPosted: Thu Apr 24, 2008 1:03 am    Post subject: Reply with quote

all i see is something about calling .net dll's
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help 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