Search code examples
c#wpfwindowsaerowindow-resize

WPF: Make window unresizeable, but keep the frame?


I have a window that does not have a title bar (WindowStyle == WindowStyle.None). The entire window uses the Aero glass effect. When I make the window unresizeable (ResizeMode == ResizeMode.NoResize), the glass effect disappears and my controls just hang in midair. (Essentially, the window itself disappears but leaves its contents.)

Is there a way for me to make the window unresizeable without getting rid of the window frame?


I have read the question Enable Vista glass effect on a borderless WPF window, but that's not quite what I want--I would like to keep the window border. For an example of what I would like my window to look like, hit Alt+Tab with Aero enabled.


To clarify, I do no want the resize cursors to show up at all when hovering over the window border. This is essentially what I want my window to look like:

Projector

The solution doesn't have to be strictly WPF--I am fine with hacking around with the Win32 API in order to achieve this.


Solution

  • You can hook the wndproc and intercept the WM_WINDOWPOSCHANGING message. Not strictly WPF, but probably your best bet.

    If you want to hide the resize cursors, then your best bet is to intercept WM_NCHITTEST. Call the DefWindowProc (to get the default behavior), and test the return value; if it's HTBOTTOM, HTBOTTOMLEFT, HTBOTTOMRIGHT, HTTOP, HTTOPLEFT, or HTTOPRIGHT, change the return value to HTBORDER.