Recently in a spoof program, is opened, the program gets the desktop then, and then full screen display on the screen, the user can not do anything at this time.
At this time, I hope that the user can not use the keyboard alt+f4 to end the program and through the win key to the window operation. I searched the Internet, using the global keyboard hook method can be done to block the user's keyboard operation. The following is the related code, which uses the Form1_Load event and the Form1_formclosing event:
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.text;using system.windows.forms;using system.runtime.interopservices;using System.Reflection; Namespace windowsapplication10{public partial class form1:form{//mounting hooks [DllImport ("User32.dll")]public static extern int SetWindowsHookEx (int idhook, HookProc lpfn, IntPtr hinstance, int threadId);//unload Hook [DllImport ("User32.dll")]public static extern bool UnhookWindowsHookEx (int idhook);//Continue Next Hook [DllImport ("User32.dll")]public static extern int CallNextHookEx (int idhook, int nCode, Int32 wParam, IntPtr lParam);//Declaration defines public delegate int HookProc (int nCode, Int32 wPa RAM, IntPtr lParam); static int hkeyboardhook = 0; HookProc keyboardhookprocedure;public Form1 () {InitializeComponent ();} private void Form1_Load (object sender, EventArgs e) {Hookstart ();} private void Form1_formclosing (object sender, FormClosingEventArgs e) {hookstop ();} Install hook public void Hookstart () {if (HkeyboardhoOK = = 0) {//create HookProc instance keyboardhookprocedure = new HookProc (KEYBOARDHOOKPROC);//define global hook Hkeyboardhook = SetWindowsHookEx (Keyboardhookprocedure, Marshal.gethinstance (assembly.getexecutingassembly). GetModules () [0]), 0);
If not, put Marshal.gethinstance (assembly.getexecutingassembly (). GetModules () [0]) changed to IntPtr.Zero
if (Hkeyboardhook = = 0) {hookstop (); throw new Exception ("SetWindowsHookEx failed.");}} }//The hook is what the hook is going to do. private int Keyboardhookproc (int nCode, Int32 wParam, IntPtr lParam) {//Here you can add another function of code return 1;}//unload hook public void Hoo Kstop () {bool Retkeyboard = true; if (Hkeyboardhook! = 0) {Retkeyboard = UnhookWindowsHookEx (hkeyboardhook); Hkeyboardho OK = 0; } if (! ( Retkeyboard)) throw new Exception ("UnhookWindowsHookEx failed."); } } }
(Note: This method can shield win and alt+f4 but not shield Ctrl+alt+del)
C # Winform Implementation code that implements the win and alt+f4 of the shielded keyboard