api 怎么声明阿 FindWindowEx 参数的数据类型
试了没成功,能详细点吗?
我写了一个完整的,你看看吧:
1、命名空间:
using System.Runtime.InteropServices;
2、定义:
[DllImport("user32", EntryPoint = "SendMessageA")]//传送信息给控件
private static extern int SendMessage(IntPtr Hwnd, int wMsg, int wParam, int lParam);
[DllImport("user32", EntryPoint = "FindWindowExA")]
private static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string lpsz1, string lpsz2);
private const int BM_CLICK = 0x00F5;
3、Button_Click事件:
IntPtr dialogHandle = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "登录到 .NET Messenger Service - MSN Messenger"); // 寻找窗口句柄
if (dialogHandle != IntPtr.Zero)
{
IntPtr buttonHandle = FindWindowEx(dialogHandle, IntPtr.Zero, "Button", "确定");//该窗口内的Button按钮
if (buttonHandle != IntPtr.Zero)
{
MessageBox.Show("OK");
SendMessage(buttonHandle, BM_CLICK, 0, 0);//给Button发送信息
}
}
楼主,我已经测试通过了,你试试吧。