博客
关于我
MFC之标签控件26
阅读量:241 次
发布时间:2019-03-01

本文共 2107 字,大约阅读时间需要 7 分钟。

为了实现基于对话框的TabControl项目,按照以下步骤操作:

  • 创建基于对话框的MFC项目。

  • 在主窗口对话框的窗口中添加CTabCtrl控件,可以使用类定位:

    CTabCtrl m_tabCtrl;m_tabCtrl.Create(nullptr, NULL, WS_TABCONTROL | WS_VISIBLE | WS_DISABLED, 0);

    将CTabCtrl添加到主窗口的对话框中。

  • 创建并实现CTabSheet类,继承自CTabCtrl,添加必要的成员变量和方法:

    class CTabSheet : public CTabCtrl {private:    int m_nNumOfPages;    int m_nCurrentPage;    CDialog** m_pPages;    UINT* m_IDD;    LPCTSTR* m_Title;public:    CTabSheet() { m_nNumOfPages = 0; m_nCurrentPage = 0; }    ~CTabSheet() {}};
  • 实现CTabSheet的关键方法:

    bool CTabSheet::AddPage(LPCTSTR title, CDialog* pDialog, UINT ID) {    if (m_nNumOfPages >= MAXPAGE) return FALSE;    m_nNumOfPages++;    m_pPages[m_nNumOfPages - 1] = pDialog;    m_IDD[m_nNumOfPages - 1] = ID;    m_Title[m_nNumOfPages - 1] = title;    return TRUE;}void CTabSheet::Show() {    int i = 0;    for (; i < m_nNumOfPages; ++i) {        if (AfxGetMainWnd()) {            InsertItem(i, m_Title[i]);        } else {            return;        }    }    for (; i < m_nNumOfPages; ++i) {        m_pPages[i]->ShowWindow(SW_HIDE);    }    m_pPages[0]->ShowWindow(SW_SHOW);    SetRect();}void CTabSheet::SetRect() {    CRect tabRect, itemRect;    GetClientRect(&tabRect);    GetItemRect(0, &itemRect);    int nX = itemRect.left;    int nY = itemRect.bottom + 1;    int nXc = tabRect.right - itemRect.left - 2;    int nYc = tabRect.bottom - nY - 2;    m_pPages[0]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);    for (int nCount = 1; nCount < m_nNumOfPages; ++nCount) {        m_pPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);    }}
  • 在主窗口对话框的头文件中添加对话框类的头文件,并声明对象成员变量:

    #include "MyDlg1.h"#include "MyDlg2.h"CTabSheet m_tabSheet;CDialog* m_dlg1 = nullptr;CDialog* m_dlg2 = nullptr;
  • 在主窗口的OnInitDialog函数中初始化CTabSheet:

    BOOL CMainDlg::OnInitDialog() {    CDialogEx::OnInitDialog();    // ... 其他初始化代码 ...    // 初始化CTabSheet    m_tabSheet.AddPage(_T("系统设置"), m_dlg1, IDD_DIALOG1);    m_tabSheet.AddPage(_T("参数设置"), m_dlg2, IDD_DIALOG2);    m_tabSheet.Show();}
  • 确保对话框作为CTabSheet的子窗口并正确嵌入:

    • 设置对话框的父窗口为CTabSheet。
    • 调整对话框的边框属性,确保它们作为CTabSheet的页面显示。
  • 通过以上步骤,可以实现基于对话框的TabControl,实现多个页面的切换和显示。

    转载地址:http://itfv.baihongyu.com/

    你可能感兴趣的文章
    npm发布自己的组件UI包(详细步骤,图文并茂)
    查看>>
    npm和package.json那些不为常人所知的小秘密
    查看>>
    npm和yarn清理缓存命令
    查看>>
    npm和yarn的使用对比
    查看>>
    npm如何清空缓存并重新打包?
    查看>>
    npm学习(十一)之package-lock.json
    查看>>
    npm安装 出现 npm ERR! code ETIMEDOUT npm ERR! syscall connect npm ERR! errno ETIMEDOUT npm ERR! 解决方法
    查看>>
    npm安装crypto-js 如何安装crypto-js, python爬虫安装加解密插件 找不到模块crypto-js python报错解决丢失crypto-js模块
    查看>>
    npm安装教程
    查看>>
    npm报错Cannot find module ‘webpack‘ Require stack
    查看>>
    npm报错Failed at the node-sass@4.14.1 postinstall script
    查看>>
    npm报错fatal: Could not read from remote repository
    查看>>
    npm报错File to import not found or unreadable: @/assets/styles/global.scss.
    查看>>
    npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
    查看>>
    npm淘宝镜像过期npm ERR! request to https://registry.npm.taobao.org/vuex failed, reason: certificate has ex
    查看>>
    npm版本过高问题
    查看>>
    npm的“--force“和“--legacy-peer-deps“参数
    查看>>
    npm的安装和更新---npm工作笔记002
    查看>>
    npm的常用操作---npm工作笔记003
    查看>>
    npm的常用配置项---npm工作笔记004
    查看>>