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