新手上路,请多多指教! 我编写了一个程序,循环执行一段操作并显示进度条,此时程序处于等待状态,我想能够实现随时取消此操作,该处是否用到多线程?能否举例并附段代码? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不一定用多线程的,加上一段代码就行了while (1){ if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) { if(message.message==xxx消息) { ... } ::TranslateMessage(&message); ::DispatchMessage(&message); } ...} 要用线程。AfxBeginThread((AFX_THREADPROC)CAutoSelThread,this); 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; } } } 这机器配置装win 2008 server + sqlserver 2005 在线等答案 编译时的问题怎么解决? 哪位达人有window网络编程中文版电子书? 数据库添加记录问题.ODBC的 简单问题:创建一个类似ComboBox里的ListBox窗口 怎么检测一个进程加载了哪些dll? 如何进行类型转换?char型的转换 一个关于DLL/Lib的菜鸟问题 腐蚀和膨胀的相减运算得到什么? 希望大家来测试~~~~~~ 哎,高度程序出错, 不是说 “错误操作” 就是说“ 访问了非法的内存页”~~~~~~
while (1)
{
if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
{
if(message.message==xxx消息)
{
...
}
::TranslateMessage(&message);
::DispatchMessage(&message);
}
...
}
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;
}
}
}