Use the screenshot dll library on WeChat PC to implement the WeChat screenshot function.

Source: Internet
Author: User

Use the PC dll library to implement the function.

This article provides examples of dll library implementation functions for your reference. The specific content is 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 button#click (object sender, EventArgs e) {DLL. prScrn ();} private void Form1_Load (object sender, EventArgs e) {// register the Hotkey (Form handle, Hotkey ID, secondary key, solid key) try {Hotkey. regist (Handle, HotkeyModifiers. MOD_ALT, Keys. f1, ScreenCapture);} catch (Exception te) {MessageBox. show ("Alt + A Hot Key occupied") ;}} private void form=formclosed (object sender, FormClosedEventArgs e) {// Delete Hotkey (handle, Hotkey ID) Hotkey. unRegist (Handle, ScreenCapture);} public class DLL {[DllImport ("PrScrn. dll ", EntryPoint =" PrScrn ")] public static extern int PrScrn (); // consistent with that in dll} public static class Hotkey {# region system api [DllImport ("user32.dll")] [return: financialas (UnmanagedType. bool)] private static extern bool RegisterHotKey (IntPtr hWnd, int id, HotkeyModifiers fsModifiers, Keys vk); [DllImport ("user32.dll")] private static extern bool partial (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> /// register the shortcut key /// </summary> /// <param name = "hWnd"> hold the handle of the shortcut key window </param> // /<param name = "fsModifiers"> key combination </param> // <param name = "vk"> virtual key code of the shortcut key </pa Ram> // <param name = "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> /// cancel the shortcut key /// </summary> /// <param name = "hWnd"> hold the handle of the shortcut key window </param> // /<param name = "callBack"> callBack function </param> public static void UnRegist (IntPtr hWnd, hotKeyCallBackHanlder callBack) {foreach (var in keymap) {if (var. value = callBack) UnregisterHotKey (hWnd, var. key) ;}//< summary> /// shortcut Key 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 }}

Running result:

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.