我现在想动态地create一个对话框,如果在View中create是可以的,但是感觉很不别扭,现在我在InitInstance()中仅仅生成一个框架,也就是使:
cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;这样只有一个空的框架了,我要在这个框架中create一个Dialog,发现不行,有没有办法呀?
我是这样create的:
m_pMyDlg->Create(NULL,WS_CHILD|WS_VISIBLE,rect,this,1);是不是这个this有问题呀,应该用什么呀,也就是父窗口的问题,请高手指点。
解决马上给分。

解决方案 »

  1.   

    你是m_pMyDlg是什么类型,CDialog的Create是不这样的
      

  2.   

    其实我这个m_pMyDlg是一个有界面的控件。
    我当然不是在InitInstance()中create的,我是在一个消息函数中create的
    但是对应的menu是灰的,不能响应消息。还是你说怎么把主窗口作为它的
    父窗口呀,参数怎么给呀,不妨赐教。偶的VC很不行呀。
      

  3.   

    参考下面,是不是有帮助:#include "stdafx.h"#define IDD_DIALOG1                     129
    /////////////////////////////////////////////////////////////////////////////
    // CMyDlg dialogclass CMyDlg : public CDialog
    {
    public:
    CMyDlg(CWnd* pParent = NULL); enum { IDD = IDD_DIALOG1 }; DECLARE_MESSAGE_MAP()
    };CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CMyDlg::IDD, pParent)
    {
    }BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMfcDlgAppclass CMfcDlgApp : public CWinApp
    {
    public:
    CMfcDlgApp();public:
    virtual BOOL InitInstance(); DECLARE_MESSAGE_MAP()
    };BEGIN_MESSAGE_MAP(CMfcDlgApp, CWinApp)
    ON_COMMAND(ID_HELP, CWinApp::OnHelp)
    END_MESSAGE_MAP()CMfcDlgApp::CMfcDlgApp()
    {
    }CMfcDlgApp theApp;BOOL CMfcDlgApp::InitInstance()
    {
    CMyDlg dlg;
    m_pMainWnd = &dlg;
    dlg.DoModal();
    return FALSE;
    }
      

  4.   

    int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
    return -1;
    //pPage是你的对话框指针 
              pPage = new CMyDialog;
    if(!pPage->Create(CMyDialog::IDD,this))
    return FALSE;
    CRect re;
    GetClientRect(&re);
    pPage->MoveWindow(&re);
    return true;
    }//加上下面的,处理命令
    void CChildFrame::OnSetFocus(CWnd* pOldWnd) 
    {
    CMDIChildWnd::OnSetFocus(pOldWnd);
    if (m_pPage.m_hWnd)
    m_pPage->SetFocus();
    }
    //
    void CChildFrame::OnSize(UINT nType, int cx, int cy)
    {
    CWnd::OnSize(nType, cx, cy); if (m_pPage.m_hWnd)
    m_pPage->MoveWindow(0,0,cx,cy);
    }
      

  5.   


    #include <afxwin.h>// 说明应用程序类
    class CHelloApp : public CWinApp
    {
       public:
          virtual BOOL InitInstance();
    };// 建立应用程序类的实例
    CHelloApp HelloApp;// 说明主窗口类
    class CHelloWindow : public CFrameWnd
    {
        CStatic* cs;
        public:
            CHelloWindow();
    };// 每当应用程序首次执行时都要调用的初始化函数
    BOOL CHelloApp::InitInstance()
    {
        m_pMainWnd = new CHelloWindow();
        m_pMainWnd->ShowWindow(m_nCmdShow);
        m_pMainWnd->UpdateWindow();
        return TRUE;
    }// 窗口类的构造函数
    CHelloWindow::CHelloWindow()
    {
        // 建立窗口本身
        Create(NULL, 
               "Hello World!", 
               WS_OVERLAPPEDWINDOW, 
               CRect(0,0,200,200));    // 建立静态标签
        cs = new CStatic();
        cs->Create("hello world",
                   WS_CHILD|WS_VISIBLE|SS_CENTER,
                   CRect(50,80,150,150),
                   this);
    }
      

  6.   

    但是对应的menu是灰的,不能响应消息这个问题我遇到过,我在CMainFrame写的菜单消息,在工具条里的树空件
    弹出OnContextMenul里这么写
    CMenu menu;
    menu.LoadMenu(IDR_MAINFRAME);
    menu.GetSubMenu(2)->TrackPopupMenu(TPM_CENTERALIGN,point.x,point.y,AfxGetMainWnd());
    第一个问题我没做过但我想在CMainFrame的OnCreate()里create()肯定好用
    我create()过树控件TAB