Skip to content

Instantly share code, notes, and snippets.

@sachintha81
Created June 22, 2017 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sachintha81/26129460b20659dcd1b08aa206207b36 to your computer and use it in GitHub Desktop.
Save sachintha81/26129460b20659dcd1b08aa206207b36 to your computer and use it in GitHub Desktop.
WPF Hide Window Close Button (Red X Button)
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace KawasakiLogConverter
{
/// <summary>
/// Interaction logic for ProgressBarWindow.xaml
/// </summary>
public partial class ProgressBarWindow : Window
{
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 ProgressBarWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var hwnd = new WindowInteropHelper(this).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