65.9K
CodeProject 正在变化。 阅读更多。
Home

一个简单的标签式对话框控件

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.76/5 (39投票s)

2003年6月13日

viewsIcon

140445

downloadIcon

3786

CTabDialog 将按钮和对话框捆绑在一起,允许用户添加自定义绘制的按钮和对话框。

Sample Image - TabDialog.gif

引言

如今,基于对话框的应用程序越来越受欢迎。为了使我未来的基于对话框的应用程序开发更容易,我开发了这个 CTabDialog,它的操作方式类似于选项卡控件,但为您提供了添加自定义绘制按钮和对话框的更多机会。希望 CTabDialog 能使您开发基于对话框的应用程序更加容易。

使用代码

使用该类

  • 将类包含到您的应用程序中
    #include 
    "TabDialog.h"
    
  • CTabDialog 数据成员添加到您的应用程序中
    private:
        CTabDialog* m_pTabDialog;
    
  • 在您的应用程序的 OnInitDialog() 中,初始化 CTabDialog
    //create the TabDialog
    m_pTabDialog = new CTabDialog(IDD_TABDLG, this);
    
    if (m_pTabDialog->Create(IDD_TABDLG, this) == FALSE)
        return FALSE;
    
    //set the TabDialog's positon
    m_pTabDialog->SetWindowPos(this, rect.left, rect.top, 0 , 0,
        SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
    

    注意:您需要为 CTabDialog 控件创建一个对话框资源。

  • 然后您需要将页面添加到控件中
    ////////////////////////////////////////////////////////////
    //Add pages (include button and dialog) to TabDialog
    BOOL CTabDialogTestDlg::AddPagesToTabDialog()
    {
        //create first button
        m_pBtnOne = new CButton();
        RECT rectOne;
    
        rectOne.left = BTNONE_LOCATION.x;
        rectOne.right = BTNONE_LOCATION.x+BUTTON_WIDTH;
        rectOne.top = BTNONE_LOCATION.y;
        rectOne.bottom = BTNONE_LOCATION.y+BUTTON_HEIGHT;
    
        m_pBtnOne->Create("One", WS_CHILD | WS_VISIBLE | WS_TABSTOP, rectOne,
            m_pTabDialog, BUTTON_ONE);
    
        //create first dialog
        m_pPageOne = new CPageOneDlg(m_pTabDialog);
    
        if (m_pPageOne->Create(IDD_PAGE_ONE, m_pTabDialog) == FALSE)
            return FALSE;
    
        //add first page
        m_pTabDialog->AddPage(m_pPageOne, m_pBtnOne);
    
        //Create second button
        m_pBtnTwo = new CButton();
        RECT rectTwo;
    
        rectTwo.left = BTNTWO_LOCATION.x;
        rectTwo.right = BTNTWO_LOCATION.x+BUTTON_WIDTH;
        rectTwo.top = BTNTWO_LOCATION.y;
        rectTwo.bottom = BTNTWO_LOCATION.y+BUTTON_HEIGHT;
    
        m_pBtnTwo->Create("Two", WS_CHILD | WS_VISIBLE | WS_TABSTOP, rectTwo,
            m_pTabDialog, BUTTON_TWO);
    
        //create second dialog
        m_pPageTwo = new CPageTwoDlg(m_pTabDialog);
    
        if(m_pPageTwo->Create(IDD_PAGE_TWO, m_pTabDialog) == FALSE)
            return FALSE;
    
        //add second page
        m_pTabDialog->AddPage(m_pPageTwo, m_pBtnTwo);
    
        //Create third button
        m_pBtnThree = new CButton();
        RECT rectThree;
    
        rectThree.left = BTNTHREE_LOCATION.x;
        rectThree.right = BTNTHREE_LOCATION.x+BUTTON_WIDTH;
        rectThree.top = BTNTHREE_LOCATION.y;
        rectThree.bottom = BTNTHREE_LOCATION.y+BUTTON_HEIGHT;
    
        m_pBtnThree->Create("Three", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
            rectThree, m_pTabDialog, BUTTON_THREE);
    
        //create third dialog
        m_pPageThree = new CPageThreeDlg(m_pTabDialog);
    
        if(m_pPageThree->Create(IDD_PAGE_THREE, m_pTabDialog) == FALSE)
            return FALSE;
    
        //add third page
        m_pTabDialog->AddPage(m_pPageThree, m_pBtnThree);
    
        return TRUE;
    }
    
  • 然后您需要调用 CTabDialogInitPagesShow() 成员函数来设置控件的默认显示方式。
    //initialize the showing of TabDialog
    m_pTabDialog->InitPagesShow();
    
© . All rights reserved.