본문 바로가기
C# /WPF

[WPF] Title Bar에 최소화,최대화,닫기 버튼 숨기는 방안

by Hwoarang757 2024. 3. 21.

[WPF] Title Bar에 최소화,최대화,닫기 버튼 숨기는 방안

 

출처 : c# - How to hide close button in WPF window? - Stack Overflow

 

How to hide close button in WPF window?

I'm writing a modal dialog in WPF. How do I set a WPF window to not have a close button? I'd still like for its WindowState to have a normal title bar. I found ResizeMode, WindowState, and WindowS...

stackoverflow.com

 

Loaded 이벤트에 명시 하였습니다!

    /// <summary>
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class MainWindow : Window ,IDialog
    {
        private readonly int GWL_STYLE = -16;
        private readonly 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 MainWindow()
        {
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;

            //this.Hide();
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            IntPtr hwnd = new WindowInteropHelper(this).Handle;
            SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
        }
    }