I stole the code I found on the MSDN forums and made an extension method in the Window class, for example:
internal static class WindowExtensions { // from winuser.h private const int GWL_STYLE = -16, WS_MAXIMIZEBOX = 0x10000, WS_MINIMIZEBOX = 0x20000; [DllImport("user32.dll")] extern private static int GetWindowLong(IntPtr hwnd, int index); [DllImport("user32.dll")] extern private static int SetWindowLong(IntPtr hwnd, int index, int value); internal static void HideMinimizeAndMaximizeButtons(this Window window) { IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle; var currentStyle = GetWindowLong(hwnd, GWL_STYLE); SetWindowLong(hwnd, GWL_STYLE, (currentStyle & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX)); } }
The only thing to remember is that for some reason this does not work from the window constructor. I went around this by inserting this into the constructor:
this.SourceInitialized += (x, y) => { this.HideMinimizeAndMaximizeButtons(); };
Hope this helps!
Matt Hamilton Dec 04 '08 at 5:00 2008-12-04 05:00
source share