我用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);
}
为什么仍然无效呢?不能获得输入焦点,好像不存在似的,错误在哪呢?
在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);
}
为什么仍然无效呢?不能获得输入焦点,好像不存在似的,错误在哪呢?
注意红字!
使用前要先用 AfxInitRichEdit 函数
{
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;
}
{
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(); 加上了,还是不好用啊