.Net 使用句柄与其他程序交互


[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]

private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]

private static extern IntPtr FindWindowEx(IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]

private static extern IntPtr SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);

[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Unicode)]

private static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, IntPtr wParam, string lParam);

[DllImport("user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true)]

private static extern void SetForegroundWindow(IntPtr hwnd);

引入系统API后,就可以使用FindWindow,FindWindowEx,SetForegroundWindow,SendKeys,SendMessage等等来操作应用了~

查系统API就可以搞定大部分工作了~


发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

验证码 * Time limit is exhausted. Please reload CAPTCHA.