你的视GetDocument返回什么?
没有文档为什么要用视呢?

解决方案 »

  1.   

    我也想要
    我也需要在一个对话款中显示视图,因为在对话框上显示比较直观
    [email protected]
      

  2.   

    http://www.codeproject.com/docview/dfv.asp
    上面的例子就是往dialog中加视图
      

  3.   

    右两种方法实现。
    一种是直接在对话框中创建视图。
    还有一种是用子类化。先谈第一种:
    先在对话框中定义自己的视图对象
    MyView *m_pView;
    在对话框的CPP中
    CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)  //构造函数
    {
    m_pView = NULL;
    }
    void CAboutDlg::OnDestroy() 
    {
    if(m_pView)
    {
    m_pView->DestroyWindow();
    delete m_pView;
    }
    CDialog::OnDestroy();
    }
    BOOL CAboutDlg::OnInitDialog() 
    {
    CDialog::OnInitDialog(); CRect rect;
    GetClientRect(&rect);

    if(!m_pView)
    {
    m_pView = new MyView;
    m_pView->Create(NULL,NULL,WS_CHILD|WS_VISIBLE,rect,this,AFX_IDW_PANE_LAST);
    }
    return TRUE;
    }
    用这种方法需要重载视图类的PostNcDestroy和OnMouseActivate两个函数
    void MyView::PostNcDestroy() 
    {
    }
    int MyView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message) 
    {
    return MA_NOACTIVATE;
    }第二重方法是子类化:
    在对话框上放一个简单空间比如RECTANGLE,然后在对话框重定义视图的对象
    MyView *m_pView;
    在对话框的CPP中
    CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    m_pView = NULL;
    }
    BOOL CAboutDlg::OnInitDialog() 
    {
    CDialog::OnInitDialog();

    if(!m_pView)
    {
    m_pView = new MyView;
    m_pView->SubclassDlgItem(IDC_STATIC1,this);
    }

    return TRUE;
    }
    void CAboutDlg::OnDestroy() 
    {
    if(m_pView)
    {
    m_pView->UnsubclassWindow();
    delete m_pView;
    }
    CDialog::OnDestroy();
    }
    在视图中重载OnEraseBkgnd函数
    BOOL MyView::OnEraseBkgnd(CDC* pDC) 
    {
    CRect rect;
    CBrush Brush(RGB(255,255,255));
    GetClientRect(&rect);
    pDC->FillRect(&rect,&Brush);
    return TRUE;
    }
      

  4.   

    这个问题我曾经请教过,这是别人给的代码,很好用的。
    OnInitDialog()
    {
        CCreateContext ctx1;
        ctx1.m_pCurrentDoc = NULL;
        ctx1.m_pCurrentFrame = NULL;
        ctx1.m_pLastView = NULL;
        ctx1.m_pNewDocTemplate = NULL;
        ctx1.m_pNewViewClass = RUNTIME_CLASS(threadview2);
        threadview2 *m_pview = (threadview2 *)((CFrameWnd *)this)->CreateView(&ctx1);
        CRect rectClient;
        GetDlgItem(IDC_STATIC22)->GetClientRect(rectClient);
        GetDlgItem(IDC_STATIC22)->MapWindowPoints(this, rectClient);
        rectClient.DeflateRect(0,0);
        m_pview->MoveWindow(rectClient);
        m_pview->UpdateWindow();
    }
      

  5.   

    threadview2是你自己添加的视类,
    IDC_STATIC22是对话框上静态的文本,它的区域就是视图区的大小。
      

  6.   

    To ky640(exec):
        我只不过想用封装好的众多视图类而已。它们并不是只可以用在D/V结构中的。