Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a windows region without disabling theming

Does anyone know how to assign a window region (SetWindowRgn or Control.Region in WinForms) without killing the theming in the non-client area?

For example, running the following generates a Windows 2000-style unthemed title bar, border, etc:

var form = new Form { Width=500, Height=500, BackColor = Color.Azure };
form.Text = "But soft, what light through yonder window breaks?";
var region = new Region (new Rectangle (Point.Empty, form.Size));
region.Exclude (new Rectangle (100, 100, 300, 300));
form.Region = region;
form.ShowDialog();

I'm guessing it's to do with this MSDN article which says:

As long as a window has a non-NULL region applied to it (SetWindowRgn), the UxTheme Manager assumes that this is a specialized window and the window will not use visual styles.

...hence UxThemes assumes it's a specialized window. Is there a way to tell the UxTheme Manager explicitly to theme a window?

like image 375
Joe Albahari Avatar asked Jun 11 '11 01:06

Joe Albahari


1 Answers

The answer to your question is that you cannot.

But a workaround, to give you a transparent section in your form, would be to add the WS_EX_LAYERED extended window style to your form. Then you can tell the Window Manager that you want to use a chroma-color key to make part of your form transparent:

SetLayeredWindowAttributes(
      Form.Handle, //  __in  HWND hwnd,
      RGB(0, 255, 0), //green is the color key     __in  COLORREF crKey,
      255, //window is opaque otherwise  __in  BYTE bAlpha,
      LWA_COLORKEY //use color-key (rather than per-pixel alpha)  __in  DWORD dwFlags
);

Then you can put your "transparent" area as lime green:

enter image description here

Which then at runtime will be transparent:

enter image description here


Update: When i use layered window to have full transparency mouse events do trickle through to what's underneath. Notice the "flag" icon highlight:

enter image description here

See also

  • Window Overview -> Window Features -> Layered Windows
  • SetLayeredWindowAttributes Function
  • Extended Window Styles
  • Layered Windows
like image 99
Ian Boyd Avatar answered Sep 28 '22 20:09

Ian Boyd