最近一個項目中用到的一些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<