MDI中,如何在对话框的CStatic中创建视图!
BOOL CMyDlg2::OnInitDialog() 
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
CCreateContext cc;
cc.m_pNewViewClass = RUNTIME_CLASS(CMyVIew);
cc.m_pCurrentDoc = NULL;
cc.m_pNewDocTemplate = NULL;
cc.m_pLastView = NULL;
cc.m_pCurrentFrame = NULL; 

m_pView = (CMyVIew*)theApp.CreateNewView(&cc, this, CRect(0, 0, 0, 0), 0);
if (m_pView == NULL)
EndDialog(IDCANCEL);

// place the View in the view rectangle
CRect rect;
CStatic *s = (CStatic*)GetDlgItem(IDC_STATIC_MAP2);
//GetDlgItem(IDC_MY_VIEW_RECT)->GetWindowRect(&rect);
s->GetWindowRect (&rect);
ScreenToClient(rect);
m_pView->MoveWindow(&rect);
s->ShowWindow(SW_HIDE); // Add by syx
return TRUE;  // return TRUE unless you set the focus to a control
              // EXCEPTION: OCX Property Pages should return FALSE
}我这样创建,出现viewcore.cpp的252行错误

解决方案 »

  1.   

    BOOL   CMyDlg2::OnInitDialog()   

    CDialog::OnInitDialog(); //   TODO:   Add   extra   initialization   here 
    //CCreateContext   cc; 
    //cc.m_pNewViewClass   =   RUNTIME_CLASS(CMyVIew); 
    //cc.m_pCurrentDoc   =   NULL; 
    //cc.m_pNewDocTemplate   =   NULL; 
    //cc.m_pLastView   =   NULL; 
    //cc.m_pCurrentFrame   =   NULL;   //m_pView   =   (CMyVIew*)theApp.CreateNewView(&cc,   this,   CRect(0,   0,   0,   0),   0); 
    //if   (m_pView   ==   NULL) 
    //EndDialog(IDCANCEL); 
    //m_pView直接创建
    m_pView->Create();
    //   place   the   View   in   the   view   rectangle 
    CRect   rect; 
    CStatic   *s   =   (CStatic*)GetDlgItem(IDC_STATIC_MAP2); 
    //GetDlgItem(IDC_MY_VIEW_RECT)-> GetWindowRect(&rect); 
    s-> GetWindowRect   (&rect); 
    ScreenToClient(rect); 
    m_pView-> MoveWindow(&rect); 
    s-> ShowWindow(SW_HIDE); //   Add   by   syx 
    return   TRUE;     //   return   TRUE   unless   you   set   the   focus   to   a   control 
                                //   EXCEPTION:   OCX   Property   Pages   should   return   FALSE 

      

  2.   

    error C2660: 'Create' : function does not take 0 parameters
      

  3.   

    晕,我是简写,参数要你自己填~~BOOL   CMyDlg2::OnInitDialog()   

    CDialog::OnInitDialog();  //   TODO:   Add   extra   initialization   here 
    //CCreateContext   cc; 
    //cc.m_pNewViewClass   =   RUNTIME_CLASS(CMyVIew); 
    //cc.m_pCurrentDoc   =   NULL; 
    //cc.m_pNewDocTemplate   =   NULL; 
    //cc.m_pLastView   =   NULL; 
    //cc.m_pCurrentFrame   =   NULL;    //m_pView   =   (CMyVIew*)theApp.CreateNewView(&cc,   this,   CRect(0,   0,   0,   0),   0); 
    //if   (m_pView   ==   NULL) 
    //EndDialog(IDCANCEL); 
    //m_pView直接创建
    CStatic   *s   =   (CStatic*)GetDlgItem(IDC_STATIC_MAP2); 
     m_pView=new CMyVIew;
    m_pView->Create(NULL,NULL,WS_CHILD|WS_VISIBLE,CRect(0,   0,   0,   0),s,0);
    //   place   the   View   in   the   view   rectangle 
    CRect   rect; 

    //GetDlgItem(IDC_MY_VIEW_RECT)-> GetWindowRect(&rect); 
    s-> GetWindowRect   (&rect); 
    ScreenToClient(rect); 
    m_pView-> MoveWindow(&rect); 
    //s-> ShowWindow(SW_HIDE); //   Add   by   syx 
    return   TRUE;     //   return   TRUE   unless   you   set   the   focus   to   a   control 
    //   EXCEPTION:   OCX   Property   Pages   should   return   FALSE 
    }