天天看點

php 微信相親截圖,使用微信PC端的截圖dll庫實作微信截圖功能

[導讀]這篇文章主要為大家詳細介紹了使用微信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

}

}