如何在MFC中显示和隐藏选项卡控件
问题描述:
我想显示和隐藏changeTab上的控件.
我在尝试..
在头文件中
I want to show and hide the controls on changeTab.
I am trying..
In header file
struct ITEM
{
//HWND h;
CWnd* wnd; //our control
int nID;
int iTab; //which tab it belongs to
BOOL bTabStop; //does this control allow tabstop
};
在C ++文件中
In c++ file
m_cTab.InsertItem(0,"Register new user");
m_cTab.InsertItem(1,"Identify fingerprints");
void CMyTabCtrl::ShowTab(int iTab)
{
iCtrl = -1;//reset any control which may be selected in a tab
if(iCurrentTab == iTab)//already focused on selected tab
{
return;
}
//save old tab location so we can hide its controls
int iOldTab = iCurrentTab;
iCurrentTab = iTab;
//check if tab is in focus, if not, put it in focus
int t = GetCurFocus();
if(iTab != t)
{
SetCurSel(iTab);
}
//hide old tabs controls, show the selected tab's controls
INT_PTR iCount = obArray.GetCount();
for(INT_PTR i=0; i<iCount; i++)
{
ITEM* pItem = (ITEM*)obArray[i];
if(pItem->iTab == iOldTab)
{
pItem->wnd->ShowWindow(SW_HIDE);
}
else if(pItem->iTab == iCurrentTab)
{
pItem->wnd->ShowWindow(SW_SHOW);
}
}
}
当我单击Tab 1时,即iTab = 1,它显示Tab 1项,但隐藏Tab 0项.
When I click Tab 1 i.e. iTab=1,It shows Tab 1 item but does hide Tab 0 items.
答
最简单的方法是为每个标签页创建一个无边界的对话框.在需要的地方创建并放置它们,然后在"ShowTab"函数中显示/隐藏它们.
The easiest way to do what your trying to do would be to create a borderless dialog for each tab page. Create and place them where they need to be and then show/hide them in your "ShowTab" function.
使用cpropertpage和cmfcpropertysheet
use cpropertpage and cmfcpropertysheet