当前位置:编程学习 > C#/ASP.NET >>

几个常用的API在c#中的定义

最近一个项目中用到的一些API,在解决一些实际的问题上(特别是和外部程序打交道)的时候还是蛮有用的。具体的参数什么的网上都有!

代码
 //置顶窗体
[DllImport("user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true)]
private static extern bool SetForegroundWindow(IntPtr hwnd);

//寻找窗体,一般是得到了窗体的句柄方便以后的操作
[DllImport("user32.dll ")]
public static extern IntPtr FindWindow(string className, string title);

//显示窗体(包括使得窗体最小化,最大化等等操作)
[DllImport("user32.dll ")]
public static extern bool ShowWindow(IntPtr hwnd, int cmdshow);

//获得窗体的位置(相对于整个屏幕)
[DllImport("user32.dll")]
public static extern int GetWindowRect(IntPtr hwnd, ref Rectangle rc);

//鼠标的点击事件
private readonly int MOUSEEVENTF_LEFTDOWN = 0x2;
private readonly int MOUSEEVENTF_LEFTUP = 0x4;
[DllImport("user32 ")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);

//设置鼠标的位置,一般和mouse_event合用
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);

//获得鼠标的位置
[DllImport("user32.dll")]
static extern bool GetCursorPos(ref Point lpPoint);

//设置窗体的位置
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int<
补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,