# [Win32] Get Dialog Contrl Type

## Recommended Posts

I'm not sure if Win32 Discussions belongs Here (I couldn't find a Windows Only Forum). Basically, I'm creating an editor for my game and I'm using dialog boxes instead of Windows (Because you can design them using the VS resource editor). I have many controls on this dialog window and Instead of Manually sifting through all the controls to see what type it is, is there a way to programatically read out the control type based on the handle? Here is what I'm trying to do:
HWND hwnd = GetTopWindow(m_hWnd);
UINT id;

// Loop through all the controls on the Window and save it's functions
while (hwnd)
{
// Grab the next "Window" control
hwnd = GetNextWindow(hwnd, GW_HWNDNEXT);

// *** Is there a way to Get Control Type from HWND?? ***
// eg: if (GetDlgCtlType() == PUSHBUTTON) CButton btn = hwnd;
}


GetDlgCtlType() doesnt exist, obviously, but what I want to do is essentially the same type of logic in that comment. Any suggestions on this matter are greatly appreciated. Using MFC is an option but I'm trying to see if this way can be done first. Thanks.

##### Share on other sites
Quote:
 I'm using dialog boxes instead of Windows
A dialog box *is* a window. And so are the controls in it (usually).

What you're looking for is GetClassName. Once you have the class name you may need to do additional processing to refine the type. e.g. class "BUTTON" includes regular push buttons, radio buttons, check boxes, etc., etc.

I'm not entirely sure what you're doing but suspect that you're trying to go about things the hard way. If you're creating the dialog don't you already know what type of control you created?

##### Share on other sites
Quote:
Original post by Anon Mike
Quote:
 I'm using dialog boxes instead of Windows
A dialog box *is* a window. And so are the controls in it (usually).

That's true, I only said it merely to convey the fact that I'm using Dialogs instead of making a window using CreateWindowEx() just in case DIalogs had shortcomings that I was not aware of.

Quote:
 What you're looking for is GetClassName. Once you have the class name you may need to do additional processing to refine the type. e.g. class "BUTTON" includes regular push buttons, radio buttons, check boxes, etc., etc.

This is most excellent! Thanks!!

Quote:
 I'm not entirely sure what you're doing but suspect that you're trying to go about things the hard way. If you're creating the dialog don't you already know what type of control you created?

The Hard Way? Maybe. The reason why I'm doing this is because I have many controls on this window and manually entering it by hand would be a big hastle:
CEdit strEditBox = GetDlgItem(m_hWnd, IDC_EDIT_STRENGTH);CEdit dexEditBox = GetDlgItem(m_hWnd, IDC_EDIT_DEXTERITY);CEdit conEditBox = GetDlgItem(m_hWnd, IDC_EDIT_CONSTITUTION);// etc.. do this for 100+ controls that I have

I'm trying to make the source code a bit shorter as well as less of an eyesore.