我用Appwizard生成一个View是派生于CView的多文档程序,在其中修改如下:
在CMyview中加入:   
  public:   
          CRichEditCtrl   m_rich;   
  再加入以下代码:   
  int   CMyview::Oncreate(LPCREATESTRUCT   lpCreateStruct)   
  {   
          CRect   rect(0,   0,   0,   0);   
          if   (CView::OnCreate(lpCreateStruct)   ==   -1)   
                  return   -1;   
          m_rich.Create(ES_AUTOVSCROLL   |   ES_MULTILINE   |   ES_WANTRETURN   |   
                                      WS_CHILD   |   WS_VISIBLE   |   WS_VSCROLL,   rect,   this,   1);   
    
          return   0;   
  }   
    
      以及:   
  void   CMyview::OnSize(UINT   nType,   int   cx,   int   cy)   
  {   
          CRect   rect;   
          CView::OnSize(nType,   cx,   cy);   
          GetClientRect(rect);   
          m_rich.SetWindowPos(&wndTop,   0,   0,   rect.right   -   rect.left,   
                                                  rect.bottom   -   rect.top,   SWP_SHOWWINDOW);   
  }   
为什么仍然无效呢?不能获得输入焦点,好像不存在似的,错误在哪呢?

解决方案 »

  1.   

    If you are using a rich edit control in a dialog box (regardless whether your application is SDI, MDI, or dialog-based), you must call AfxInitRichEdit once before the dialog box is displayed. A typical place to call this function is in your program's InitInstance member function. You do not need to call it for each time you display the dialog box, only the first time. You do not have to call AfxInitRichEdit if you are working with CRichEditView.
    注意红字!
    使用前要先用 AfxInitRichEdit 函数
      

  2.   

    回楼上,我加在OnCreate里面了还是不行啊int CMyView::OnCreate(LPCREATESTRUCT  lpCreateStruct)
    {
    CRect rect(0,0,0,0);
    if(CView::OnCreate(lpCreateStruct)==-1)
    return -1;
    m_rich.Create(ES_AUTOVSCROLL|ES_MULTILINE|ES_WANTRETURN|WS_CHILD|WS_VISIBLE|WS_VSCROLL, rect,this,idcedit);  
    AfxInitRichEdit();
    return 0;
    }
      

  3.   

    BOOL CMyApp::InitInstance()
    {
    AfxEnableControlContainer();

    AfxInitRichEdit();
    // Standard initialization
    // If you are not using these features and wish to reduce the size
    //  of your final executable, you should remove from the following
    //  the specific initialization routines you do not need.#ifdef _AFXDLL
    Enable3dControls(); 加上了,还是不好用啊