/// <summary> /// 隐藏标题栏(包括ICon, titlebar的右键菜单, 三个系统窗口按钮) /// </summary> /// <param name="w"></param> public static void HideSysMenu(this Window w) { IntPtr hwnd = new WindowInteropHelper(w).Handle; int extendedStyle = WindowApiHelper.GetWindowLong(hwnd, WindowStaticMacro.GWL_EXSTYLE); WindowApiHelper.SetWindowLong(hwnd, WindowStaticMacro.GWL_EXSTYLE, extendedStyle | WindowStaticMacro.WS_EX_DLGMODALFRAME); WindowApiHelper.SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, WindowStaticMacro.SWP_NOMOVE | WindowStaticMacro.SWP_NOSIZE | WindowStaticMacro.SWP_NOZORDER | WindowStaticMacro.SWP_FRAMECHANGED); }
/// <summary> /// 移除Icon /// </summary> /// <param name="window"></param> public static void RemoveIcon(this Window window) { // Get this window's handle IntPtr hwnd = new WindowInteropHelper(window).Handle; // Change the extended window style to not show a window icon int extendedStyle = WindowApiHelper.GetWindowLong(hwnd, WindowStaticMacro.GWL_EXSTYLE); WindowApiHelper.SetWindowLong(hwnd, WindowStaticMacro.GWL_EXSTYLE, extendedStyle | WindowStaticMacro.WS_EX_DLGMODALFRAME); // Update the window's non-client area to reflect the changes WindowApiHelper.SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, WindowStaticMacro.SWP_NOMOVE | WindowStaticMacro.SWP_NOSIZE | WindowStaticMacro.SWP_NOZORDER | WindowStaticMacro.SWP_FRAMECHANGED); }