I would like to remove the close button (x on top right) in my WPF application. I found some hints in the web and do it like that:
private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x80000;
[DllImport("user32.dll")]
private extern static int SetWindowLong(IntPtr hwnd, int index, int value);
[DllImport("user32.dll")]
private extern static int GetWindowLong(IntPtr hwnd, int index);
public MainWindow()
{
SourceInitialized += MainWindow_SourceInitialized;
InitializeComponent();
}
void MainWindow_SourceInitialized(object sender, EventArgs e)
{
WindowInteropHelper wih = new WindowInteropHelper(this);
int style = GetWindowLong(wih.Handle, GWL_STYLE);
SetWindowLong(wih.Handle, GWL_STYLE, style & ~WS_SYSMENU);
}
That works fine so far, except that it also removes my minimize/maximize buttons. But i only want to remove the close button. Is there a way just to remove the close button only and keep the maximize and minimize button?
For those who think it is an bad idea to remove the x button because i have read this here before: Its not due to bad UI design or whatever. It just a matter of fact that not all user levels should be allowed to close an application in an productive environment.