我有一个tabctrl,初始化的时候要显示第一个标签,可是对话框弹出来的时候看得见该标签对话框上的内容(各种控件)闪了一下界面就空白了,如果点到别的标签再回到这个标签,内容能显示,或者拿鼠标在空白区域里晃啊晃也会显示出来。放置tabctrl控件对话框的初始化函数如下:BOOL CDlgStructureAnlys::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_tabctrl.InsertItem(0,_T("圆角半径"));
m_tabctrl.InsertItem(1,_T("最小冲孔尺寸"));
m_tabctrl.InsertItem(2,_T("孔间/孔边距(平面)"));
m_tabctrl.InsertItem(3,_T("悬臂/凹槽"));
m_tabctrl.InsertItem(4,_T("弯曲边/孔边距"));
m_tabctrl.InsertItem(5,_T("弯曲半径"));
m_page1.Create(IDD_STRUCTPAGE1,GetDlgItem(IDC_TABCTRL));
m_page2.Create(IDD_STRUCTPAGE2,GetDlgItem(IDC_TABCTRL));
m_page3.Create(IDD_STRUCTPAGE3,GetDlgItem(IDC_TABCTRL));
m_page4.Create(IDD_STRUCTPAGE4,GetDlgItem(IDC_TABCTRL));
m_page5.Create(IDD_STRUCTPAGE5,GetDlgItem(IDC_TABCTRL));
m_page6.Create(IDD_STRUCTPAGE6,GetDlgItem(IDC_TABCTRL));/* m_page1.Create(IDD_STRUCTPAGE1,&m_tabctrl);
m_page2.Create(IDD_STRUCTPAGE2,&m_tabctrl);
m_page3.Create(IDD_STRUCTPAGE3,&m_tabctrl);
m_page4.Create(IDD_STRUCTPAGE4,&m_tabctrl);
m_page5.Create(IDD_STRUCTPAGE5,&m_tabctrl);
m_page6.Create(IDD_STRUCTPAGE6,&m_tabctrl);
*/
CRect rc;
m_tabctrl.GetClientRect(&rc);
rc.top += 41;
rc.bottom -= 3;
rc.left += 2;
rc.right -= 2; m_page1.MoveWindow(&rc);
m_page2.MoveWindow(&rc);
m_page3.MoveWindow(&rc);
m_page4.MoveWindow(&rc);
m_page5.MoveWindow(&rc);
m_page6.MoveWindow(&rc); m_page1.ShowWindow(FALSE);
m_page2.ShowWindow(FALSE);
m_page3.ShowWindow(FALSE);
m_page4.ShowWindow(FALSE);
m_page5.ShowWindow(FALSE);
m_page6.ShowWindow(TRUE); m_tabctrl.SetCurSel(5); pDialog[0] = &m_page1;
pDialog[1] = &m_page2;
pDialog[2] = &m_page3;
pDialog[3] = &m_page4;
pDialog[4] = &m_page5;
pDialog[5] = &m_page6;
/*
pDialog[0]->ShowWindow(SW_HIDE);
pDialog[1]->ShowWindow(SW_HIDE);
pDialog[2]->ShowWindow(SW_HIDE);
pDialog[3]->ShowWindow(SW_HIDE);
pDialog[4]->ShowWindow(SW_HIDE);
pDialog[5]->ShowWindow(SW_SHOW);
*/
m_CurSelTab = 5; return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}void CDlgStructureAnlys::OnSelchangeTabctrl(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
pDialog[m_CurSelTab]->ShowWindow(SW_HIDE);
m_CurSelTab=m_tabctrl.GetCurSel();
pDialog[m_CurSelTab]->ShowWindow(SW_SHOW);
*pResult = 0;
}
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_tabctrl.InsertItem(0,_T("圆角半径"));
m_tabctrl.InsertItem(1,_T("最小冲孔尺寸"));
m_tabctrl.InsertItem(2,_T("孔间/孔边距(平面)"));
m_tabctrl.InsertItem(3,_T("悬臂/凹槽"));
m_tabctrl.InsertItem(4,_T("弯曲边/孔边距"));
m_tabctrl.InsertItem(5,_T("弯曲半径"));
m_page1.Create(IDD_STRUCTPAGE1,GetDlgItem(IDC_TABCTRL));
m_page2.Create(IDD_STRUCTPAGE2,GetDlgItem(IDC_TABCTRL));
m_page3.Create(IDD_STRUCTPAGE3,GetDlgItem(IDC_TABCTRL));
m_page4.Create(IDD_STRUCTPAGE4,GetDlgItem(IDC_TABCTRL));
m_page5.Create(IDD_STRUCTPAGE5,GetDlgItem(IDC_TABCTRL));
m_page6.Create(IDD_STRUCTPAGE6,GetDlgItem(IDC_TABCTRL));/* m_page1.Create(IDD_STRUCTPAGE1,&m_tabctrl);
m_page2.Create(IDD_STRUCTPAGE2,&m_tabctrl);
m_page3.Create(IDD_STRUCTPAGE3,&m_tabctrl);
m_page4.Create(IDD_STRUCTPAGE4,&m_tabctrl);
m_page5.Create(IDD_STRUCTPAGE5,&m_tabctrl);
m_page6.Create(IDD_STRUCTPAGE6,&m_tabctrl);
*/
CRect rc;
m_tabctrl.GetClientRect(&rc);
rc.top += 41;
rc.bottom -= 3;
rc.left += 2;
rc.right -= 2; m_page1.MoveWindow(&rc);
m_page2.MoveWindow(&rc);
m_page3.MoveWindow(&rc);
m_page4.MoveWindow(&rc);
m_page5.MoveWindow(&rc);
m_page6.MoveWindow(&rc); m_page1.ShowWindow(FALSE);
m_page2.ShowWindow(FALSE);
m_page3.ShowWindow(FALSE);
m_page4.ShowWindow(FALSE);
m_page5.ShowWindow(FALSE);
m_page6.ShowWindow(TRUE); m_tabctrl.SetCurSel(5); pDialog[0] = &m_page1;
pDialog[1] = &m_page2;
pDialog[2] = &m_page3;
pDialog[3] = &m_page4;
pDialog[4] = &m_page5;
pDialog[5] = &m_page6;
/*
pDialog[0]->ShowWindow(SW_HIDE);
pDialog[1]->ShowWindow(SW_HIDE);
pDialog[2]->ShowWindow(SW_HIDE);
pDialog[3]->ShowWindow(SW_HIDE);
pDialog[4]->ShowWindow(SW_HIDE);
pDialog[5]->ShowWindow(SW_SHOW);
*/
m_CurSelTab = 5; return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}void CDlgStructureAnlys::OnSelchangeTabctrl(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
pDialog[m_CurSelTab]->ShowWindow(SW_HIDE);
m_CurSelTab=m_tabctrl.GetCurSel();
pDialog[m_CurSelTab]->ShowWindow(SW_SHOW);
*pResult = 0;
}
BOOL CDlgStructureAnlys::OnInitDialog()
{
CDialog::OnInitDialog(); // TODO: Add extra initialization here m_CurSelTab = -1;pDialog[0] = &m_page1;
pDialog[1] = &m_page2;
pDialog[2] = &m_page3;
pDialog[3] = &m_page4;
pDialog[4] = &m_page5;
pDialog[5] = &m_page6; m_page1.Create(IDD_STRUCTPAGE1,&m_tabctrl);
m_page2.Create(IDD_STRUCTPAGE2,&m_tabctrl);
m_page3.Create(IDD_STRUCTPAGE3,&m_tabctrl);
m_page4.Create(IDD_STRUCTPAGE4,&m_tabctrl);
m_page5.Create(IDD_STRUCTPAGE5,&m_tabctrl);
m_page6.Create(IDD_STRUCTPAGE6,&m_tabctrl); CRect rc;
m_tabctrl.GetClientRect(&rc);
m_tabctrl.ClientToScreen(&rc);
rc.top += 41;
rc.bottom -= 3;
rc.left += 2;
rc.right -= 2; m_page1.MoveWindow(&rc);
m_page2.MoveWindow(&rc);
m_page3.MoveWindow(&rc);
m_page4.MoveWindow(&rc);
m_page5.MoveWindow(&rc);
m_page6.MoveWindow(&rc); m_tabctrl.InsertItem(0,_T("圆角半径"));
m_tabctrl.InsertItem(1,_T("最小冲孔尺寸"));
m_tabctrl.InsertItem(2,_T("孔间/孔边距(平面)"));
m_tabctrl.InsertItem(3,_T("悬臂/凹槽"));
m_tabctrl.InsertItem(4,_T("弯曲边/孔边距"));
m_tabctrl.InsertItem(5,_T("弯曲半径")); m_tabctrl.SetCurSel(5); return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
} void CDlgStructureAnlys::OnSelchangeTabctrl(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
if (m_CurSelTab != -1)
pDialog[m_CurSelTab]->ShowWindow(SW_HIDE);
m_CurSelTab=m_tabctrl.GetCurSel();
pDialog[m_CurSelTab]->ShowWindow(SW_SHOW); *pResult = 0;
}
多了这一行反倒是什么都看不到了。
我有一点搞错了,SetCurSel不会引发TCN_SELCHANGE消息,所以还是要稍稍改一下。
m_tabctrl.SetCurSel(5);之后加上:
m_CurSelTab = 5;
pDialog[5]->ShowWindow(SW_SHOW);
另,按以前的写法,主对话框弹出后,貌似各标签对话框初始化函数都响应了(因为各初始化函数里面的afxmessagebox都有反应),不知是何原因。
BOOL CDlgStructureAnlys::OnInitDialog()
{
CDialog::OnInitDialog(); // TODO: Add extra initialization here m_CurSelTab = -1; pDialog[0] = &m_page1;
pDialog[1] = &m_page2;
pDialog[2] = &m_page3;
pDialog[3] = &m_page4;
pDialog[4] = &m_page5;
pDialog[5] = &m_page6; m_page1.Create(IDD_STRUCTPAGE1,&m_tabctrl);
m_page2.Create(IDD_STRUCTPAGE2,&m_tabctrl);
m_page3.Create(IDD_STRUCTPAGE3,&m_tabctrl);
m_page4.Create(IDD_STRUCTPAGE4,&m_tabctrl);
m_page5.Create(IDD_STRUCTPAGE5,&m_tabctrl);
m_page6.Create(IDD_STRUCTPAGE6,&m_tabctrl); CRect rc;
m_tabctrl.GetClientRect(&rc);
rc.top += 41;
rc.bottom -= 3;
rc.left += 2;
rc.right -= 2; m_page1.MoveWindow(&rc);
m_page2.MoveWindow(&rc);
m_page3.MoveWindow(&rc);
m_page4.MoveWindow(&rc);
m_page5.MoveWindow(&rc);
m_page6.MoveWindow(&rc); m_tabctrl.InsertItem(0,_T("圆角半径"));
m_tabctrl.InsertItem(1,_T("最小冲孔尺寸"));
m_tabctrl.InsertItem(2,_T("孔间/孔边距(平面)"));
m_tabctrl.InsertItem(3,_T("悬臂/凹槽"));
m_tabctrl.InsertItem(4,_T("弯曲边/孔边距"));
m_tabctrl.InsertItem(5,_T("弯曲半径")); m_tabctrl.SetCurSel(5);
m_CurSelTab = 5;
pDialog[5]->ShowWindow(SW_SHOW); return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
m_page1.ShowWindow(TRUE);//修改
m_page2.ShowWindow(FALSE);
m_page3.ShowWindow(FALSE);
m_page4.ShowWindow(FALSE);
m_page5.ShowWindow(FALSE);
m_page6.ShowWindow(FALSE);//修改m_tabctrl.SetCurSel(0);//修改 pDialog[0] = &m_page1;
pDialog[1] = &m_page2;
pDialog[2] = &m_page3;
pDialog[3] = &m_page4;
pDialog[4] = &m_page5;
pDialog[5] = &m_page6;
/*
pDialog[0]->ShowWindow(SW_HIDE);
pDialog[1]->ShowWindow(SW_HIDE);
pDialog[2]->ShowWindow(SW_HIDE);
pDialog[3]->ShowWindow(SW_HIDE);
pDialog[4]->ShowWindow(SW_HIDE);
pDialog[5]->ShowWindow(SW_SHOW);
*/
m_CurSelTab = 0;//修改
m_tab.GetClientRect(&rc);
rc.left+=1;
rc.top+=20; rc.right-=1;
rc.bottom-=2;
m_dlgFaultCfg.MoveWindow(&rc);
m_dlgFaultInfo.MoveWindow(&rc);
m_dlgExam.MoveWindow(&rc);
m_dlgFaultCfg.ShowWindow(SW_SHOW);
m_dlgFaultInfo.ShowWindow(SW_HIDE);
比如是m_dlgFaultCfg.ShowWindow(SW_SHOW) 在后面加一句m_dlgFaultCfg.SetFocus()
,你是没加这一句话吧。ClientToScreen 不要用这个 啊