您好,登錄后才能下訂單哦!
小編給大家分享一下用微信PC端dll庫(kù)如何實(shí)現(xiàn)截圖,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
ScreenForm.cs代碼:
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) { //注冊(cè)熱鍵(窗體句柄,熱鍵ID,輔助鍵,實(shí)鍵) try { Hotkey.Regist(Handle, HotkeyModifiers.MOD_ALT, Keys.F1, ScreenCapture); } catch (Exception te) { MessageBox.Show("Alt + A 熱鍵被占用"); } } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { //注消熱鍵(句柄,熱鍵ID) Hotkey.UnRegist(Handle, ScreenCapture); } } public class DLL { [DllImport("PrScrn.dll", EntryPoint = "PrScrn")] public static extern int PrScrn(); //與dll中一致 } public static class Hotkey { #region 系統(tǒng)api [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.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, HotKeyCallBackHanlder>(); /// <summary> /// 注冊(cè)快捷鍵 /// </summary> /// <param name="hWnd">持有快捷鍵窗口的句柄</param> /// <param name="fsModifiers">組合鍵</param> /// <param name="vk">快捷鍵的虛擬鍵碼</param> /// <param name="callBack">回調(diào)函數(shù)</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> /// 注銷快捷鍵 /// </summary> /// <param name="hWnd">持有快捷鍵窗口的句柄</param> /// <param name="callBack">回調(diào)函數(shù)</param> public static void UnRegist(IntPtr hWnd, HotKeyCallBackHanlder callBack) { foreach (var var in keymap) { if (var.Value == callBack) UnregisterHotKey(hWnd, var.Key); } } /// <summary> /// 快捷鍵消息處理 /// </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 } }
運(yùn)行結(jié)果如圖:
以上是用微信PC端dll庫(kù)如何實(shí)現(xiàn)截圖的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。