我在OnSize中改写IDC_TAB1是对话框中的tab control控件,m_tab是与之关联的变量,m_labe1、m_label2、m_label3是与属性页对话框关联的变量,我用F9调试到m_label1.MoveWindow(&m_rect);语句就出错了Debug Assertion Failed,怎么回事啊,请高手指点。
void CEDDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CWnd *pWnd;
pWnd = GetDlgItem(IDC_TAB1); //获取控件句柄
if(pWnd)//判断是否为空,因为对话框创建时会调用此函数,而当时控件还未创建
{
GetClientRect(&m_rect);
m_tab.MoveWindow(&m_rect);
m_tab.GetClientRect(&m_rect);
//调整子对话框在父窗口中的位置
m_rect.top+=20;
m_rect.bottom-=1;
m_rect.left+=1;
m_rect.right-=1;
//设置子对话框尺寸并移动到指定位置
m_label1.MoveWindow(&m_rect);
m_label2.MoveWindow(&m_rect);
m_label3.MoveWindow(&m_rect);
//分别设置隐藏和显示
m_label1.ShowWindow(true);
m_label2.ShowWindow(false);
m_label3.ShowWindow(false);
}
m_tab.SetCurSel(0);
}
}
void CEDDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CWnd *pWnd;
pWnd = GetDlgItem(IDC_TAB1); //获取控件句柄
if(pWnd)//判断是否为空,因为对话框创建时会调用此函数,而当时控件还未创建
{
GetClientRect(&m_rect);
m_tab.MoveWindow(&m_rect);
m_tab.GetClientRect(&m_rect);
//调整子对话框在父窗口中的位置
m_rect.top+=20;
m_rect.bottom-=1;
m_rect.left+=1;
m_rect.right-=1;
//设置子对话框尺寸并移动到指定位置
m_label1.MoveWindow(&m_rect);
m_label2.MoveWindow(&m_rect);
m_label3.MoveWindow(&m_rect);
//分别设置隐藏和显示
m_label1.ShowWindow(true);
m_label2.ShowWindow(false);
m_label3.ShowWindow(false);
}
m_tab.SetCurSel(0);
}
}
源文件里构造函数:
m_Create=FALSE;
源文件里初始函数,比如OnInitDialog()函数里
m_Create=TRUE;
在
void CEDDlg::OnSize(UINT nType, int cx, int cy)
{
if(!m_Create)//加这两句
return;//加这两句CDialog::OnSize(nType, cx, cy);//可以试试屏蔽这句,应该没问题// TODO: Add your message handler code here
CWnd *pWnd;
pWnd = GetDlgItem(IDC_TAB1); //获取控件句柄
if(pWnd)//判断是否为空,因为对话框创建时会调用此函数,而当时控件还未创建
.....
}
这是因为控件还没建立就执行OnSize函数了
m_sheet.AddPage(&m_pg1);
m_sheet.AddPage(&m_pg2); m_sheet.Create(this, WS_CHILD , WS_EX_CONTROLPARENT); m_sheet.SetActivePage(1);
m_sheet.SetActivePage(0); CRect rectPos;
CStatic* pPos = (CStatic*)this->GetDlgItem(IDC_STATIC_POSITION);
pPos->GetWindowRect(rectPos);
CPoint a(rectPos.left, rectPos.top);
ScreenToClient(&a);
m_sheet.SetWindowPos(NULL, a.x, a.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
m_sheet.ShowWindow(SW_SHOW);