栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

使用微信PC端的截图dll库实现微信截图功能

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用微信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 keymap =
      new Dictionary();

    /// 
    ///   注册快捷键
    /// 
    /// 持有快捷键窗口的句柄
    /// 组合键
    /// 快捷键的虚拟键码
    /// 回调函数
    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;
    }

    /// 
    ///   注销快捷键
    /// 
    /// 持有快捷键窗口的句柄
    /// 回调函数
    public static void UnRegist(IntPtr hWnd, HotKeyCallBackHanlder callBack)
    {
      foreach (var var in keymap)
      {
 if (var.Value == callBack)
   UnregisterHotKey(hWnd, var.Key);
      }
    }

    /// 
    ///   快捷键消息处理
    /// 
    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
  }
}

运行结果如图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/55585.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号