用微信电脑端截图dll库来实现微信截图功能

巴扎黑
发布: 2017-08-08 12:02:17
原创
3105 人浏览过

这篇文章主要为大家详细介绍了使用微信PC端的截图dll库实现微信截图功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了截图dll库实现微信截图功能 ,供大家参考,具体内容如下

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)
    {
      //注册热键(窗体句柄,热键ID,辅助键,实键)  
      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 系统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>
    ///   注册快捷键
    /// </summary>
    /// <param name="hWnd">持有快捷键窗口的句柄</param>
    /// <param name="fsModifiers">组合键</param>
    /// <param name="vk">快捷键的虚拟键码</param>
    /// <param name="callBack">回调函数</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">回调函数</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
  }
}
登录后复制

运行结果如图:

以上是用微信电脑端截图dll库来实现微信截图功能的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!