Reputation: 6552
Strange issue I can't put my finger on. Search for the main window, then I search for the button control with the caption "Start". After it finds start and sends the button click, it just sits and never gets past that so I never see "Leaving loop" in the console.
The button does get pressed and a message box pops up that I would continue to answer outside of this section of code. The odd thing is once I manually answer that box it then breaks past NativeMethods.SendMessage(start, BM_CLICK, IntPtr.Zero, ""); and I see "Leaving Loop" and then it's all happy and continues on it's way.
What am I missing here? Hope I explained this well enough.
while (!mainFound)
{
hwnd = NativeMethods.FindWindow(null, "Loader");
if (!hwnd.Equals(IntPtr.Zero))
{
Console.WriteLine("Found Main");
IntPtr p = IntPtr.Zero;
while (!mainFound)
{
hwndChild = NativeMethods.FindWindowEx(hwnd, p, null, null);
if (hwndChild == IntPtr.Zero)
{
break;
}
IntPtr start = NativeMethods.FindWindowEx(hwndChild, IntPtr.Zero, null, "Start");
if (!start.Equals(IntPtr.Zero))
{
Console.WriteLine("Found Start");
NativeMethods.SendMessage(start, BM_CLICK, IntPtr.Zero, "");
Console.WriteLine("Leaving Loop");
mainFound = true;
}
//Console.WriteLine(hwndChild);
p = hwndChild;
}
}
}
Upvotes: 0
Views: 1158
Reputation: 12276
SendMessage
is a synchronous call: it waits for the message to be processed before returning. From your description, it sounds like the handler for BM_CLICK displays a modal dialog, which means that SendMessage won't return until the modal dialog is dismissed.
Try PostMessage
instead.
Upvotes: 2