选项卡控件的封装

1.新建默认MFC项目

2.添加资源Dialog,属性style改child,边框改none,添加类取名CMyDialog1;

同理,CMyDialog2;

3.类向导,添加MFC类-CTabCtrl类,取名CMyTabCtrl。

4.CMyTabCtrl类添加自定义封装函数


VOID CMyTabCtrl::InesrtTabColumn(int count, ...)
{
va_list valist;
va_start(valist, count);

for (int i = 0; i < count; ++i)
{
// 获取字符串类型的值
LPCWSTR Text = va_arg(valist, LPCWSTR);

// 添加到选项卡
InsertItem(i, Text);
}

va_end(valist);
}

// 创建窗口必须要[对象][id]
VOID CMyTabCtrl::InsertTabDialog(int count, ...)
{
va_list valist;
va_start(valist, count);

// 计算出需要移动的位置
CRect Rect;
GetClientRect(&Rect);
Rect.DeflateRect(17, 44, -9, -12);

for (int i = 0; i < count; ++i)
{
// 获取对话框
CDialog* Dlg = va_arg(valist, CDialog*);

// 获取资源的 id
UINT DlgId = va_arg(valist, UINT);
Dlg->Create(DlgId);

// 移动窗口
Dlg->MoveWindow(&Rect);

// 将对话框添加到容器中
DialogVec.push_back(Dlg);
}

ShowTabDialog(0);

va_end(valist);
}


VOID CMyTabCtrl::ShowTabDialog(int index)
{
for (int i = 0; i < DialogVec.size(); ++i)
{
if (i == index)
DialogVec[i]->ShowWindow(

相关文章:

  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
  • 2021-12-20
  • 2021-12-26
  • 2021-12-19
猜你喜欢
  • 2022-12-23
  • 2021-05-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2022-12-23
相关资源
相似解决方案