Skip to content

Commit

Permalink
Disable Alt+F4 command
Browse files Browse the repository at this point in the history
  • Loading branch information
shibayan committed Sep 2, 2020
1 parent 54d9fd1 commit a06cd36
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
9 changes: 9 additions & 0 deletions WinQuickLook/Interop/Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ public static class Consts
public const int WH_KEYBOARD_LL = 13;
public const int WH_MOUSE_LL = 14;
public const int HC_ACTION = 0;

public const int HTCAPTION = 0x02;
public const int WM_NCRBUTTONDOWN = 0x00a4;
public const int WM_CONTEXTMENU = 0x007b;
public const int WM_KEYDOWN = 0x0100;
public const int WM_SYSKEYDOWN = 0x0104;
public const int WM_LBUTTONDOWN = 0x0201;

public const int VK_F4 = 0x73;

public const int MAX_PATH = 260;

public const int GWL_STYLE = -16;
public const int WS_MAXIMIZEBOX = 0x00010000;
public const int WS_MINIMIZEBOX = 0x00020000;
public const int WS_SYSMENU = 0x00080000;

public const int GWL_EXSTYLE = -20;
Expand Down
2 changes: 1 addition & 1 deletion WinQuickLook/QuickLookWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Name="window" d:DesignWidth="600" d:DesignHeight="400" MinWidth="400" MinHeight="400" Background="Transparent" WindowStyle="None"
ShowActivated="False" ShowInTaskbar="False" SnapsToDevicePixels="True" UseLayoutRounding="True" FocusVisualStyle="{x:Null}" WindowState="Normal"
ShowActivated="False" ShowInTaskbar="False" SnapsToDevicePixels="True" UseLayoutRounding="True" FocusVisualStyle="{x:Null}"
Unloaded="Window_Unloaded" SizeChanged="Window_SizeChanged">
<Window.Resources>
<ResourceDictionary Source="Styles.xaml" />
Expand Down
20 changes: 19 additions & 1 deletion WinQuickLook/QuickLookWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,25 @@ private void InitializeWindowStyle()
Marshal.FreeHGlobal(accentPolicyPtr);

var style = NativeMethods.GetWindowLong(hwnd, Consts.GWL_STYLE);
NativeMethods.SetWindowLong(hwnd, Consts.GWL_STYLE, style & ~Consts.WS_SYSMENU);
NativeMethods.SetWindowLong(hwnd, Consts.GWL_STYLE, style & ~(Consts.WS_SYSMENU | Consts.WS_MINIMIZEBOX | Consts.WS_MAXIMIZEBOX));

var hwndSource = HwndSource.FromHwnd(hwnd);
hwndSource.AddHook(WndProc);
}

private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case Consts.WM_SYSKEYDOWN:
if (wParam.ToInt32() == Consts.VK_F4)
{
handled = true;
}
break;
}

return IntPtr.Zero;
}

private void MoveWindowCentering(Size requestSize)
Expand Down

0 comments on commit a06cd36

Please sign in to comment.