1 user32.dll中的所有函数
2
3
4
5
6 using System;
7 using System.Collections.Generic;
8 using System.Linq;
9 using System.Text;
10 using System.Runtime.InteropServices;
11
12 namespace WindowsAPI
13 {
14 class CSharp_Win32Api
15 {
16 #region User32.dll 函数
17 /// <summary>
18 /// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下
19
20
21 文环境的句柄,以后可以在GDI函数中使用该句柄来在设备上下文环境中绘图
22
23
24 。hWnd:设备上下文环境被检索的窗口的句柄
25 /// </summary>
26 [DllImport("user32.dll", CharSet = CharSet.Auto)]
27 public static extern IntPtr GetDC(IntPtr hWnd);
28 /// <summary>
29 /// 函数释放设备上下文环境(DC)供其他应用程序使用。
30 /// </summary>
31 public static extern int ReleaseDC(IntPtr hWnd, IntPtr
32
33
34 hDC);
35 /// <summary>
36 /// 该函数返回桌面窗口的句柄。桌面窗口覆盖整个屏幕。
37 /// </summary>
38 static public extern IntPtr GetDesktopWindow();
39 /// <summary>
40 /// 该函数设置指定窗口的显示状态。
41 /// </summary>
42 static public extern bool ShowWindow(IntPtr hWnd, short
43
44
45 State);
46 /// <summary>
47 /// 通过发送重绘消息 WM_PAINT 给目标窗体来更新目标窗体客户
48
49
50 区的无效区域。
51 /// </summary>
52 static public extern bool UpdateWindow(IntPtr hWnd);
53 /// <summary>
54 /// 该函数将创建指定窗口的线程设置到前台,并且激活该窗口。
55
56
57 键盘输入转向该窗口,并为用户改各种可视的记号。系统给创建前台窗口的
58
59
60 线程分配的权限稍高于其他线程。
61 /// </summary>
62 static public extern bool SetForegroundWindow(IntPtr hWnd);
63
64
65
66 /// <summary>
67 /// 该函数改变一个子窗口,弹出式窗口式顶层窗口的尺寸,位置
68
69
70 和Z序。
71 /// </summary>
72 static public extern bool SetWindowPos(IntPtr hWnd, IntPtr
73
74
75 hWndInsertAfter, int x, int y, int Width, int Height, uint flags);
76
77
78
79 /// <summary>
80 /// 打开剪切板
81 /// </summary>
82 static public extern bool OpenClipboard(IntPtr
83
84
85 hWndNewOwner);
86 /// <summary>
87 /// 关闭剪切板
88 /// </summary>
89 static public extern bool CloseClipboard();
90 /// <summary>
91 /// 打开清空</summary>
92 static public extern bool EmptyClipboard();
93 /// <summary>
94 /// 将存放有数据的内存块放入剪切板的资源管理中
95 /// </summary>
96 static public extern IntPtr SetClipboardData(uint Format,
97
98
99 IntPtr hData);
100 /// <summary>
101 /// 在一个矩形中装载指定菜单条目的屏幕坐标信息
102 /// </summary>
103 static public extern bool GetMenuItemRect(IntPtr hWnd,
104
105
106 IntPtr hMenu, uint Item, ref RECT rc);
107
108 [DllImport("user32.dll", ExactSpelling = true, CharSet =
109
110
111 CharSet.Auto)]
112 /// <summary>
113 /// 该函数获得一个指定子窗口的父窗口句柄。
114 /// </summary>
115 public static extern IntPtr GetParent(IntPtr hWnd);
116 /// <summary>
117 /// 该函数将指定的消息发送到一个或多个窗口。此函数为指定的
118
119
120 窗口调用窗口程序,直到窗口程序处理完消息再返回。
121 /// </summary>
122 /// <param name="hWnd">其窗口程序将接收消息的窗口的句柄
123
124
125 </param>
126 /// <param name="msg">指定被发送的消息</param>
127 /// <param name="wParam">指定附加的消息指定信息</param>
128 /// <param name="lParam">指定附加的消息指定信息</param>
129 /// <returns></returns>
130 public static extern int SendMessage(IntPtr hWnd, int msg,
131
132
133 int wParam, int lParam);
134 public static extern IntPtr SendMessage(IntPtr hWnd, int
135
136
137 msg, int wParam, IntPtr lParam);
138 public static extern void SendMessage(IntPtr hWnd, int msg,
139
140
141 int wParam, ref RECT lParam);
142 public static extern int SendMessage(IntPtr hWnd, int msg,
143
144
145 int wParam, ref POINT lParam);
146 public static extern void SendMessage(IntPtr hWnd, int msg,
147
148
149 int wParam, ref TBBUTTON lParam);
150 public static extern void SendMessage(IntPtr hWnd, int msg,
151
152
153 int wParam, ref TBBUTTONINFO lParam);
154 public static extern int SendMessage(IntPtr hWnd, int msg,
155
156
157 int wParam, ref REBARBANDINFO lParam);
158 public static extern void SendMessage(IntPtr hWnd, int msg,
159
160
161 int wParam, ref TVITEM lParam);
162 public static extern void SendMessage(IntPtr hWnd, int msg,
163
164
165 int wParam, ref LVITEM lParam);
166 public static extern void SendMessage(IntPtr hWnd, int msg,
167
168
169 int wParam, ref HDITEM lParam);
170 public static extern void SendMessage(IntPtr hWnd, int msg,
171
172
173 int wParam, ref HD_HITTESTINFO hti);
174 /// <summary>
175 /// 该函数将一个消息放入(寄送)到与指定窗口创建的线程相联
176
177
178 系消息队列里
179 /// </summary>
180 public static extern IntPtr PostMessage(IntPtr hWnd, int
181
182
183 msg, int wParam, int lParam);
184 public static extern IntPtr SetWindowsHookEx(int hookid,
185
186
187 HookProc pfnhook, IntPtr hinst, int threadid);
188
189 [DllImport("user32.dll", CharSet = CharSet.Auto,
190
191
192 ExactSpelling = true)]
193 public static extern bool UnhookWindowsHookEx(IntPtr
194
195
196 hhook);
197
198 [DllImport("user32.dll", CharSet = CharSet.Auto,
199
200
201 ExactSpelling = true)]
202 public static extern IntPtr CallNextHookEx(IntPtr hhook,
203
204
205 int code, IntPtr wparam, IntPtr lparam);
206 /// <summary>
207 /// 该函数对指定的窗口设置键盘焦点。
208 /// </summary>
209 public static extern IntPtr SetFocus(IntPtr hWnd);
210 /// <summary>
211 /// 该函数在指定的矩形里写入格式化文本,根据指定的方法对文
212
213
214 本格式化(扩展的制表符,字符对齐、折行等)。
215 /// </summary>
216 public extern static int DrawText(IntPtr hdc, string
217
218
219 lpString, int nCount, ref RECT lpRect, int uFormat);
220 /// <summary>
221 /// 该函数改变指定子窗口的父窗口。
222 /// </summary>
223 public extern static IntPtr SetParent(IntPtr hChild, IntPtr
224
225
226 hParent);
227 /// <summary>
228 /// 获取对话框中子窗口控件的句柄
229 /// </summary>
230 public extern static IntPtr GetDlgItem(IntPtr hDlg, int
231
232
233 nControlID);
234 /// <summary>
235 /// 该函数获取窗口客户区的坐标。
236 /// </summary>
237 public extern static int GetClientRect(IntPtr hWnd, ref
238
239
240 RECT rc);
241 /// <summary>
242 /// 该函数向指定的窗体添加一个矩形,然后窗口客户区域的这一
243
244
245 部分将被重新绘制。
246 /// </summary>
247 public extern static int InvalidateRect(IntPtr hWnd, IntPtr
248
249
250 rect, int bErase);
251 /// <summary>
252 /// 该函数产生对其他线程的控制,如果一个线程没有其他消息在
253
254
255 其消息队列里。
256 /// </summary>
257 public static extern bool WaitMessage();
258 /// <summary>
259 /// 该函数为一个消息检查线程消息队列,并将该消息(如果存在
260
261
262 )放于指定的结构。
263 /// </summary>
264 public static extern bool PeekMessage(ref MSG msg, int
265
266
267 hWnd, uint wFilterMin, uint wFilterMax, uint wFlag);
268 /// <summary>
269 /// 该函数从调用线程的消息队列里取得一个消息并将其放于指定
270
271
272 的结构。此函数可取得与指定窗口联系的消息和由PostThreadMesssge寄送的
273
274
275 线程消息。此函数接收一定范围的消息值。
276 /// </summary>
277 public static extern bool GetMessage(ref MSG msg, int hWnd,
278
279
280 uint wFilterMin, uint wFilterMax);
281 /// <summary>
282 /// 该函数将虚拟键消息转换为字符消息。
283 /// </summary>
284 public static extern bool TranslateMessage(ref MSG msg);
285 /// <summary>
286 /// 该函数调度一个消息给窗口程序。
287 /// </summary>
288 public static extern bool DispatchMessage(ref MSG msg);
289 /// <summary>
290 /// 该函数从一个与应用事例相关的可执行文件(EXE文件)中载入
291
292
293 指定的光标资源.
294 /// </summary>
295 public static extern IntPtr LoadCursor(IntPtr hInstance,
296
297
298 uint cursor);
299 /// <summary>
300 /// 该函数确定光标的形状。
301 /// </summary>
302 public static extern IntPtr SetCursor(IntPtr hCursor);
303 /// <summary>
304 /// 确定当前焦点位于哪个控件上。
305 /// </summary>
306 public static extern IntPtr GetFocus();
307 /// <summary>
308 /// 该函数从当前线程中的窗口释放鼠标捕获,并恢复通常的鼠标
309
310
311 输入处理。捕获鼠标的窗口接收所有的鼠标输入(无论光标的位置在哪里)
312
313
314 ,除非点击鼠标键时,光标热点在另一个线程的窗口中。
315 /// </summary>
316 public static extern bool ReleaseCapture();
317 /// <summary>
318 /// 准备指定的窗口来重绘并将绘画相关的信息放到一个
319
320
321 PAINTSTRUCT结构中。
322 /// </summary>
323 public static extern IntPtr BeginPaint(IntPtr hWnd, ref
324
325
326 PAINTSTRUCT ps);
327 /// <summary>
328 /// 标记指定窗口的绘画过程结束,每次调用BeginPaint函数之后被
329
330
331 请求
332 /// </summary>
333 public static extern bool EndPaint(IntPtr hWnd, ref
334
335
336 PAINTSTRUCT ps);
337 /// <summary>
338 /// 半透明窗体
339 /// </summary>
340 public static extern bool UpdateLayeredWindow(IntPtr hwnd,
341
342
343 IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref
344
345
346 POINT pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32
347
348
349 dwFlags);
350 /// <summary>
351 /// 该函数返回指定窗口的边框矩形的尺寸。该尺寸以相对于屏幕
352
353
354 坐标左上角的屏幕坐标给出。
355 /// </summary>
356 public static extern bool GetWindowRect(IntPtr hWnd, ref
357
358
359 RECT rect);
360 /// <summary>
361 /// 该函数将指定点的用户坐标转换成屏幕坐标。
362 /// </summary>
363 public static extern bool ClientToScreen(IntPtr hWnd, ref
364
365
366 POINT pt);
367 /// <summary>
368 /// 当在指定时间内鼠标指针离开或盘旋在一个窗口上时,此函数
369
370
371 寄送消息。
372 /// </summary>
373 public static extern bool TrackMouseEvent(ref
374
375
376 TRACKMOUSEEVENTS tme);
377 /// <summary>
378 ///
379 /// </summary>
380 public static extern bool SetWindowRgn(IntPtr hWnd, IntPtr
381
382
383 hRgn, bool redraw);
384 /// <summary>
385 /// 该函数检取指定虚拟键的状态。
386 /// </summary>
387 public static extern ushort GetKeyState(int virtKey);
388 /// <summary>
389 /// 该函数改变指定窗口的位置和尺寸。对于顶层窗口,位置和尺
390
391
392 寸是相对于屏幕的左上角的:对于子窗口,位置和尺寸是相对于父窗口客户
393
394
395 区的左上角坐标的。
396 /// </summary>
397 public static extern bool MoveWindow(IntPtr hWnd, int x,
398
399
400 int y, int width, int height, bool repaint);
401 /// <summary>
402 /// 该函数获得指定窗口所属的类的类名。
403 /// </summary>
404 public static extern int GetClassName(IntPtr hWnd, out
405
406
407 STRINGBUFFER ClassName, int nMaxCount);
408 /// <summary>
409 /// 该函数改变指定窗口的属性
410 /// </summary>
411 public static extern int SetWindowLong(IntPtr hWnd, int
412
413
414 nIndex, int dwNewLong);
415 /// <summary>
416 /// 该函数检索指定窗口客户区域或整个屏幕的显示设备上下文环
417
418
419 境的句柄,在随后的GDI函数中可以使用该句柄在设备上下文环境中绘图。
420
421
422
423 /// </summary>
424 public static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr
425
426
427 hRegion, uint flags);
428 /// <summary>
429 /// 获取整个窗口(包括边框、滚动条、标题栏、菜单等)的设备
430
431
432 场景 返回值 Long。
433 /// </summary>
434 public static extern IntPtr GetWindowDC(IntPtr hWnd);
435 /// <summary>
436 /// 该函数用指定的画刷填充矩形,此函数包括矩形的左上边界,
437
438
439 但不包括矩形的右下边界。
440 /// </summary>
441 public static extern int FillRect(IntPtr hDC, ref RECT
442
443
444 rect, IntPtr hBrush);
445 /// <summary>
446 /// 该函数返回指定窗口的显示状态以及被恢复的、最大化的和最
447
448
449 小化的窗口位置。
450 /// </summary>
451 public static extern int GetWindowPlacement(IntPtr hWnd,
452
453
454 ref WINDOWPLACEMENT wp);
455 /// <summary>
456 /// 该函数改变指定窗口的标题栏的文本内容
457 /// </summary>
458 public static extern int SetWindowText(IntPtr hWnd, string
459
460
461 text);
462 /// <summary>
463 /// 该函数将指定窗口的标题条文本(如果存在)拷贝到一个缓存
464
465
466 区内。如果指定的窗口是一个控制,则拷贝控制的文本。
467 /// </summary>
468 public static extern int GetWindowText(IntPtr hWnd, out
469
470
471 STRINGBUFFER text, int maxCount);
472 /// <summary>
473 /// 用于得到被定义的系统数据或者系统配置信息.
474 /// </summary>
475 static public extern int GetSystemMetrics(int nIndex);
476 /// <summary>
477 /// 该函数设置滚动条参数,包括滚动位置的最大值和最小值,页
478
479
480 面大小,滚动按钮的位置。
481 /// </summary>
482 static public extern int SetScrollInfo(IntPtr hwnd, int
483
484
485 bar, ref SCROLLINFO si, int fRedraw);
486 /// <summary>
487 /// 该函数显示或隐藏所指定的滚动条。
488 /// </summary>
489 public static extern int ShowScrollBar(IntPtr hWnd, int
490
491
492 bar, int show);
493 /// <summary>
494 /// 该函数可以激活一个或两个滚动条箭头或是使其失效。
495 /// </summary>
496 public static extern int EnableScrollBar(IntPtr hWnd, uint
497
498
499 flags, uint arrows);
500 /// <summary>
501 /// 该函数将指定的窗口设置到Z序的顶部。
502 /// </summary>
503 public static extern int BringWindowToTop(IntPtr hWnd);
504 /// <summary>
505 /// 该函数滚动指定窗体客户区域的目录。
506 /// </summary>
507 static public extern int ScrollWindowEx(IntPtr hWnd, int
508
509
510 dx, int dy,ref RECT rcScroll, ref RECT rcClip, IntPtr UpdateRegion,
511
512
513 ref RECT rcInvalidated, uint flags);
514 /// <summary>
515 /// 该函数确定给定的窗口句柄是否识别一个已存在的窗口。
516 /// </summary>
517 public static extern int IsWindow(IntPtr hWnd);
518 /// <summary>
519 /// 该函数将256个虚拟键的状态拷贝到指定的缓冲区中。
520 /// </summary>
521 public static extern int GetKeyboardState(byte[]
522
523
524 pbKeyState);
525 /// <summary>
526 /// 该函数将指定的虚拟键码和键盘状态翻译为相应的字符或字符
527
528
529 串。该函数使用由给定的键盘布局句柄标识的物理键盘布局和输入语言来翻
530
531
532 译代码。
533 /// </summary>
534 public static extern int ToAscii(int uVirtKey,int
535
536
537 uScanCode, byte[] lpbKeyState, byte[] lpwTransKey,int fuState);
538 #endregion
539
540 }
541 }