views:

127

answers:

3

Is there any way to get a control's name through win32api? (c++)

I'm talking about the property that in C# is 'Name', like 'frmMain', or 'btnNext'. Is there any way to retrieve this data through the win32API?

I've tried GetWindowInfo() and stuff but I think I'm not heading in the right direction..

thanks

edit: I'm iterating with EnumChildWindows() and I got the correct HWND.. not sure if I can use it to print it's name.. (im a c++/win32 absolute noob)

Added 7/10/09

By the way I found this really good tool to operate win32 apps. http://www.autoitscript.com/autoit3/

Check it out looks good and looks like it's freeware? :)

+3  A: 

The name of a control is usually a private variable of the control and is not exposed to win32. You could try GetWindowText to get the title of some controls or GetWindowLong to get some properties, but i dont think you can get the name of most controls.

Andrew Keith
I've actually just headed against GetWindowText(). Bummer. The thing is that the handle is going to change when re-running, while the name won't. I wonder what kind of referential information I could hardcode for my code to be reused on the same Windows app, to access the same controls, or windows.
lb
For ListBoxs, I doubt GetWindowText() will have anything.. :(
lb
+1  A: 

The name property is something added, AFAIK, by the compiler. Win32 does not, inttrinsicaly, support naming like this.
In C/C++ one uses the IDC_* value instead with the added bonus that integer comparisons are far faster than string comparison.

Edit: Btw Its possible to use the IDC values mentioned above to get child controls of a dialog by using the GetDlgItemInt( hDlgWnd, IDC_* ) to get an HWND to the control. Far easier then using EnumWindows ....

Goz
What exactly is this IDC_* value? How can I access it?
lb
When you define a given control you assign an "id" to it. Using the Visual Studio dialog designer it will automatically get assigned a constant (its actually a #define in "resource.h") integer value that represents it. This usually has the form IDC_*, ie ID = identifier and C = control.
Goz
So how can I access it from the C++/Win32 point of view? Is it part of a struct? Or do I use a Win32 API function by passing the handle? Sorry If I sound confused, this is totally new (I'm a .NET boy that knows little about the insides)
lb
+1  A: 

I seriously doubt that this information is even in the executable code, I would think that from the c# compilers point of view these symbols get reduced to object pointers or window identifiers values (the IDC_ mentioned above).

Having been faced with this type of problem before I chose to create hidden static text controls with identifying text on each window to provide this named window capability to an external process. Not very elegant but solved my problem at the time.

Elemental
hehe I see. :) Are you coming from actually making the software? This is 3rd party I'm trying to control, sorry if I didn't explicitly state it.. I have the problem to ask about a specific question instead of overall view..
lb
Yeah I made both sides - as a third party I don't see any specific solution - do you actually need the name of the window or just a way to uniquely identify it?
Elemental
I actually needed this as I needed to parse the text of cells in a gridview and operate from there on..
lb