Jump to content
  • Advertisement
Sign in to follow this  
_Sigma

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

This topic is 4470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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().

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!