Ho un programma che deve inviare il messaggio BM_CLICK a un altro pulsante di applicazioni. Posso ottenere l'handle della finestra genitore ma quando cerco di ottenere l'handle del pulsante se restituisce sempre 0Ottenere un handle Button da un'altra applicazione
Ho il nome del pulsante e il tipo di pulsante da Spy ++ sembra giusto, ma so che devo aver trovato qualcosa di sbagliato. qui di seguito è il mio codice
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);
}
}
schermo Spy girato
ciao Brian, a meno che non fraintenda ciò che stai chiedendo, credo che il nome della classe debba sempre essere una stringa no? – Mike
Correggere la mia risposta. –
Ciao Brian, Ok, provalo e ancora niente :-) – Mike