This article mainly for you in detail the use of PC-side DLL library implementation functions, with a certain reference value, interested in small partners can refer to
The example of this article for everyone to share the DLL library implementation functions for your reference, the specific content as follows
ScreenForm.cs Code:
Using system;using system.collections.generic;using system.runtime.interopservices;using System.Windows.Forms; namespace screent{public partial class Screenform:form {public Screenform () {InitializeComponent (); } private void Screencapture () {DLL.PRSCRN (); } protected override void WndProc (ref Message m) {base. WndProc (ref m); Hotkey.processhotkey (m); } private void Button1_Click (object sender, EventArgs e) {dll.prscrn (); } private void Form1_Load (object sender, EventArgs e) {//Register hotkey (form handle, hotkey ID, secondary key, real key) try {Hotke Y.regist (Handle, Hotkeymodifiers.mod_alt, KEYS.F1, screencapture); } catch (Exception te) {MessageBox.Show ("Alt + A Hotkey is occupied"); }} private void Form1_formclosed (object sender, Formclosedeventargs e) {//Note cancellation hotkey (handle, hotkey ID) hotkey.unre Gist (Handle, screencapture); }} public class DLL {[DllImport ("PrScrn.dll", EntryPoint = "Prscrn")] public static extern int Prscrn (); Consistent with DLL} public static class Hotkey {#region system API [DllImport ("User32.dll")] [Return:marshalas (unmanage Dtype.bool)] private static extern Bool RegisterHotKey (IntPtr hWnd, int id, hotkeymodifiers fsmodifiers, Keys VK); [DllImport ("User32.dll")] private static extern bool Unregisterhotkey (INTPTR hWnd, int id); #endregion public delegate void Hotkeycallbackhanlder (); Private Const int wm_hotkey = 0x312; private static int keyID = 10; private static readonly Dictionary<int, hotkeycallbackhanlder> keymap = new Dictionary<int, Hotkeycallbackha Nlder> (); <summary>///Register shortcut key///</summary>//<param name= "HWnd" > hold the handle of the accelerator window </param>// <param name= "fsmodifiers" > Key combinations </param>//<param name= "VK" > Shortcut keys for virtual keys </param>//<param N Ame= "CallBack" > callback function </param> public static void Regist (IntPtr hWnd, Hotkeymodifiers fsmodIfiers, Keys VK, Hotkeycallbackhanlder callBack) {int id = keyid++; if (! RegisterHotKey (hWnd, ID, fsmodifiers, VK)) throw new Exception ("Regist hotkey fail."); Keymap[id] = CallBack; }///<summary>///Logout shortcut key////</summary>//<param name= "hWnd" > Hold Handle to Accelerator window </param> <param name= "CallBack" > callback function </param> public static void Unregist (IntPtr hWnd, Hotkeycallbackhanlder CA Llback) {foreach (var var in keymap) {if (Var). Value = = callBack) Unregisterhotkey (HWnd, var.) Key); }}///<summary>///Accelerator message processing///</summary> public static void Processhotkey (message m) { if (m.msg = = Wm_hotkey) {int id = m.wparam.toint32 (); Hotkeycallbackhanlder callback; if (keymap. TryGetValue (ID, out callback)) {callback (); }}}} public enum hotkeymodifiers {mod_alt = 0x1, Mod_control = 0x2, Mod_shift = 0x4, Mod_win = 0x8}}
Operation Result: