在 死循环 处 加void DoEvents() { MSG msg; // Process existing messages in the application's message queue. // When the queue is empty, do clean up and return. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)) {// has msg if (!AfxGetThread()->PumpMessage()) break; } }
如果没有最小化,检测到按键F10就开始循环,循环中不断判断一个标志变量,如果标志为真就退出循环。循环中还要不断响应系统消息,以便有按键消息F12时可以执行。
检测到按键F12改变标志变量的值为真。如果你本身的程序也要最小化,可能需要Hook来检测按键F10和F12。
{
MSG msg;
// Process existing messages in the application's message queue.
// When the queue is empty, do clean up and return.
while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
{// has msg
if (!AfxGetThread()->PumpMessage()) break;
}
}
一定要注意,发送按键的POSTMESSAGE之类的一定要放在工作线程中,否则会占住主线程,是什么都干不来了。