对话框类不允许我在对话框上与 CButton 交互?

Dialog Class doesn't let me interact with CButton on the dialog?

本文关键字:对话框 CButton 交互 不允许 允许我      更新时间:2023-10-16

如果我在myTab类中创建CButton,我就不能作为用户与它交互。

但是,如果我在Main CD对话框中"创建"了CButton,并将pParentWnd设置为dlgMine,那么我就可以与进行交互。

Thx

//Main CDialog
CDialog *dlgMine = new myTab(this);
dlgMine->Create(IDD_DIALOG1,this);
dlgMine->SetWindowPos(&wndTop, 20, 20, 300, 300, SWP_SHOWWINDOW);

myTab::myTab(CWnd* pParent /*=NULL*/)
    : CDialog(myTab::IDD, pParent)
{
    //{{AFX_DATA_INIT(myTab)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    CButton *btn = new CButton();
    btn->Create("Run", WS_BORDER|WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(40,40,100,100),this,10);
}

您不应该在对话框构造函数中创建按钮,因为对话框本身仍未创建。请改为在OnInitDialog中执行此操作。