我有一個程序需要將BM_CLICK消息發送到另一個應用程序按鈕。 我可以得到父窗口的句柄,但是當我嘗試獲得按鈕句柄,如果總是返回0從另一個應用程序獲取按鈕句柄
我從Spy ++得到了按鈕標題名稱和按鈕類型它似乎是正確的,但我知道我一定得到了錯誤。下面是我的代碼
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", CharSet = CharSet.Auto, 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, IntPtr.Zero);
}
}
間諜屏幕截圖
嗨布賴恩,除非我誤解你的問題,我相信類名永遠必須是一個字符串否? – Mike 2010-09-23 01:23:01
更正了我的答案。 – 2010-09-23 01:30:27
嗨,布萊恩,好吧給一個嘗試,但仍然沒有:-) – Mike 2010-09-23 01:31:33