大侠们:我想把原先的弹出的对话框内嵌到CWnd中,这样就可以不弹出对话框,效果看起来是直接在CWnd中显示的,请问用什么方法可以做到,二者创建是如何联系的,万分感谢,感谢!!

解决方案 »

  1.   

    Dialog需要改成child的类型的,
    然后通过create创建。
      

  2.   

    新建单文档或多文档项目时,在MFC AppWizard中点Next,第6步中将Base class选为CFormView,默认为CView,点完成就可以了。
      

  3.   

    对话框也是一个窗口
    CDialog* pDlg = new CDialog();
    pDlg->Create(IDD,this);
    pDlg->MoveWindow(...);
      

  4.   

    谢谢楼上面大哥们 请问是在CWnd中掉用 在什么地方掉用啊?
    CDialog* pDlg = new CDialog();
    pDlg->Create(IDD,this);
    pDlg->MoveWindow(...);谢谢!!大哥
      

  5.   

    依据你的需要了,一般在OnCreate里面调用。
      

  6.   

    我写的extern "C" _declspec(dllexport) bool ShowLineOnSamePoleDialog(CDictionary *pGlo,CDictionary *pLocal = NULL)
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    InitGlobalVar(pGlo); CWnd *pParent = (CWnd *)(UINT)(*pLocal)["DEVICETAB"].AsInt();

    CLineOnSamePoleDlg *dlg = new CLineOnSamePoleDlg;
    CRect rect;
    pParent->GetClientRect(&rect);

    dlg->Create(IDD_DLGLINEONSAMEPOLE);
    // dlg->AddEquipList(EquipCodeList, ChangeNumList);
    DWORD style = dlg->GetStyle();
    dlg->ModifyStyle(style,WS_CHILD|WS_VISIBLE,1);


    dlg->SetParent(pParent);
    dlg->MoveWindow(&rect);
    dlg->Invalidate(true);

    pLocal->At("LocalWindow").SetInt((UINT)dlg);
    // CLineOnSamePoleDlg lineOnSamePoleDlg;
    // lineOnSamePoleDlg.DoModal(); return true;
    }
      

  7.   

    谢谢各位大哥的热心帮助 ,我按到上面的提示 写的如下,但是有点问题哦: 帮帮忙看看 谢谢
    ///////////////////////////////////////
    //   ChildView.h
    //
    //////////////////////////////////////
    class CChildView : public CWnd
    {
    // Construction
    public:
    CChildView();// Attributespublic:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CChildView)
    protected:
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    //}}AFX_VIRTUAL// Implementation
    public:

    void ViewBase();
    virtual ~CChildView();protected:
    InfoDialog* info_dlg;        // 申明要嵌进去的对话框Dialog
    // Generated message map functions
    protected:
    //{{AFX_MSG(CChildView)
    afx_msg void OnPaint();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif ///////////////////////////////////////////////////////////////
    // CChildView.cpp
    //
    ////////////////////////////////////////////////////////////
    #include "MainFrm.h"
    #include "InfoDialog.h"
      .......CChildView::CChildView()
    {
    info_dlg = NULL;
    }CChildView::~CChildView()
    {
    }
    BEGIN_MESSAGE_MAP(CChildView,CWnd )
    //{{AFX_MSG_MAP(CChildView)
    ON_WM_PAINT()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    /////////////////////////////////////////////////////////////////////////////
    // CChildView message handlersBOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
    {
    if (!CWnd::PreCreateWindow(cs))
    return FALSE; cs.dwExStyle |= WS_EX_CLIENTEDGE;
    cs.style &= ~WS_BORDER;
    cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
    ::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL); return TRUE;
    }void CChildView::OnPaint() 
    {
    CPaintDC dc(this);
    CMainFrame *pFrame = (CMainFrame *)AfxGetApp()->m_pMainWnd;
    dc.TextOut(1, 1, pFrame->GetInfo());

    }
    //****************************************
    //别的方法调用ViewBase()   即产生窗口放在CWnd中
    //***************************************
    void CChildView::ViewBase()      
    {
    if (info_dlg != NULL)
    info_dlg->SetFocus();
      else {
      CRect rc;

    info_dlg = new InfoDialog;

    info_dlg->Create (IDD_PROPPAGE_MEDIUM,this);
    info_dlg->ShowWindow (SW_SHOW);
       GetClientRect(&rc);
      info_dlg->MoveWindow(&rc);
    info_dlg->DoModal();
      delete info_dlg;
       }
    }有点问题 望大哥们指点,跪谢 跪谢!!!!
      

  8.   

    你说的功能是嵌入使用,按二楼的做法就对了,除非你想使用CView的某些功能新建单文档或多文档项目时,在MFC AppWizard中点Next,第6步中将Base class选为CFormView,默认为CView,点完成就可以了。
      

  9.   

    谢谢 楼上讲的我知道啊,但我想知道的是把原先的弹出的对话框Dialog内嵌到CWnd中,这样就可以不弹出对话框,效果看起来是直接在CWnd中显示的 即能不能不能把Dialog放到CWnd中呢 我上面也写了代码 但有点问题  希望大哥们 帮忙看看谢谢!!!跪谢 跪谢!!
      

  10.   

    void CChildView::ViewBase()      
    {
    if (info_dlg != NULL)
    info_dlg->SetFocus();
     else {
     CRect rc;info_dlg = new InfoDialog;info_dlg->Create (IDD_PROPPAGE_MEDIUM,this);
    info_dlg->ShowWindow (SW_SHOW);
    //--------------------
    DWORD style = dlg->GetStyle();//这一句和下面一句是去除模态,否则有点问题
    dlg->ModifyStyle(style,WS_CHILD|WS_VISIBLE,1);
    dlg->SetParent(pParent);//这一句最好加上
    //----------------------------
      GetClientRect(&rc);
     info_dlg->MoveWindow(&rc);
    info_dlg->DoModal();
     delete info_dlg;
      }这样应该就OK了,你再试试