forked from yaunqiying/EasyCharts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathXlWookbookHelperDef.cs
129 lines (100 loc) · 4.22 KB
/
XlWookbookHelperDef.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace ExcelAddIn_Graphics
{
public partial class XlWorkbookHelper
{
//http://blog.csdn.net/ke_yang/article/details/5417552
//屏幕参数
//CreateGraphics().DpiX;
private readonly int LOGPIXELSX = 88; //沿屏幕宽度每逻辑英寸的像素数,在多显示器系统中,该值对所显示器相同
private readonly int LOGPIXELSY = 90; //沿屏幕高度每逻辑英寸的像素数,在多显示器系统中,该值对所显示器相同
//GetSystemMetrics要用到的,获取窗口的边框大小,X表示横轴方向,Y表示纵轴方向
private readonly int SM_CXBORDER = 5;
private readonly int SM_CYBORDER = 6;
private readonly int SM_CXDLGFRAME = 7;
private readonly int SM_CYDLGFRAME = 8;
private readonly int SM_CXFRAME = 32;
private readonly int SM_CYFRAME = 33;
private readonly int SM_CXSIZEFRAME = 32;
private readonly int SM_CYSIZEFRAME = 33;
//
private readonly double PoundsPerInch = 72; //1 Inch = 72 Pound//
//
private IntPtr HWND_DESKTOP = IntPtr.Zero; //桌面句柄参数
private IntPtr HWND_SCREEN = IntPtr.Zero; //屏幕句柄参数
/////////////////////////////////////////////////////////
/// API区
/////////////////////////////////////////////////////////
//搜索窗口
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx
(
IntPtr hwndParent,
IntPtr hwndChildAfter,
string lpszClass,
string lpszWindow
);
//回调函数
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
public delegate bool EnumChildProc(IntPtr hwnd, IntPtr lParam);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool EnumChildWindows(int hwndParent, EnumChildProc EnumFunc, IntPtr lParam);
bool EnumCP(IntPtr hwnd, IntPtr lParam)
{
System.Text.StringBuilder sbClassName = new StringBuilder(255);
GetClassName(hwnd, sbClassName, 255);
if ("Static" == sbClassName.ToString())
{
return false;
}
return true;
}
//获取笔刷
[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern IntPtr GetWindowDC(IntPtr hwnd);
//获取设备句柄
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
//颜色
[DllImport("gdi32.dll")]
public static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
//获取设备参数
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern int GetDeviceCaps(IntPtr hDC, int index);
//获取尺寸
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
//获取坐标
public struct POINT
{
public int Left;
public int Top;
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
[DllImport("user32.dll")]
static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
static extern bool ClientToScreen(IntPtr hWnd, out POINT pt);
//得到被定义的系统数据或者系统配置信息
[DllImport("user32.dll")]
static extern int GetSystemMetrics(int smIndex);
//获得所有子窗口
private delegate bool EnumWindowsProc(IntPtr hWnd, int lParam);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc, int lParam);
}
}