我在Application中用CEditView,但发现有几个问题请各位解决一下:
1。我发现CEditView里面的文字可以让用户任意修改,如果我要这些文字只能读,而不能让用户任意删改,该怎么做?如果风格设为READONLY的话,整个CEdit Control都变成灰色了,我需要不改变View的显示风格,仍然是白底黑字。
2。由于有View/Doc关联,每次退出的时候,Application都会弹出个对话框,问是否需要保存。如果不需要弹出对话框,应该如何做?

解决方案 »

  1.   

    1.
    m_hbr = CreateSolidBrush(RGB(255, 255, 255));
    ......
    BEGIN_MESSAGE_MAP(CMyView, CEditView)
    //{{AFX_MSG_MAP(CMyView)
    ON_WM_CTLCOLOR()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()2.重载CDocument::SaveModified()
    HBRUSH CMyView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    CEditView::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
    pDC->SetBkColor(RGB(255, 255, 255));
    // TODO: Return a different brush if the default is not desired
    return m_hbr;
    }
      

  2.   

    1.
    m_hbr = CreateSolidBrush(RGB(255, 255, 255));
    ......
    BEGIN_MESSAGE_MAP(CMyView, CEditView)
    //{{AFX_MSG_MAP(CMyView)
    ON_WM_CTLCOLOR()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    HBRUSH CMyView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    CEditView::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
    pDC->SetBkColor(RGB(255, 255, 255));
    // TODO: Return a different brush if the default is not desired
    return m_hbr;
    }
    2.重载CDocument::SaveModified()
    BOOL CDocument::SaveModified()
    {
         return TRUE;
    }