更改CPropertySheet中CPropertyPage的文本

三方法改变标签页标题

1 CPropertyPage::Construct(UINT nIDTemplate, UINT nIDCaption = 0)函数具有 nIDCaption 参数可用于指定 ID 字符串资源。 默认值为 0 (表示要使用对话框模板标题) 但可标识任何有效字符串资源。

2 CPropertyPage 有称为 m_psp, 是 PROPSHEETPAGE 结构成员。 您可以设置此结构的 dwFlags 元素和 PSP_USETITLE pszTitle 指向字符串将用作标题。

 

3 如果要更改标签中文本, 表创建后可以调用 PropertySheet::GetTabControl() 以获取 CTabCtrl 指针。 然后可以填写 TC_ITEM 结构, 并使用 CTabCtrl 指针, 调用 CTabCtrl::SetItem() 以设置文本对每个选项卡.

 

 

示例代码

方法1
/* Compile options needed:  Default
*/ 

// CMySheet is derived from CPropertySheet.
// CPage1 is derived from CPropertyPage.

// METHOD ONE ======================================================
// passing the string ID to the constructor. ClassWizard does not
// generate a constructor that takes the caption ID as a parameter,
// so it may be necessary to modify the CPage1's constructor
class CPage1 : public CPropertyPage
{
// ...

public:
    CPage1(UINT nIDCaption = 0);

// ...
};

CPage1::CPage1(UINT nIDCaption) :CPropertyPage(CMyPage::IDD, nIDCaption)
{
    //{{AFX_DATA_INIT(CMyPage)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
}

// Use the class's constructor to pass the string ID
CMyView::ShowPropertySheet ()
{
    m_pSheet = new CMySheet ("Sheet Title");
    ASSERT (m_pSheet);
    m_pPage1 = new CPage1(IDS_MYCAPTION); // id of string resource
    ASSERT (m_pPage1);

    m_pSheet->DoModal ();
}

方法2
// METHOD TWO ======================================================
// this shows how to change the title of a CPropertyPage before the
// call to DoModal()
CMyView::ShowPropertySheet ()
{
    m_pSheet = new CMySheet ("Sheet Title");
    ASSERT (m_pSheet);
    m_pPage1 = new CPage1;
    ASSERT (m_pPage1);

    m_pPage1->m_psp.dwFlags |= PSP_USETITLE;
    m_pPage1->m_psp.pszTitle = _T("My Caption");

    m_pSheet->DoModal ();
}
方法3
// METHOD THREE ======================================================
// This function allows you to pass the index number of a
// CPropertyPage and a string to set the title to.
BOOL CMySheet::SetPageTitle (int nPage, LPTSTR pszText)
{
    CTabCtrl* pTab = GetTabControl();
    ASSERT (pTab);

    TC_ITEM ti;
    ti.mask = TCIF_TEXT;
    ti.pszText = pszText;
    VERIFY (pTab->SetItem (nPage, &ti));

    return TRUE;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值