我试图在WindowsAPI中使用FindWindow / FindWindowEx找到另一个(MFC)程序的MessageBox。我的代码是无限循环。我怎么能找到它?
我正在使用此代码:
case 17: // target Program's Create Button
// Click
SendMessage(hWnd, WM.LBUTTONDOWN, 0, null);
SendMessage(hWnd, WM.LBUTTONUP, 0, null);
// -> Show MessageBox in Display
// my program is stop. What's the happen ?
/******** here is Problem Code. (infinite loop) ********/
int main = FindWindow(null, "Create Connecter"); // Parent
int finish = 0;
do {
finish = FindWindowEx(main, 0, null, "Encode"); // MessageBox
textBox1.AppendText("Wating....");
System.Threading.Thread.Sleep(100);
} while (finish == 0);
textBox1.AppendText("Find MessageBox !!");
/********************************************************/
// OK Button Click in MessageBox
hWnd = FindWindowEx(finish, 0, "Button", "OK");
SendMessage(hWnd, WM.LBUTTONDOWN, 0, null);
SendMessage(hWnd, WM.LBUTTONUP, 0, null);
那是:
有人帮助我......我想上床睡觉。
答案 0 :(得分:0)
我自己解决了一个问题。
使用此代码:
case 17: // target Program's Create Button
// Click : SendMessage -> PostMessage
PostMessage(hWnd, WM.LBUTTONDOWN, 0, null);
PostMessage(hWnd, WM.LBUTTONUP, 0, null);
// used SendMessage : my program is stop
// useing PostMessage : no problem
/******** here is Problem Code. (infinite loop) ********/
int main = FindWindow(null, "Create Connecter"); // Parent
int finish = 0;
do {
finish = FindWindowEx(main, 0, null, "Encode"); // MessageBox
textBox1.AppendText("Wating....");
System.Threading.Thread.Sleep(100);
} while (finish == 0 || main == finish);
textBox1.AppendText("Find MessageBox !!");
/********************************************************/
// OK Button Click in MessageBox
hWnd = FindWindowEx(finish, 0, "Button", "OK");
SendMessage(hWnd, WM.LBUTTONDOWN, 0, null);
SendMessage(hWnd, WM.LBUTTONUP, 0, null);