我创建了一个单文档视图的应用程序,视类选择了CFormView,我在上面添加了一个按钮,一个编辑框,还有列表框,我想在发生窗口重绘时这些控件的相对位置、大小不变。在只有按钮和编辑框的时候,重绘正常,加入列表框后,重绘就会出问题。比如想去掉工具栏,点击查看,去掉工具栏前的对勾后,工具栏,状态栏还有我添加的控件都消失,只有再点击一下查看或者帮助等子菜单后,这些控件才能显示。若想再恢复工具栏,也是同样情况,不能立即显示这些控件。代码如下:
void CTest2View::OnPaint() 
{
CPaintDC dc(this); // device context for painting

// TODO: Add your message handler code here

CRect rect(0,0,0,0);
GetClientRect(rect);
rect.left = rect.right - 26;
rect.top = rect.bottom - 26;

//计算EditBox的坐标
int ed_top = rect.top;
int ed_width = rect.left ;
int ed_hight = rect.bottom - ed_top;

//计算ListBox的坐标
int lst_top = rect.top - 70;
int lst_width = rect.right;
int lst_hight = 70;

m_btn1.MoveWindow(rect);
m_edit1.MoveWindow(0,ed_top,ed_width,ed_hight);
m_list1.MoveWindow(0,lst_top,lst_width,lst_hight); // Do not call CFormView::OnPaint() for painting messages
}