~~~~~~Dialog应用程序APP的Onldle()为什么不起作用,在线等~~~~~~

addition 2003-04-14 09:32:42
我用向导新建一个工程,是Dialog的
然后用classwizard把CWinApp的onIdel()函数弄出来,
可是他怎么不执行呢?就是我在里面写代码竟然不会执行,是什么道理
急啊
...全文
101 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
afc 2003-04-15
  • 打赏
  • 举报
回复
最简单的方法,改成如下
static CTestdlgDlg dlg;
dlg.Create(IDD_TESTDLG_DIALOG, NULL);
m_pMainWnd = &dlg;

return TRUE;
然后在对话框的OnOK和OnCancel函数中加入
AfxGetApp()->PostThreadMessage(WM_QUIT, 0, 0);
maoxianwang 2003-04-14
  • 打赏
  • 举报
回复
关注,蹭分
addition 2003-04-14
  • 打赏
  • 举报
回复
哦,这么麻烦啊
那么Create怎么写啊,就是这种方法要怎么弄啊?????
afc 2003-04-14
  • 打赏
  • 举报
回复
对话框应用程序使用的是模态方式调用
CTestDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
...

return FALSE;
调用dlg.DoModal()函数后程序一直在这里等待对话框关闭,所以theApp的OnIdle函数
不会被调用,如果要在OnIdle中运行代码的话应该使用非模态对话框,也就是使用Create函数
建立对话框
addition 2003-04-14
  • 打赏
  • 举报
回复
好像它从来就不会进去OnIdle()嘛!
addition 2003-04-14
  • 打赏
  • 举报
回复
不是很明白,试试看了,
我的是(默认的阿)
BOOL CMyApp::OnIdle(LONG lCount)
{
// TODO: Add your specialized code here and/or call the base class

return CWinApp::OnIdle(lCount);
}
然后里面我加了一句话,结果就是根本就没有进去,等于这个函数没有用
cxjlw 2003-04-14
  • 打赏
  • 举报
回复
The following two examples show how to use OnIdle. The first example processes two idle tasks using the lCount argument to prioritize the tasks. The first task is high priority, and you should do it whenever possible. The second task is less important and should be done only when there is a long pause in user input. Note the call to the base-class version of OnIdle. The second example manages a group of idle tasks with different priorities.

BOOL CMyApp::OnIdle(LONG lCount)
{
BOOL bMore = CWinApp::OnIdle(lCount);

if (lCount == 0)
{
TRACE("App idle for short period of time\n");
bMore = TRUE;
}
else if (lCount == 10)
{
TRACE("App idle for longer amount of time\n");
bMore = TRUE;
}
else if (lCount == 100)
{
TRACE("App idle for even longer amount of time\n");
bMore = TRUE;
}
else if (lCount == 1000)
{
TRACE("App idle for quite a long period of time\n");
// bMore is not set to TRUE, no longer need idle
// IMPORTANT: bMore is not set to FALSE since CWinApp::OnIdle may
// have more idle tasks to complete.
}

return bMore;
// return TRUE as long as there is any more idle tasks
}

Second Example

// In this example, four idle loop tasks are given various
// opportunities to run:
// Task1 is always given a chance to run during idle time, provided
// that no message has queued up while the framework was processing
// its own idle loop tasks (at lCount levels 0 and 1).
// Task2 is given a chance to run only if Task1 has already run,
// provided that no message has queued up while Task1 was running.
// Task3 and Task4 are given a chance to run only if both Task1 and
// Task2 have already run, and no message has queued up in the mean
// time. If Task3 gets its chance to run, then Task4 always gets
// a chance to run immediately after Task3.

BOOL CMyApp::OnIdle(LONG lCount)
{
// In this example, as in most applications, you should let the
// base class CWinApp::OnIdle complete its processing before you
// attempt any additional idle loop processing.
if (CWinApp::OnIdle(lCount))
return TRUE;

// The base class CWinApp::OnIdle reserves the lCount values 0
// and 1 for the framework's own idle processing. If you wish to
// share idle processing time at a peer level with the framework,
// then replace the above if-statement with a straight call to
// CWinApp::OnIdle; and then add a case statement for lCount value
// 0 and/or 1. Study the base class implementation first to
// understand how your idle loop tasks will compete with the
// framework's idle loop processing.

switch (lCount)
{
case 2:
Task1();
return TRUE; // next time give Task2 a chance
case 3:
Task2();
return TRUE; // next time give Task3 and Task4 a chance
case 4:
Task3();
Task4();
return FALSE; // cycle through the idle loop tasks again
}
return FALSE;
}

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧