我正在从windows应用程序的WndProc函数调用子例程。当按钮被按下时,从消息处理循环中调用WndProc。该子例程需要相当长的时间才能运行,因此它使用SendMessage(WM_USER)定期发送消息。这些消息应该会导致屏幕更新。不幸的是,所有更新都会一直保留到子例程返回;此时,所有消息都会得到处理,屏幕也会更新。消息的处理程序在WndProc中;它使窗口无效,这将导致生成一条绘图消息。
我是否需要将该子例程作为单独的线程运行?
发布于 2010-08-05 22:30:30
发布于 2010-08-05 22:29:17
最好的方法是使用单独的线程。但您也可以在handler function中运行消息循环:
HWND hwnd;
BOOL fDone;
MSG msg;
// Begin the operation and continue until it is complete
// or until the user clicks the mouse or presses a key.
fDone = FALSE;
while (!fDone)
{
fDone = DoLengthyOperation(); // application-defined function
// Remove any messages that may be in the queue. If the
// queue contains any mouse or keyboard
// messages, end the operation.
while (PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE))
{
switch(msg.message)
{
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_KEYDOWN:
//
// Perform any required cleanup.
//
fDone = TRUE;
}
}
} https://stackoverflow.com/questions/3415644
复制相似问题