如何改变propertypage的标题?

hury 2002-10-22 05:06:56
往一个property设额头里加入同一个propertypage的不同实例,但要改变其标题,用setwindowtext不行,该如何做呢?
...全文
134 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hury 2002-10-23
  • 打赏
  • 举报
回复
thank you very much!
蒋晟 2002-10-23
  • 打赏
  • 举报
回复
HOWTO: How to Change the Text in the Tabs of a CPropertySheet

Q141487


--------------------------------------------------------------------------------
The information in this article applies to:

The Microsoft Foundation Classes (MFC), used with:
Microsoft Visual C++, 32-bit Editions, version 4.0

--------------------------------------------------------------------------------


SUMMARY
The text that appears in the tabs of a CPropertySheet are usually taken from the caption of each CPropertyPage in the dialog template resource. There are some other methods that can be used to select the caption for each page.



MORE INFORMATION

Three Methods You Can Use to Select the Caption for Each Page
The CPropertyPage constructor has a UINT nIDCaption parameter that can be used to specify a string resource ID. The default is 0 (indicates to use the dialog template caption) but can be any valid string resource ID.


The CPropertyPage has a member called m_psp that is a PROPSHEETPAGE structure. You can set this structure's dwFlags element to PSP_USETITLE and pszTitle to a string that will be used as the title. This method can only be used before the call to Create() or DoModal().


If you want to change the text in the tabs after the sheet has been created, you can call PropertySheet::GetTabControl() to get a CTabCtrl pointer. You can then fill in a TC_ITEM structure, and using the CTabCtrl pointer, call CTabCtrl::SetItem() to set the text for each tab.


Sample Code

/* 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 ();
}

// 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 ();
}

// 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;
}

Additional query words: kbinf 4.00

Keywords : kbMFC kbPropSheet KbUIDesign kbVC kbGrpDSMFCATL
Issue type : kbhowto
Technology : kbAudDeveloper kbMFC

hury 2002-10-22
  • 打赏
  • 举报
回复
如上面代码所示,我在一个propertysheet里要同时显示CViewStartEndCon的两个实例,但无论是在propertysheet的WM_INITDIALOG的事件里还是m_pActEndCon这个实例的类的WM_INITDIALOG事件里处理,两个tab的标题还是一样:(,其代码如下:
if( !m_bIsStart)
{
TCITEM tabItem;
tabItem.dwState = TCIF_TEXT;
tabItem.pszText = _T("结束时间");
((CPropertySheet*)this->GetParent())->GetTabControl()->SetItem( 1, &tabItem );
}
跟踪一把,发现m_sheet.DoModal() ;之前既没触发oncreate事件,也没有触发WM_INITDIALOG。请问那里出错了,救救我啊:(
蒋晟 2002-10-22
  • 打赏
  • 举报
回复
在Page有窗口的时候改,通常在Page的WM_INITDIALOG或者其他消息处理中
hury 2002-10-22
  • 打赏
  • 举报
回复
在propertysheet里加吗?我在父窗口的代码为:
CViewStartEndCon m_pActStartCon;//开始条件属性页类
CViewStartEndCon m_pActEndCon;//结束条件属性页类
m_sheet.AddPage( &m_pActStartCon );
m_pActEndCon.m_bIsStart = FALSE ;
m_sheet.AddPage( &m_pActEndCon );
int nRet = m_sheet.DoModal() ;
if ( IDOK == nRet )
{
//save data
}
在domodal前setitem不行呀!而在CViewStartEndCon 这个属性页的create和initdialog用bIsStart 标志判断也不行,好像一必须在domodal前改,在那里呢?
蒋晟 2002-10-22
  • 打赏
  • 举报
回复
1 GetParent(a propertysheet)
2 GetTanCtrl
3 SetItem

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧