日期:2014-05-17  浏览次数:21040 次

C#调用Win32 的API函数--User32.dll
Win32的API函数是微软自己的东西,可以直接在C#中直接调用,在做WinForm时还是很有帮助的。有时候我们之直接调用Win32 的API,可以很高效的实现想要的效果。

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace WindowsAPI
{
class CSharp_Win32Api
{
#region User32.dll 函数
/// <summary>
/// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在GDI函数中使用该句柄来在设备上下文环境中绘图。hWnd:设备上下文环境被检索的窗口的句柄
/// </summary>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetDC(IntPtr hWnd);
/// <summary>
/// 函数释放设备上下文环境(DC)供其他应用程序使用。
/// </summary>
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
/// <summary>
/// 该函数返回桌面窗口的句柄。桌面窗口覆盖整个屏幕。
/// </summary>
static public extern