资源简介
利用c#写的jpg拼图软件,可以随意剪切和拼接
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace AutoDrawRect
{
public class MouseHook
{
//好吧这个没有用到
private bool isSet;
public bool IsSet {
get { return isSet; }
}
//这个也没有用到
private int handleOfHook;
public int HandleOfHook {
get { return handleOfHook; }
}
//这个还是没有用到、、、淡定!
private bool isStopMsg;
public bool IsStopMsg {
get { return isStopMsg; }
set { isStopMsg = value; }
}
//自己定义了一个事件 放到Hook里面去
public delegate void MEventhandler(object sender, MouseInfoEventArys e);
public event MEventhandler HooKMouseEvent;
[DllImport("user32.dll")]//设置钩子 第二个参数为回调函数指针
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hmod, int dwThreadid);
[DllImport("user32.dll")]//传递到下一个钩子
public static extern int CallNextHookEx(int hHook, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]//卸载钩子
public static extern bool UnhookWindowsHookEx(int hHook);
[DllImport("kernel32.dll")]//获取模块句柄
public static extern IntPtr GetModuleHandle(string lpModuleName);
public const int WH_MOUSE_LL = 14;//全局鼠标Hook 7是局部的 13全局键盘 2局部键盘
public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);//话说c#里面委托就是函数指针?、
private const int WM_LBUTTONDOWN = 0x201; //在Hook里面判断是否左键点下
private const int WM_RBUTTONUP = 0x205; //在Hook里面判断是否右键抬起
public struct POINT {//鼠标位置的结构体
public int x;
public int y;
}
public struct MouseLLInfo {//全局鼠标Hook的结构体
public POINT pt; //其实这里可以用Point只是这个新建的类里面没有应用System.Windows.Forms(应该是这个)
public int mouseData;
public int flags;
public int time;
public int dwExtraInfo;
}
GCHandle gc;//好吧 话说就是应为这个东西害得我研究了两天 没有这个的话 程序运行一会儿就提示崩溃了
//因为垃圾回收期把我的回调函数当垃圾收了 所以运行程序的时候 一会儿就提示我 一个垃圾的回调导致程序崩溃
//在非托管调用托管的时候 必须保持托管代码的或活动性 大概就这个意思 反正就是被收废品的收了、害的我用.net3.5用其他方式设置Hook
public int MouseHookProcedure(int nCode, IntPtr wParam, IntPtr lParam) {//这个就是回调函数了
if (nCode >= 0 && HooKMouseEvent != null) {//先判断是否事件被绑定(感觉有点多余的判断 丫的我不在上面绑定 我写Hook干嘛)
//话说是把内存的什么什么转换成结构体
MouseLLInfo mouseInfo = (MouseLLInfo)Marshal.PtrToStructure(lParam, typeof(MouseLLInfo));
Btn btn = Btn.None; //自己定义的一个枚举 里面只有三个值
if (wParam == (IntPtr)WM_LBUTTONDOWN) { //如果左键被点下
btn = Btn.LeftDowm;
} else if (wParam == (IntPtr)WM_RBUTTONUP) { //如果右键被抬起
btn = Btn.RightUp;
}
//好吧 我就不知道当时我怎么想的 在Hook里面获取的坐标 有负数的现象 所以在那边 我没用这个坐标
MouseInfoEventArys e = new MouseInfoEventArys(btn, mouseInfo.pt.x, mouseInfo.pt.y);
HooKMouseEvent(this, e);//触发绑定到这个上面的事件
}
return CallNextHookEx(handleOfHook, nCode, wParam, lParam);//继续下一个钩子
}
public bool SetMouseHook() { //设置Hook
if (isSet) {//如果已经设置了 就不要设置啦、、、
return false;
}
HookProc MouseCallBack = new HookProc(MouseHookProcedure);
handleOfHook = SetWindowsHookEx(WH_MOUSE_LL, MouseCallBack,
GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
if (handleOfHook != 0) {//如果设置成功、、
gc = GCHandle.Alloc(MouseCallBack);//这个就是那个什么什么、、然后我的回调就不会被收废品的拣去了
isSet = true;
return true;
}
return false;
}
public bool UnLoadMouseHook() {
if (!isSet) {//如果装都没有装那么久不要卸载啦、、
return false;
}
if (UnhookWindowsHookEx(handleOfHook)) {
gc.Free();//将回调释放掉、、
isSet = false;
return true;
}
return false;
}
}
public enum Btn//我只感觉到这三个有用、(应该是两个 左键点下 右键抬起)
{
LeftDowm, RightUp, None
}
public class MouseInfoEventArys {//话说定义事件的时候都是这么写的 所以我也弄一个内出来保存事件参数
private int x;//坐标 多余的后来才发现 鼠标慢慢贴近屏幕边缘的时候 3 2 1 0 -1 、、丫的 负数都出来了
public int X {
get { return x; }
}
private int y;//坐标
public int Y {
get { return y; }
}
private Btn mBtn;
public Btn MBtn {
get { return mBtn; }//鼠标的情况
}
public MouseInfoEventArys(Btn btn,int x,int y) {//构造器
mBtn = btn;
this.x = x;
this.y = y;
}
}
}
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//Download by http://www.codefans.net
using System.Runtime.InteropServices;
namespace AutoDrawRect
{
public partial class Form1 : Form
{
[DllImport(“user32.dll“)]
public static extern bool RegisterHotKey(IntPtr hWnd int id int fsModifiers int vk);
public const int MOD_ALT = 0x1;
public const int MOD_CONTROl = 0x2;
public const int HOTKEY = 0x312;
[DllImport(“user32.dll“)]
public static extern bool UnregisterHotKey(IntPtr hWnd int id);
public Form1() {
InitializeComponent();
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4064 2012-04-22 18:00 softhy.net\AutoDrawRect\AutoDrawRect\AutoDrawRect.csproj
文件 1595 2012-06-26 17:53 softhy.net\AutoDrawRect\AutoDrawRect\Form1.cs
文件 2076 2012-04-22 16:53 softhy.net\AutoDrawRect\AutoDrawRect\Form1.Designer.cs
文件 5817 2012-04-22 16:53 softhy.net\AutoDrawRect\AutoDrawRect\Form1.resx
文件 14413 2012-06-26 17:53 softhy.net\AutoDrawRect\AutoDrawRect\Form2.cs
文件 6217 2012-04-22 17:25 softhy.net\AutoDrawRect\AutoDrawRect\Form2.Designer.cs
文件 10634 2012-04-22 17:25 softhy.net\AutoDrawRect\AutoDrawRect\Form2.resx
文件 6277 2012-06-26 17:53 softhy.net\AutoDrawRect\AutoDrawRect\MouseHook.cs
文件 532 2012-06-26 17:56 softhy.net\AutoDrawRect\AutoDrawRect\Program.cs
文件 1454 2012-03-06 19:26 softhy.net\AutoDrawRect\AutoDrawRect\Properties\AssemblyInfo.cs
文件 2769 2012-03-06 19:26 softhy.net\AutoDrawRect\AutoDrawRect\Properties\Resources.Designer.cs
文件 5612 2012-03-06 19:26 softhy.net\AutoDrawRect\AutoDrawRect\Properties\Resources.resx
文件 1075 2012-03-06 19:26 softhy.net\AutoDrawRect\AutoDrawRect\Properties\Settings.Designer.cs
文件 249 2012-03-06 19:26 softhy.net\AutoDrawRect\AutoDrawRect\Properties\Settings.settings
文件 1513 2012-06-26 17:56 softhy.net\AutoDrawRect\AutoDrawRect\WinAPI.cs
文件 878 2012-03-06 19:26 softhy.net\AutoDrawRect\AutoDrawRect.sln
..A..H. 25600 2012-04-22 19:41 softhy.net\AutoDrawRect\AutoDrawRect.suo
目录 0 2012-06-26 17:50 softhy.net\AutoDrawRect\AutoDrawRect\Properties
目录 0 2012-06-26 17:52 softhy.net\AutoDrawRect\AutoDrawRect
目录 0 2012-06-26 17:50 softhy.net\AutoDrawRect
目录 0 2012-06-26 17:56 softhy.net
----------- --------- ---------- ----- ----
90775 21
相关资源
- c#入门经典 第七版 中文版 非扫描版
- .netc#新手菜鸟mvc5的仓库管理系统 so
- C# NPOI生成word插入图片和表格
- C#程序设计基础C#程序设计及应用教程
- 深入.NET平台和C#编程
- .net 美萍超市管理系统源码C#
- WinForm GeckoFx33 Demo JS与C#互交 窗口浏览
- 《ASP.NET程序设计项目教程》周虎,王
- 计算机图形学 三维模型处理算法初步
- C# KTV 点歌系统,C#项目源码带数据库
- C#实验--A.1 视频动态绘制练习.
- c#实现动态规划法——求解矩阵连乘问
- c#winform中完美代替WebBrowser最新的控件
- C#高级编程第9版:C#5.0 & .NET 4.5.1 par
- Illustrated C# 2010 C# 4.0图解教程
- C# WINFORM框架源碼
- C# WinForm实践开发教程清晰版
- 3D打印机上位机源码Reprap Host 是C#写的
- C#设计模式+源码JamesW.Cooper.zip
- C#程序开发范例宝典(第3版).(配套
- C#写的年会抽奖软件包含源代码.zip
- 大型ERP C#源码
- asp.net完整项目带数据库
- 清大出版社 段德亮 《C#课程设计案例
- C#人事管理系统/人力资源管理系统
- C# 7 and .NET Core: Modern Cross-Platform Deve
- C# 5.0 in a Nutshell 5th Edition.pdf
-
C# 6.0 and the .NET 4.6 fr
amework(7th). - C# .NET webservices简单使用
- C# 6.0 in a Nutshell.pdf

川公网安备 51152502000135号
评论
共有 条评论