指を置くことができない奇妙な問題。メイン ウィンドウを検索し、「開始」というキャプションを持つボタン コントロールを検索します。開始を見つけてボタンクリックを送信した後、ただ座ってそれを通過することはないため、コンソールに「Leaving loop」が表示されることはありません。
ボタンが押されるとメッセージ ボックスが表示され、このコード セクションの外で引き続き回答します。奇妙なことに、そのボックスに手動で回答すると、NativeMethods.SendMessage(start, BM_CLICK, IntPtr.Zero, ""); を通過します。そして「Leaving Loop」を見ると、それはすべて幸せで、その道を進んでいます。
ここで何が欠けていますか?これを十分に説明したことを願っています。
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;
}
}
}