views:

432

answers:

3

The environment is plain-old win32 under C/C++ without any fancy MFC or similar mumbo-jumbo. I have a window, which has several children and grandchildren. Some children are oddly-shaped icons, and I need them to have transparent background (oddly-shaped icons). Consider a this pseudo-structure:

  • Parent1
    • Child1 (normal)
    • Child2 (oddly-shaped icon)
    • Child3 (normal) / Parent2
      • Grandchild1 (normal)
      • Grandchild2 (oddly-shaped icon)

Above, Child2 and Grandchild2 are supposed to have transparent background (WM_ERASEBKGND does nothing, or (WNDCLASS)->hbrBackground = NULL). Right now the background for these icons is transparent, but transparent to extreme -- I see stuff under Parent1 -- desktop, etc.

This all happens under Windows Mobile.

Is there any extra flag I have to set for Parent1 and Parent2? Any good tricks you might offer?

I would be surprised if noone had similar problems, since many applications now have to display icons, all shapes and sizes.

EDIT: The oddly-shaped window is icon with transparencies. It would be nice if parent window would not do clipping for these particular windows, but invalidate them every time parent draws itself. CS_PARENTDC looks very promising, but not promising enough. Any ideas?

+1  A: 

In the oddly shaped windows, how are you handling WM_PAINT? Are you erasing the background? Maybe a better solution would be to use a non-rectangular clipping region?

EDIT SetWindowRgn is documented here - I was incorrect to say "clipping region", I was really thinking of this method. You set up an irregular region which is the shape of your icon and then draw to that. I think this is probably a common technique for drawing windows with odd shapes.

1800 INFORMATION
Yes, WM_PAINT is calling DrawIcon. How do I set up that non-rectangular clipping region?
Ignas Limanauskas
A: 

If you try using SetBkColor() cant you specify the colors in your WM_PAIN processing for the window, and then it doesn't matter if it irregular in size. Am I getting your question correctly ?

Roman M
The background (parent window) is not necessarily plain color. It might be gradient or, worse, a bitmap!
Ignas Limanauskas
A: 

GWES will not paint the rectangle of any child window with contents of the parent window. Ever. Period. That's by design.

You can either paint in the child rectangle in response to WM_CTL... in the parent, or subclass the child and override its WM_PAINT completely. That will be really tough for certain windows, such as edit controls, but it's mostly doable.

Johann Gerell