Created
August 30, 2012 10:13
-
-
Save tormodfj/3525505 to your computer and use it in GitHub Desktop.
P/Invoke for hiding the Close button of a WPF Window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static class Win32 | |
{ | |
private const int GWL_STYLE = -16; | |
private const int WS_SYSMENU = 0x80000; | |
[DllImport("user32.dll", SetLastError = true)] | |
private static extern int GetWindowLong(IntPtr hWnd, int nIndex); | |
[DllImport("user32.dll")] | |
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); | |
public static void HideCloseButton(this Window window) | |
{ | |
var hwnd = new WindowInteropHelper(window).Handle; | |
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment