简体   繁体   中英

Win32Api - Window Name Property

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? :)

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.

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 ....

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM