Skip to content

Instantly share code, notes, and snippets.

@tormodfj
Created August 30, 2012 10:13
Show Gist options
  • Save tormodfj/3525505 to your computer and use it in GitHub Desktop.
Save tormodfj/3525505 to your computer and use it in GitHub Desktop.
P/Invoke for hiding the Close button of a WPF Window
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