Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keydata As System.Windows.Forms.Keys) As Boolean
'屏蔽 Alt + F4
Dim WM_KEYDOWN As Integer = 256
Dim WM_SYSKEYDOWN As Integer = 260
If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
Select Case keydata
Case Keys.Alt + Keys.F4
Return (True)
End Select
End If
End Function
using System;
using System.Runtime.InteropServices;
namespace Hook
{
/// <summary>
/// 设置键盘钩子屏蔽win键
/// </summary>
public class Win32Hook
{
public Win32Hook()
{
}
private IntPtr hHook =IntPtr.Zero;
public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
public const int WH_KEYBOARD = 13;
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern bool UnhookWindowsHookEx(IntPtr idHook);
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern int CallNextHookEx(IntPtr idHook, int nCode, IntPtr wParam, IntPtr lParam);
[StructLayout(LayoutKind.Sequential)]
public struct KBDLLHOOKSTRUCT
{
public int vkCode;
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
}