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

作者: Nishizhen 分类: C#相关 发布时间: 2011-04-08 17:14 ė 6没有评论
[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就可以搞定大部分工作了~

本文出自 逆时针's Place,转载时请注明出处及相应链接。

本文永久链接: http://www.nishizhen.cn/net-%e4%bd%bf%e7%94%a8%e5%8f%a5%e6%9f%84%e4%b8%8e%e5%85%b6%e4%bb%96%e7%a8%8b%e5%ba%8f%e4%ba%a4%e4%ba%92/

发表评论

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

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

Ɣ回顶部