我有一个程序需要将BM_CLICK消息发送到另一个应用程序按钮.
我可以获得父窗口句柄,但是当我尝试获取按钮句柄时,如果总是返回0
我可以获得父窗口句柄,但是当我尝试获取按钮句柄时,如果总是返回0
我从间谍那里得到了按钮标题名称和按钮类型似乎没错,但我知道我一定是弄错了.下面是我的代码
public const Int BM_CLICK = 0x00F5; [DllImport("user32.dll",CharSet = CharSet.Auto,SetLastError = true)] private static extern IntPtr SendMessage(IntPtr hwnd,uint Msg,IntPtr wParam,IntPtr lParam); [DllImport("user32.dll",SetLastError = true)] static extern IntPtr FindWindowEx(IntPtr hwndParent,IntPtr hwndChildAfter,string lpszClass,string lpszWindow); private void button1_Click(object sender,EventArgs e) { Process[] processes = Process.GetProcessesByName("QSXer"); foreach (Process p in processes) { ////the Button's Caption is "Send" and it is a "Button". IntPtr ButtonHandle = FindWindowEx(p.MainWindowHandle,IntPtr.Zero,"Button","Send"); //ButtonHandle is always zero thats where I think the problem is SendMessage(ButtonHandle,BM_CLICK,IntPtr.Zero); } }
间谍屏幕截图