三方法改变标签页标题
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; }