问题描述
我想在CScrollView派生的类上具有2组选项卡,因此我将2个CMFCTabCtrs并排放置.选项卡控件充满了对话框(当前是同一类,但出于测试目的,对象不同,以后每个选项卡控件的对话框也不同).
问题是控件本身按需要彼此并排放置.第二个选项卡控件中的选项卡或对话框出现在第一个选项卡控件的区域中,因此与之重叠.
左边对话框上方图片中的(当前用于测试的最低要求)实际上属于右边的控件.标签内的对话框是视图的子级.
对话框的资源:
IDD_COMBATANTDLG DIALOGEX 0, 0, 320, 331
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VISIBLE
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
GROUPBOX "Flotte",IDC_STATIC,19,18,192,175,BS_FLAT
LTEXT "Static",IDC_STATIC,91,94,19,8
EDITTEXT IDC_EDIT1,136,118,40,14,ES_AUTOHSCROLL
END
声明:
class SimDataInput : public CScrollView
{
protected: // create from serialization only
SimDataInput();
DECLARE_DYNCREATE(SimDataInput)
// Attributes
private:
CMFCTabCtrl combatant_tabs[2];//tabs
std::vector<CombatantDlg*> p2combatdlg[2];//stores pointers to dialog
const CStringW attdef[2] = { L"Angreifer ", L"Verteidiger " };//standard labels for respective tab controls
............
来自OnInitialUpdate():
void SimDataInput::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
for (auto i = 0; i < 2;i++)
{
CStringW label ( attdef[i]);
RECT pos = RECT{ i * 400, 0, 400 + i * 400, 500 };
combatant_tabs[i].Create(CMFCTabCtrl::STYLE_3D, pos, this,10000+i, CMFCTabCtrl::LOCATION_TOP,TRUE);//create tab
combatant_tabs[i].EnableTabSwap(FALSE);
combatant_tabs[i].EnableActiveTabCloseButton();
//combatant_tabs[sim::ATT].EnableTabDocumentsMenu(TRUE);
p2combatdlg[i].reserve(16);
p2combatdlg[i].emplace_back();//create pointer
p2combatdlg[i].back() = new CombatantDlg(this);//initialize pointer to the new dialog
p2combatdlg[i].back()->Create(IDD_COMBATANTDLG, this);//create dialog
//p2combatdlg[i].back()->SetWindowPos(&combatant_tabs[i], 400, 0, 0, 0, SWP_NOZORDER | SWP_SHOWWINDOW);//tried this -doesn't help
label.AppendFormat(L"%d",1);
combatant_tabs[i].InsertTab(p2combatdlg[i].back(),label , 0, -1, FALSE);//insert the first tab
}
.......下一个功能会在按下相应按钮后插入新标签页
void SimDataInput::OnCombatant(UINT nID)//used by ON_COMMAND_RANGE for both tab controls
{
nID -= ID_ATTACKER;
if (combatant_tabs[nID].GetTabsNum() == 16)
return;
CStringW label ( attdef[nID]);
p2combatdlg[nID].emplace_back();
label.AppendFormat(L"%d", p2combatdlg[nID].size());
p2combatdlg[nID].back() = new CombatantDlg(this);
p2combatdlg[nID].back()->Create(IDD_COMBATANTDLG, this);
combatant_tabs[nID].InsertTab(p2combatdlg[nID].back(), label , combatant_tabs[nID].GetTabsNum(), -1, FALSE);
combatant_tabs[nID].SetActiveTab(combatant_tabs[nID].GetTabsNum() - 1);
// TODO: Add your command handler code here
}
毕竟,使CMFCTabCtrls成为所包含对话框的父母可以纠正此行为.我必须将指向以前父母的指针存储在对话框中,以使访问更容易
I've would like to have 2 sets of tabs on my CScrollView -derived class, so I put 2 CMFCTabCtrs side by side. The tab controls are filled with dialogs (currently same class, but different objects for test purpose, later different dialogs for each tab control).
The problem is while the controls themselves are placed besides each other as desired. the tabs or dialogs from the second tab control appear in area of the first tab controls, thus overlapping with it.
on the picture above the dialog on the left (currently minimalistic for testing) actually belongs to the control on the right. the dialogs inside of tab are childs of the view.
Resource of the dialog:
IDD_COMBATANTDLG DIALOGEX 0, 0, 320, 331
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VISIBLE
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
GROUPBOX "Flotte",IDC_STATIC,19,18,192,175,BS_FLAT
LTEXT "Static",IDC_STATIC,91,94,19,8
EDITTEXT IDC_EDIT1,136,118,40,14,ES_AUTOHSCROLL
END
declarations:
class SimDataInput : public CScrollView
{
protected: // create from serialization only
SimDataInput();
DECLARE_DYNCREATE(SimDataInput)
// Attributes
private:
CMFCTabCtrl combatant_tabs[2];//tabs
std::vector<CombatantDlg*> p2combatdlg[2];//stores pointers to dialog
const CStringW attdef[2] = { L"Angreifer ", L"Verteidiger " };//standard labels for respective tab controls
............
from OnInitialUpdate():
void SimDataInput::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
for (auto i = 0; i < 2;i++)
{
CStringW label ( attdef[i]);
RECT pos = RECT{ i * 400, 0, 400 + i * 400, 500 };
combatant_tabs[i].Create(CMFCTabCtrl::STYLE_3D, pos, this,10000+i, CMFCTabCtrl::LOCATION_TOP,TRUE);//create tab
combatant_tabs[i].EnableTabSwap(FALSE);
combatant_tabs[i].EnableActiveTabCloseButton();
//combatant_tabs[sim::ATT].EnableTabDocumentsMenu(TRUE);
p2combatdlg[i].reserve(16);
p2combatdlg[i].emplace_back();//create pointer
p2combatdlg[i].back() = new CombatantDlg(this);//initialize pointer to the new dialog
p2combatdlg[i].back()->Create(IDD_COMBATANTDLG, this);//create dialog
//p2combatdlg[i].back()->SetWindowPos(&combatant_tabs[i], 400, 0, 0, 0, SWP_NOZORDER | SWP_SHOWWINDOW);//tried this -doesn't help
label.AppendFormat(L"%d",1);
combatant_tabs[i].InsertTab(p2combatdlg[i].back(),label , 0, -1, FALSE);//insert the first tab
}
.......next function inserts new tabs after pushing respective button
void SimDataInput::OnCombatant(UINT nID)//used by ON_COMMAND_RANGE for both tab controls
{
nID -= ID_ATTACKER;
if (combatant_tabs[nID].GetTabsNum() == 16)
return;
CStringW label ( attdef[nID]);
p2combatdlg[nID].emplace_back();
label.AppendFormat(L"%d", p2combatdlg[nID].size());
p2combatdlg[nID].back() = new CombatantDlg(this);
p2combatdlg[nID].back()->Create(IDD_COMBATANTDLG, this);
combatant_tabs[nID].InsertTab(p2combatdlg[nID].back(), label , combatant_tabs[nID].GetTabsNum(), -1, FALSE);
combatant_tabs[nID].SetActiveTab(combatant_tabs[nID].GetTabsNum() - 1);
// TODO: Add your command handler code here
}
After all, making the CMFCTabCtrls parents to the contained dialog corrected the behaviour. I had to store the pointer to the former parentsd insidethe dialogs to make the access easier
这篇关于2个CMFCTabControls处于不同位置,但选项卡位于同一位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!