转:http://happyboy200032.blog.163.com/blog/static/46903113201242101247838/
由于在CFormView类中的初始化和CDialog类的初始化的不同(CFormView类初始化时相应的控件好像还没创建),因此不能简 单的在onsize函数中添加 UPDATE_EASYSIZE宏,所以在onsize中需要判断是否是第一次调用onsize函数,然后再做相应的处理,好了,话不多说,上代码:
void CMyView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
if (m_bFirst && IsWindowVisible()&& GetWindow(GW_CHILD)!=NULL)
{
INIT_EASYSIZE;
m_bFirst = FALSE;
SetScrollSizes(MM_TEXT,CSize(0,0));
UPDATE_EASYSIZE;
}else if (!m_bFirst){
SetScrollSizes(MM_TEXT,CSize(0,0));
UPDATE_EASYSIZE;
}
}
然 后 Ali Rafiee说,还要将easysize.h文件中最后一句 GetDlgItem(id)->MoveWindow(left,top,right-left,bottom-top,FALSE);/改成 GetDlgItem(id)->MoveWindow(left,top,right-left,bottom-top,TRUE);/ ,其他地方不变,这样,在CFormView类中使用easysize也可以正常的展示了。
原文:
I found a solution for the form view problem (and it's working great for me). The problem is that when OnInitalUpdate gets called the form (eventhough created) has a width and height of zero. So what I did was put an if statment in the OnSize where the first time around I call INIT_EASYSIZE, and from there on I call UPDATE_EASYSIZE. Also you have to call SetScrollSizes(MM_TEXT,0,0) in order to get rid of the scrollbars.
void CMyView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
if (m_bFirst && IsWindowVisible()&& GetWindow(GW_CHILD)!=NULL)
{
INIT_EASYSIZE;
m_bFirst = FALSE;
SetScrollSizes(MM_TEXT,CSize(0,0));
UPDATE_EASYSIZE;
}else if (!m_bFirst){
SetScrollSizes(MM_TEXT,CSize(0,0));
UPDATE_EASYSIZE;
}
}
Hope this helps.
Ali Rafiee
I forgot to add that I also had to change the last line in Easysize.h from
GetDlgItem(id)->MoveWindow(left,top,right-left,bottom-top,FALSE);\
to
GetDlgItem(id)->MoveWindow(left,top,right-left,bottom-top,TRUE);\
So that the controls get redrawn correctly during the sizing
Ali Rafiee