[C/C++] Find HWND of button in a window

Started by
13 comments, last by Oluseyi 17 years, 7 months ago
Is there a way to retrieve the HWND of a button (based on its .bmp / Win ID / etc) in a window (I have the HWND of the window in question). I've searched google up and down, but I'm not sure quite what i'm looking for, so any tips, points would be great!
Advertisement
If you have the HWND of the parent and the control ID of the button then just use GetDlgItem(). If you have the HWND of the parent and the text of the button then you can use FindWindowEx(). If you dont have those but you know how to tell if a given child window HWND is the one you're looking for then you can use EnumChildWindows().
I have HWND of parent, but the button doesn't have any text on it. Just a bitmap. Can anything be done with that?

How does one get the control ID?

Cheers

[Edited by - _Sigma on September 18, 2006 10:55:06 PM]
You can get the ID of the window using GetDlgCtrlID(). You can find out if a window is a button using GetClassName() and you can find out if it's a bitmap button by using GetWindowLongPtr() with GWLP_style
Alright. Thanks for that.

Another question. Lest say I wanted to enable ALL the buttons in the window. What is a good way to do that?
I ask b/c there are 3 other buttons that are BITMAP buttons! So how could I tell the difference b/w the three?

Thanks
Without further information about what you know about these buttons, I dont think you'll be able to differentiate between them.
Quote:Original post by _Sigma
Lest say I wanted to enable ALL the buttons in the window. What is a good way to do that?

If you just want to enable a number of controls, you can use EnumChildWindows along with GetClassName, and EnableWindow.

[Edited by - raz0r on September 19, 2006 1:25:48 PM]
This is what I know:

HWND of parent window
Class name of the button is "Button"
Caption of the button is "BITMAP" BUT this isn't a label on the button. This is only what WindowsJuggler (plugin for Olly debugger) told me. The button ONLY has a bitmap on it.

There are 3 other buttons, all of which have the SAME information as given above.

So, thus my question, how do I tell the difference b/w them, and I agree, I don't think I can.

Quote:If you just want to enable a number of controls, you can use EnumChildWindows along with GetClassName, and EnableWindow.
This method needs a callback function, so what should I do in the call back funtion? I understand that I need to do
In callback:GetClassName(mainHwnd,buff,255);if buff == "BUTTON"//do w/e


but i'm not sure exactly how to do this. Is the call back called recursivly on each component of the window?

Any example would be awesome. Thanks!
Like you said:
int _stdcall DummyEnumerator(HWND WindowHandle, LPARAM){	char szBuffer[MAX_CLASS_NAME] = {};	::GetClassName(WindowHandle, szBuffer, sizeof(szBuffer));	if(!std::strcmp(szBuffer, "Button"))		::EnableWindow(WindowHandle, TRUE);	return TRUE;}//...::EnumChildWindows(TargetWindowHandle, ::DummyEnumerator, NULL);
raz0r, When I pass the window handle to the enumerator, and i check the WindowHandle var from within the function, it's not right...Any ideas?

This topic is closed to new replies.

Advertisement