How do you disable Aero Snap in an application?

前端 未结 11 2295
一向
一向 2020-11-29 09:36

Is it possible to disable the automatic window-docking feature of Windows 7 in a WPF application?

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 10:09

    A rather simple solution I found that works with borderless windows as well: Just hide the maximize button (event if it's already not displayed due to the lack of caption bar):

        [DllImport("user32.dll")]
        private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
        [DllImport("user32.dll")]
        private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
        private const int GWL_STYLE = -16;
        private const int WS_MAXIMIZEBOX = 0x10000;
    
        private void Window_OnSourceInitialized(object sender, EventArgs e)
        {
                var hwnd = new WindowInteropHelper((Window)sender).Handle;
                var value = GetWindowLong(hwnd, GWL_STYLE);
                SetWindowLong(hwnd, GWL_STYLE, (int)(value & ~WS_MAXIMIZEBOX));
        }
    

提交回复
热议问题