forked from yaunqiying/EasyCharts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHookScroll.cs
96 lines (75 loc) · 3.13 KB
/
HookScroll.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace ExcelAddIn_Graphics
{
public partial class HookScroll
{
const int WM_LBUTTONDOWN = 0x201;
const int WM_LBUTTONDBLCLK = 0x203;
const int WM_RBUTTONDOWN = 0x204;
const int WM_RBUTTONDBLCLK = 0x206;
const int WM_NCHITTEST = 0x84; //发送到窗口,确定窗口的部分对应于特定屏幕坐标
const int VK_LBUTTON = 0x01; //指鼠标左键
const int WM_MOUSEMOVE = 0x200; //
const int WM_LBUTTONUP = 0x202; //
const int WM_RBUTTONUP = 0x205; //
const int GWL_WNDPROC = -4; //为窗口过程设定一个新的地址
private IntPtr HTCAPTION = new IntPtr(0x2); //在标题区
private IntPtr HTCLIENT = new IntPtr(0x1); //在客户区
[DllImport("user32", EntryPoint = "SetWindowLong")]
public static extern IntPtr SetWindowLong(IntPtr hwnd, int nIndex, IntPtr dwNewLong);
[DllImport("User32.dll")]
protected static extern short GetAsyncKeyState(int vKey);
[DllImport("user32", EntryPoint = "CallWindowProc")]
public static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hwnd, uint uMSG, int wParam, int lParam);
[DllImport("user32.dll")]
static extern bool UpdateWindow(IntPtr hWnd);
public delegate IntPtr WndProcHandler(IntPtr hWnd, uint msg, int wParam, int lParam);
public delegate void DrawHandler();
/////////////////////////////////////////////////////////////
/// 创建
/////////////////////////////////////////////////////////////
private IntPtr hWnd;
public IntPtr lpPrevWndProc;
public DrawHandler draw;
public HookScroll(IntPtr hWnd,DrawHandler draw)
{
this.hWnd = hWnd;
this.draw = draw;
}
public void Hook()
{
lpPrevWndProc = SetWindowLong(hWnd, GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(new WndProcHandler(WindowProc)));
}
public void UnHook()
{
SetWindowLong(hWnd, GWL_WNDPROC, lpPrevWndProc);
}
const int WM_HSCROLL = 0x0114;
const int WM_VSCROLL = 0x0115;
const int WM_MOUSEWHEEL = 0x20A;
public IntPtr WindowProc(IntPtr hWnd, uint uMsg, int wParam, int lParam)
{
switch ((int)uMsg)
{
case WM_HSCROLL:
case WM_VSCROLL:
//System.Windows.Forms.MessageBox.Show("WM_HSCROLL");
//draw();
break;
case WM_MOUSEWHEEL:
//System.Windows.Forms.MessageBox.Show("Test");
draw();
break;
default:
break;
}
//DoEvents
//System.Threading.Thread.Sleep(10);
return CallWindowProc(lpPrevWndProc, hWnd, uMsg, wParam, lParam);
}
}
}