views:

214

answers:

4

I'm trying to make some static controls transparent on a windows dialog, but I'm having difficulty with one windows message.

Windows happily sends me a WM_CTLCOLORSTATIC message when drawing static controls, but this message is also sent to readonly and disabled edit controls. So - given just a hwnd to the control, how can I tell what kind of control it is?

+1  A: 

In case you don't have many controls, use GetDlgCtrlID() to get control's resource id.
With that info, you can filter out any controls that you don't want.

Nick D
unfortunately, this dialog has hundreds :( I did think of putting all the static IDs in a range and using that, but thought I'd ask for alternatives first. May still use the ID range though. cheers.
gbjbaanb
You dont need to use an ID range - you can assign all static controls the same ID. I (for example) assigned static controls on my dialog a custom ID: `ID_STATIC_RED` - when I handle the `WM_CTLCOLORSTATIC` I check the control for that and set the text color to red giving me fine grained control over what statics get what colors.
Chris Becke
+1  A: 

Use the GetClassName function. Some of the predefined class names like BUTTON are listed here. See also How To Get a Window's Class Name and Other Window Attributes.

It's the 'class name' that determines what "kind" of control it is (more specifically, the class defines the window procedure, which defines the control's behaviour ... or only slightly more complicated if the control has been subclassed by someone).

ChrisW
+1  A: 

You could call GetClassName i.e

// given controlHwnd passed to me
TCHAR controlClassName[128];

GetClassName(controlHwnd,controlClassName,128);

You'd then have to do a bunch of string compares based on the string i.e "Button" - so not great but should work.

zebrabox
+1  A: 

As an optimization, you could first try to find your first Static control by using GetClassName and string compares, then, once you find one, store its class atom gotten using GetClassLong(hWnd, GCW_ATOM) and compare atoms from now on.

Koro