单击按钮后SendMessage被卡住
本文关键字:SendMessage 按钮 单击 | 更新日期: 2023-09-27 18:11:58
我无法指出的奇怪问题。搜索主窗口,然后搜索标题为"开始"的按钮控件。在它找到开始并发送按钮点击后,它就一直坐着,永远不会过去,所以我从来没有在控制台中看到"离开循环"。
按钮确实被按下了,弹出一个消息框,我将在这段代码之外继续回答。奇怪的是,一旦我手动回答该框,它就会突破NativeMethods.SendMessage(start,BM_CLICK,IntPtr.Zero,"(;我看到了《离开循环》,然后一切都很愉快,继续前进。
我在这里错过了什么?希望我解释得足够好。
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;
}
}
}
SendMessage
是一个同步调用:它等待消息处理后再返回。根据您的描述,听起来BM_CLICK的处理程序显示了一个模式对话框,这意味着SendMessage在模式对话框被取消之前不会返回。
请改用PostMessage
。