在模态对话框上不显示控件 [英] Not display controls on the modaless dialog

查看:151
本文介绍了在模态对话框上不显示控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

我建立了一个默认的对话框项目,并添加了一个对话框,当用户按下确定"按钮时将显示该对话框.
IDD_DIALOG1具有一些按钮和编辑框的控件,但是如果创建模态对话框如下,则它不显示按钮和编辑框:
如果有人知道原因,请给我建议.

Dear,

I built a default dialog project and added one more dialog to display when user presses OK button.
IDD_DIALOG1 has a few controls as button and editbox but it does not display the button and editbox if create modaless dialog as follow:
If somebody know why, please advice me.

void CTestDlg::OnOK()
{
   CDlgTest *dlg;

   dlg = new CDlgTest(this);
   dlg->Create(IDD_DIALOG1, this );
   dlg->ShowWindow(SW_SHOW);
   Sleep(10000);
   dlg->DestroyWindwo();
   delete dlg;
}

推荐答案

一个对话框需要一个对话框过程,在其中处理消息以绘制其子控件.在MFC中,这是由对话框类处理的. 您创建的方式是将其包装起来,并在休眠一段时间后立即将其销毁.
您没有给MFC绘制控件的机会.

您要做的是将对话框类指针创建为父类的成员.
您还需要从OnOK函数中删除对话框的破坏.
这必须在子对话框中进行.
A dialog box needs a dialog procedure in which it processes message to draw its child controls. In MFC this is handled by the dialog class.
The way you''re creating is to crate it and immediately destroy it after sleeping for some time.
You''re not giving MFC a chance to draw the controls.

What you have to do is to create the dialog class pointer as a member of the parent class.
You will also need to remove the destruction of the dialog from the OnOK function.
This must happen from within the child dialog.


这篇关于在模态对话框上不显示控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆