-1

如果我在 myTab 类中创建 CButton,我无法以用户身份与其交互。

但是,如果我在 Main CDialog 中“创建”CButton 并将 pParentWnd 设置为 dlgMine,那么我可以与之交互。

谢谢

//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);
}
4

1 回答 1

2

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

于 2012-04-05T06:44:41.860 回答