I want to launch an external application and get the handle of its Connect button. I get the top level "000A0B32" and I can get this 100% correct. Then I'm trying to get the child element "000F0C58" and get the Connect button under it. But getting "000F0C58" fails frequently. Instead of "000F0C58", you can get "000D0B94" of the same class at the top level.
I'm expliciting the parent handle In FindWindowEx
.
I don't understand why I am getting irrelevant handles.
Both "000F0C58" and "000D0B94" have no Caption and cannot add conditions for FindWindowEx
.
I'm looking into how to get the matching stuff (like the process id) from all handles, but that's just an alternative. I believe that using FindWindowEx
correctly will guarantee results, and I'd like to know what I'm doing wrong.
As you may have noticed, I am not good at English. Simple English or code sample will help me.
Process.Start(@"C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe")
{
Process[] vpnui = this.GetProcessesByName("vpnui");
if (vpnui.Length != 0 && vpnui[0] != null)
{
mainChildHwnd = FindWindowEx(vpnui[0].MainWindowHandle, IntPtr.Zero, "#32770", null);
if (mainChildHwnd != null && mainChildHwnd != IntPtr.Zero)
{
IntPtr connectButtonHwnd = FindWindowEx(mainChildHwnd, IntPtr.Zero, "Button", "Connect");
if (connectButtonHwnd != null && connectButtonHwnd != IntPtr.Zero)
{
SendMessage(connectButtonHwnd, WM_LBUTTONDOWN, MK_LBUTTON, 0x000A000A);
SendMessage(connectButtonHwnd, WM_LBUTTONUP, 0x00000000, 0x000A000A);
}
}
}
}