Skip to content

Instantly share code, notes, and snippets.

@Grabacr07
Created May 25, 2012 19:48
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 Grabacr07/2790144 to your computer and use it in GitHub Desktop.
Save Grabacr07/2790144 to your computer and use it in GitHub Desktop.
http://grabacr.net/archives/208 に張ったコードをそのまま。ただのテストですよ?
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interactivity;
using System.Windows.Interop;
namespace SystemMenuSample
{
public class HideSystemMenuBehavior : Behavior<Window>
{
[DllImport("user32")]
private static extern int GetWindowLong(
IntPtr hWnd, int nIndex);
[DllImport("user32")]
private static extern int SetWindowLong(
IntPtr hWnd, int nIndex, int dwLong);
private int GWL_STYLE = -16;
private int WS_SYSMENU = 0x00080000;
private int WM_SYSKEYDOWN = 0x0104;
private int VK_F4 = 0x73;
protected override void OnAttached()
{
base.OnAttached();
this.AssociatedObject.SourceInitialized += (sender, e) =>
{
var handle =
new WindowInteropHelper(this.AssociatedObject).Handle;
var windowStyle = GetWindowLong(handle, GWL_STYLE);
windowStyle &= ~WS_SYSMENU;
SetWindowLong(handle, GWL_STYLE, windowStyle);
var hwndSource = HwndSource.FromHwnd(handle);
hwndSource.AddHook(this.WndProc);
};
}
private IntPtr WndProc(
IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam,
ref bool handled)
{
if (msg == WM_SYSKEYDOWN && wParam.ToInt32() == VK_F4)
{
handled = true;
}
return IntPtr.Zero;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment