CRichEditCtrl随父窗口改变大小

在头文件中添加

afx_msg void OnSize(UINT nType, int cx, int cy);

在cpp文件中添加

BEGIN_MESSAGE_MAP(CCommandView, CScrollView)
 //{{AFX_MSG_MAP(CCommandView)
 ON_WM_DESTROY()
 ON_WM_KEYDOWN()
 ON_WM_SIZE()
 ON_MESSAGE(WM_MY_MESSAGE, GetEditMsg)
// ON_REGISTERED_MESSAGE(WM_MY_MESSAGE, GetEditMsg) //定义消息映射

 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CCommandView::OnInitialUpdate()
{
 CScrollView::OnInitialUpdate();
 ::AfxInitRichEdit2();

 //m_TransmitLogsArray.Add("this is log.");

 SetScrollSizes(MM_TEXT, CSize(0, 0));

 
 GetClientRect(&m_rect);

 m_InputCmdEdit = new CEditComm();
 m_EditView = new CRichEditCtrlEx();

 m_InputCmdEdit->Create(WS_CHILD | WS_VISIBLE | WS_BORDER , CRect(0, 0, 5000, 23 ), this, WM_USER+1);
 
 /*m_EditView->Create(WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_HSCROLL | WS_VSCROLL| WS_TABSTOP | WS_BORDER,
  CRect(0, 25, m_rect.left+m_rect.Width() + 1000, m_rect.top+m_rect.Height()), this, WM_USER+2);*/
 m_EditView->Create(WS_VISIBLE|WS_CHILD|WS_CLIPCHILDREN|ES_WANTRETURN|ES_MULTILINE|WS_VSCROLL|ES_READONLY | WS_BORDER,
  CRect(m_rect.left, m_rect.top+25, m_rect.left+m_rect.Width() + 1000, m_rect.top+m_rect.Height()), this, WM_USER+2);

}

void CCommandView::OnSize(UINT nType, int cx, int cy)
{
 if (nType == SIZE_MINIMIZED)
  return;  //最小化什么也不做

 if (m_EditView && m_EditView->GetSafeHwnd() != NULL)
 {
  CRect rect;
  GetWindowRect(&rect);
  ScreenToClient(&rect);
  rect.DeflateRect(0, 25, 0, 0);

  m_EditView->MoveWindow(rect);
  
 }
 GetClientRect(&m_rect);
}


 

你可能感兴趣的:(MFC)