问题1 :
if(dlg.DoModal()==IDOK){......}怎么理解啊?
问题2:
<pre style="padding: 0px; color: rgb(51, 51, 51); line-height: 24px; font-family: arial,'courier new',courier,宋体,monospace; font-size: 14px; margin-top: 10px; margin-bottom: 0px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;" class="line mt-10 q-content" name="code">当我 CMyDlg dlg;时,对话框显示了吗? 是不是要写dlg.DoModal();这时对话框才显示出来啊?
回答:
<pre style="padding: 0px; color: rgb(51, 51, 51); line-height: 24px; font-family: arial,'courier new',courier,宋体,monospace; font-size: 14px; margin-top: 0px; margin-bottom: 10px; white-space: pre-wrap; word-wrap: break-word; background-color: rgb(241, 254, 221);" id="best-content-214672597" class="best-text mb-10" name="code">当dlg.DoModal()后,显示一个<a target=_blank style="color: rgb(45, 100, 179); text-decoration: none;" class="inner-link decor-none" href="http://zhidao.baidu.com/search?word=%E6%A8%A1%E6%80%81%E5%AF%B9%E8%AF%9D%E6%A1%86&fr=qb_search_exp&ie=utf8" rel="nofollow" target="_blank">模态对话框</a>,此时DoModal()函数并不返回,即并没有执行大括号内的内容,直到用户关闭此对话框时,DoModal才返回。
如果用户点击了确定按钮,那么DoModal()函数就返回IDOK,此时进入if语句。IDOK是一个宏。 当你CMyDlg dlg;时,对话框并没有显示,只是构造了一个CMyDlg类型的对象而已,直到用户调用DoModal(),对话框才会显示出来。eg:
在CWelcome的对话框中,当点击某个按钮时,希望弹出CInitial 对话框,此时我们只希望在响应函数OnBtnInitial() 中加入以下两句代码即可:
<span style="white-space: pre;"> </span>CInitial dlg; <span style="white-space: pre;"> </span>dlg.DoModal();
if(threshsetdlg.DoModal()==IDOK),是什么意思?
threshsetdlg 这是一个对话框 用 DoModal() 方式去显示这个对话框 IDOK 这个是你创建对话框时,默认有一个确认按钮 你给这个按钮添加处理函数时,这个按键消息是IDOK if(threshsetdlg.DoModal()==IDOK) { //连起来看的一起是,显示一个模态对话框,当你按下确认按钮时,执行这里面的代码 }
DoModal 弹出模态对话框 ==IDOK判断模态对话框完成后的返值,如果是点击的ok返回,那么,执行if段的代码。