共用方式為


CPropertySheet 類別

表示屬性工作表,也稱為索引標籤對話方塊。

語法

class CPropertySheet : public CWnd

成員

公用建構函式

名稱 描述
CPropertySheet::CPropertySheet 建構 CPropertySheet 物件。

公用方法

名稱 描述
CPropertySheet::AddPage 將頁面新增至屬性工作表。
CPropertySheet::Construct 建構 CPropertySheet 物件。
CPropertySheet::Create 顯示無模式屬性表。
CPropertySheet::DoModal 顯示強制響應屬性表。
CPropertySheet::EnableStackedTabs 指出屬性表使用堆疊或捲動索引標籤。
CPropertySheet::EndDialog 終止屬性表。
CPropertySheet::GetActiveIndex 擷取屬性表使用中頁面的索引。
CPropertySheet::GetActivePage 傳回使用中的頁面物件。
CPropertySheet::GetPage 擷取指定頁面的指標。
CPropertySheet::GetPageCount 擷取屬性表中的頁面數目。
CPropertySheet::GetPageIndex 擷取屬性表指定頁面的索引。
CPropertySheet::GetTabControl 擷取索引標籤的指標。
CPropertySheet::MapDialogRect 將矩形的對話框單位轉換成螢幕單位。
CPropertySheet::OnInitDialog 覆寫以增強屬性表初始化。
CPropertySheet::PressButton 模擬屬性表中指定按鈕的選擇。
CPropertySheet::RemovePage 從屬性表移除頁面。
CPropertySheet::SetActivePage 以程式設計方式設定使用中的頁面物件。
CPropertySheet::SetFinishText 設定 [完成] 按鈕的文字。
CPropertySheet::SetTitle 設定屬性表的標題。
CPropertySheet::SetWizardButtons 啟用精靈按鈕。
CPropertySheet::SetWizardMode 啟用精靈模式。

公用資料成員

名稱 描述
CPropertySheet::m_psh Windows PROPSHEETHEADER 結構。 提供基本屬性表參數的存取權。

備註

屬性表是由 CPropertySheet 物件和一或多個 CPropertyPage 對象所組成。 架構會將屬性表顯示為一個視窗,其中包含一組索引標籤索引,以及包含目前選取頁面的區域。 用戶會使用適當的索引標籤瀏覽至特定頁面。

CPropertySheet 支援 Windows 98 和 Windows NT 2000 中引進的擴充 PROPSHEETHEADER 結構。 結構包含支援使用「浮浮浮水印」背景點陣圖的其他旗標和成員。

若要在屬性表物件中自動顯示這些新影像,請在呼叫 CPropertySheet::ConstructCPropertySheet::CPropertySheet中傳遞位圖和調色盤影像的有效值。

雖然 CPropertySheet 不是衍生自 CDialog,但管理 CPropertySheet 物件就像管理 對象一 CDialog 樣。 例如,建立屬性表需要兩部分建構:呼叫建構函式,然後呼叫 DoModal 強制響應屬性表或 Create 無模式屬性表。 CPropertySheet 有兩種類型的建構函式: CPropertySheet::ConstructCPropertySheet::CPropertySheet

當您建構 CPropertySheet 物件時,某些 視窗樣式 可能會導致第一次發生例外狀況。 這會導致系統嘗試在建立工作表之前變更屬性表的樣式。 若要避免此例外狀況,請確定您在建立 CPropertySheet時設定下列樣式:

  • DS_3DLOOK

  • DS_CONTROL

  • WS_CHILD

  • WS_TABSTOP

下列樣式是選擇性的,而且不會造成第一次發生例外狀況:

  • DS_SHELLFONT

  • DS_LOCALEDIT

  • WS_CLIPCHILDREN

禁止任何其他 Window Styles 專案,您不應該啟用它們。

在物件與外部對象之間 CPropertySheet 交換數據類似於與 CDialog 物件交換數據。 重要差異在於屬性表的設定通常是對象的成員變數 CPropertyPage ,而不是 CPropertySheet 物件本身。

您可以建立稱為精靈的索引卷標對話框類型,其中包含一連串屬性頁的屬性表,引導使用者完成作業的步驟,例如設定裝置或建立電子報。 在精靈類型索引標籤對話框中,屬性頁沒有索引標籤,而且一次只能顯示一個屬性頁。 此外,精靈類型索引標籤對話框沒有 [確定] 和 [立即套用] 按鈕,而是具有 [上一步] 或 [完成] 按鈕、[取消] 按鈕和 [說明] 按鈕。

若要建立精靈類型對話框,請遵循建立標準屬性表時所遵循的相同步驟,但在呼叫 之前呼叫 SetWizardMode DoModal。 若要開啟精靈按鈕,請使用旗標來自定義函式和外觀。若要啟用精靈按鈕,請呼叫 SetWizardButtons。 若要開啟 [ 完成] 按鈕,請在使用者於精靈的最後一頁採取動作之後呼叫 SetFinishText

如需如何使用CPropertySheet對象的詳細資訊,請參閱屬性表和屬性頁一文

繼承階層架構

CObject

CCmdTarget

CWnd

CPropertySheet

需求

頁眉: afxdlgs.h

CPropertySheet::AddPage

在屬性表中新增具有最右邊索引標籤的提供頁面。

void AddPage(CPropertyPage* pPage);

參數

pPage
指向要加入至屬性表的頁面。 不可以是 NULL

備註

以從左至右的順序,將頁面新增至屬性表,以您想要它們出現的順序。

AddPageCPropertyPage 物件新增至 CPropertySheet 對象的頁面清單,但實際上不會建立頁面的視窗。 架構會延後頁面的視窗建立,直到用戶選取該頁面為止。

當您使用 AddPage新增屬性頁時, CPropertySheet 是 的 CPropertyPage父系。 若要從屬性頁取得屬性表的存取權,請呼叫 CWnd::GetParent

不需要等到建立屬性表視窗才能呼叫 AddPage。 一般而言,您會在呼叫 或 Create之前呼叫 。AddPage DoModal

如果您在顯示屬性頁之後呼叫 AddPage ,則索引標籤數據列會反映新加入的頁面。

範例

// Add three pages to a CPropertySheet object, then show the 
// CPropertySheet object as a modal dialog.  CStylePage, CShapePage,  
// and CColorPage are CPropertyPage-derived classes created 
// by the Add Class wizard.  

CPropertySheet dlgPropertySheet(_T("Simple PropertySheet"));

CStylePage     stylePage;
CColorPage     colorPage;
CShapePage     shapePage;
dlgPropertySheet.AddPage(&stylePage);
dlgPropertySheet.AddPage(&colorPage);
dlgPropertySheet.AddPage(&shapePage);

dlgPropertySheet.DoModal();

CPropertySheet::Construct

建構 CPropertySheet 物件。

void Construct(
    UINT nIDCaption,
    CWnd* pParentWnd = NULL,
    UINT iSelectPage = 0);

void Construct(
    LPCTSTR pszCaption,
    CWnd* pParentWnd = NULL,
    UINT iSelectPage = 0);

void Construct(
    UINT nIDCaption,
    CWnd* pParentWnd,
    UINT iSelectPage,
    HBITMAP hbmWatermark,
    HPALETTE hpalWatermark = NULL,
    HBITMAP hbmHeader = NULL);

void Construct(
    LPCTSTR pszCaption,
    CWnd* pParentWnd,
    UINT iSelectPage,
    HBITMAP hbmWatermark,
    HPALETTE hpalWatermark = NULL,
    HBITMAP hbmHeader = NULL);

參數

nIDCaption
要用於屬性表之標題的標識碼。

pParentWnd
屬性表之父視窗的指標。 如果 NULL為 ,則父視窗會是應用程式的主視窗。

iSelectPage
一開始會位於頂端的頁面索引。 預設值是新增至工作表的第一頁。

pszCaption
字串的指標,其中包含要用於屬性表的標題。 不可以是 NULL

hbmWatermark
屬性頁浮浮浮

hpalWatermark
處理水位圖和/或標頭點圖的調色盤。

hbmHeader
屬性頁標頭點陣圖的句柄。

備註

如果其中一個類別建構函式尚未呼叫,請呼叫這個成員函式。 例如,當您宣告或設定 物件的陣列CPropertySheet時呼叫 Construct 。 在陣列的情況下,您必須針對陣列中的每個成員呼叫 Construct

若要顯示屬性表,請呼叫 DoModalCreate。 第一個參數中包含的字串將會放在屬性表的標題欄中。

如果您使用上述的第三個或第四個Construct原型,以及傳遞 、、 和/或 參數的有效值hbmWatermarkhpalWatermark,您可以自動顯示浮水印和/或hbmHeader標頭影像。

範例

下列範例示範在何種情況下,您會呼叫 Construct

const int c_cSheets = 3;
CPropertySheet   grpropsheet[c_cSheets];
// no need to call Construct for this next one
CPropertySheet   someSheet(_T("Some sheet"));

LPTSTR rgszSheets[c_cSheets] = {
   _T("Sheet 1"),
   _T("Sheet 2"),
   _T("Sheet 3")
};

for (int i = 0; i < c_cSheets; i++)
   grpropsheet[i].Construct(rgszSheets[i]);

CPropertySheet::CPropertySheet

建構 CPropertySheet 物件。

CPropertySheet();

explicit CPropertySheet(
    UINT nIDCaption,
    CWnd* pParentWnd = NULL,
    UINT iSelectPage = 0);

explicit CPropertySheet(
    LPCTSTR pszCaption,
    CWnd* pParentWnd = NULL,
    UINT iSelectPage = 0);

CPropertySheet(
    UINT nIDCaption,
    CWnd* pParentWnd,
    UINT iSelectPage,
    HBITMAP hbmWatermark,
    HPALETTE hpalWatermark = NULL,
    HBITMAP hbmHeader = NULL);

CPropertySheet(
    LPCTSTR pszCaption,
    CWnd* pParentWnd,
    UINT iSelectPage,
    HBITMAP hbmWatermark,
    HPALETTE hpalWatermark = NULL,
    HBITMAP hbmHeader = NULL);

參數

nIDCaption
要用於屬性表之標題的標識碼。

pParentWnd
指向屬性表的父視窗。 如果 NULL為 ,則父視窗會是應用程式的主視窗。

iSelectPage
一開始會位於頂端的頁面索引。 預設值是新增至工作表的第一頁。

pszCaption
指向包含要用於屬性表之標題的字串。 不可以是 NULL

hbmWatermark
屬性表之背景點陣圖的句柄。

hpalWatermark
浮浮水印點圖和/或標頭點陣圖調色盤的句柄。

hbmHeader
屬性頁標頭點陣圖的句柄。

備註

若要顯示屬性表,請呼叫 DoModalCreate。 第一個參數中包含的字串將會放在屬性表的標題欄中。

如果您有多個參數(例如,如果您使用陣列),請使用 Construct 而非 CPropertySheet

如果您使用 、上述的第CPropertySheet三個或第四個原型,以及傳遞、 和/或 參數的有效值hbmWatermarkhpalWatermark,您可以自動顯示浮水印和/或hbmHeader標頭影像。

範例

// Declare a CPropertySheet object titled "Simple PropertySheet".
CPropertySheet dlgPropertySheet1(_T("Simple PropertySheet"));

// Declare a CPropertySheet object whose title is specified in the
// IDS_PROPERTYSHEET_TITLE string resource, and the second page is
// initially on top.  
CPropertySheet dlgPropertySheet2(IDS_PROPERTYSHEET_TITLE, this, 1);

CPropertySheet::Create

顯示無模式屬性表。

virtual BOOL Create(CWnd* pParentWnd = NULL,
    DWORD dwStyle = (DWORD)-1,
    DWORD dwExStyle = 0);

參數

pParentWnd
指向父視窗。 如果 NULL為 ,則父系為桌面。

dwStyle
屬性表的視窗樣式。 如需可用樣式的完整清單,請參閱 視窗樣式

dwExStyle
屬性表的延伸視窗樣式。 如需可用樣式的完整清單,請參閱 延伸窗口樣式

傳回值

如果成功建立屬性表,則為非零;否則為 0。

備註

的呼叫 Create 可以位於建構函式內,或者您可以在叫用建構函式之後呼叫它。

以 傳遞 -1 表示 dwStyle的預設樣式實際上是 WS_SYSMENU|WS_POPUP|WS_CAPTION|DS_MODALFRAME|DS_CONTEXTHELP|WS_VISIBLE。 預設延伸視窗樣式,以傳遞 0 表示 dwExStyleWS_EX_DLGMODALFRAME實際上是 。

成員 Create 函式會在建立屬性表之後立即傳回。 若要終結屬性表,請呼叫 CWnd::DestroyWindow

以呼叫 Create 顯示的無模式屬性表沒有 [確定]、[取消]、[立即套用] 和 [說明] 按鈕,就像強制回應屬性表一樣。 用戶必須建立所需的按鈕。

若要顯示強制回應屬性表,請改為呼叫 DoModal

範例

// This code fragment shows how to create a modeless property sheet 
// dialog in a command message handler (OnModelessPropertySheet()) 
// of a CView-derived class.
void CPSheetView::OnModelessPropertySheet()
{
   // Declare a CPropertySheet object.  m_pdlgPropertySheet is a data
   // member of type CPropertySheet in CView-derived class.
   m_pdlgPropertySheet = new CPropertySheet(_T("Simple PropertySheet"));
   ASSERT(m_pdlgPropertySheet);

   // Add three pages to the CPropertySheet object.  Both m_pstylePage, 
   // m_pcolorPage, and m_pshapePage are data members of type 
   // CPropertyPage-derived classes in CView-derived class.
   m_pstylePage = new CStylePage;
   m_pcolorPage = new CColorPage;
   m_pshapePage = new CShapePage;
   m_pdlgPropertySheet->AddPage(m_pstylePage);
   m_pdlgPropertySheet->AddPage(m_pcolorPage);
   m_pdlgPropertySheet->AddPage(m_pshapePage);

   // Create a modeless CPropertySheet dialog.
   m_pdlgPropertySheet->Create();
}

 

// The code fragment below shows how to destroy the C++ objects for
// propertysheet and propertypage in the destructor of CView-derived
// class.
// NOTE:  DestroyWindow() is called in CPropertySheet::OnClose() so
// you do not need to call it here.  Property pages are children
// of the CPropertySheet, they will be destroyed by their parents.
CPSheetView::~CPSheetView()
{
   delete m_pshapePage;
   delete m_pstylePage;
   delete m_pcolorPage;
   delete m_pdlgPropertySheet;
}

CPropertySheet::DoModal

顯示強制響應屬性表。

virtual INT_PTR DoModal();

傳回值

IDOK 如果 IDCANCEL 函式成功,則為 ,否則為 0 或 -1。 如果屬性表已建立為精靈(請參閱 SetWizardMode),則會傳ID_WIZFINISH回 或 IDCANCELDoModal

備註

傳回值會對應至關閉屬性表之控件的標識碼。 此函式傳回之後,對應至屬性表的視窗和所有頁面都會終結。 物件本身仍會存在。 一般而言,您會在傳回IDOK之後DoModal,從物件擷CPropertyPage取數據。

若要顯示無模式屬性表,請改為呼叫 Create

從其對應的對話資源建立屬性頁時,可能會導致第一次發生例外狀況。 這會產生屬性頁,在建立頁面之前,將對話框資源的樣式變更為必要的樣式。 由於資源通常是唯讀的,因此會造成例外狀況。 系統會處理例外狀況,並製作修改過的資源複本。 因此,可以忽略第一次發生例外狀況。

注意

如果您要使用異步例外狀況處理模型進行編譯,則必須由操作系統處理此例外狀況。 如需例外狀況處理模型的詳細資訊,請參閱/EH(例外狀況處理模型)。 在此情況下,請勿 C++使用 try-catch 區塊包裝對 的呼叫 CPropertySheet::DoModal ,其中 catch 會處理所有例外狀況,例如 catch (...)。 此區塊會處理適用於操作系統的例外狀況,並造成無法預期的行為。 不過,您可以安全地使用C++例外狀況處理搭配特定的例外狀況類型或結構化例外狀況處理,其中存取違規例外狀況會傳遞至操作系統。

若要避免產生這個第一次發生例外狀況,您可以手動保證屬性表具有正確的 窗口樣式。 您必須設定屬性表的下列樣式:

  • DS_3DLOOK

  • DS_CONTROL

  • WS_CHILD

  • WS_TABSTOP

您可以使用下列選擇性樣式,而不會造成第一次發生例外狀況:

  • DS_SHELLFONT

  • DS_LOCALEDIT

  • WS_CLIPCHILDREN

停用所有其他 Windows 樣式,因為它們與屬性表不相容。 此建議不適用於延伸樣式。 適當地設定這些標準樣式可確保屬性表不需要修改,而且會避免產生第一次發生例外狀況。

範例

請參閱 CPropertySheet::AddPage 的範例。

CPropertySheet::EnableStackedTabs

指出是否要在屬性表中堆疊索引標籤的數據列。

void EnableStackedTabs(BOOL bStacked);

參數

bStacked
指出屬性表中是否啟用堆疊索引標籤。 將 設定 bStackedFALSE,以停用標記的堆疊數據列。

備註

根據預設,如果屬性表的索引卷標數目超過屬性表寬度中的單一數據列,則索引標籤會堆疊在多個數據列。 若要使用捲動索引標籤,而不是堆疊索引標籤,請在呼叫 或 之前,使用 設定為 FALSE 呼叫 。CreateEnableStackedTabs bStacked DoModal

您必須在建立強制回應或無模式屬性表時呼叫 EnableStackedTabs 。 若要將此樣式併入 CPropertySheet衍生類別中,請撰寫 的 WM_CREATE訊息處理程式。 在 覆寫的 CWnd::OnCreate版本中,呼叫 基類實作之前呼叫 EnableStackedTabs( FALSE )

範例

int CMyPropertySheet::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   // Set for Scrolling Tabs style
   EnableStackedTabs(FALSE);
   // Call the base class
   if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
      return -1;

   return 0;
}

CPropertySheet::EndDialog

終止屬性表。

void EndDialog(int nEndID);

參數

nEndID
要當做屬性表傳回值的標識碼。

備註

按下 [確定]、[取消] 或 [關閉] 按鈕時,架構會呼叫此成員函式。 如果發生應該關閉屬性表的事件,請呼叫這個成員函式。

這個成員函式只會與強制回應對話框搭配使用。

範例

請參閱 CPropertySheet::PressButton 的範例。

CPropertySheet::GetActiveIndex

取得屬性表視窗使用中頁面的索引編號,然後使用傳回的索引編號做為 的參數 GetPage

int GetActiveIndex() const;

傳回值

使用中頁面的索引編號。

範例

請參閱 CPropertySheet::GetActivePage 的範例。

CPropertySheet::GetActivePage

擷取屬性表視窗的作用中頁面。

CPropertyPage* GetActivePage() const;

傳回值

使用中頁面的指標。

備註

使用此成員函式在使用中頁面上執行一些動作。

範例

// The code fragment below sets the last active page (i.e. the 
// active page when the propertysheet was closed) to be the first 
// visible page when the propertysheet is shown. The last active 
// page was saved in m_LastActivePage, (a member variable of 
// CDocument-derived class) when OK was selected from the 
// propertysheet. CMyPropertySheet is a CPropertySheet-derived class.
BOOL CMyPropertySheet::OnInitDialog()
{
   BOOL bResult = CPropertySheet::OnInitDialog();

   CMDIFrameWnd* pframe = (CMDIFrameWnd*)AfxGetMainWnd();
   CMDIChildWnd* pchild = pframe->MDIGetActive();
   CPSheetDoc* doc = (CPSheetDoc*)pchild->GetActiveDocument();
   SetActivePage(doc->m_LastActivePage);

   return bResult;
}

BOOL CMyPropertySheet::OnCommand(WPARAM wParam, LPARAM lParam)
{
   if (LOWORD(wParam) == IDOK)
   {
      CMDIFrameWnd* pframe = (CMDIFrameWnd*)AfxGetMainWnd();
      CMDIChildWnd* pchild = pframe->MDIGetActive();
      CPSheetDoc* doc = (CPSheetDoc*)pchild->GetActiveDocument();
      doc->m_LastActivePage = GetPageIndex(GetActivePage()); // or GetActiveIndex()
   }

   return CPropertySheet::OnCommand(wParam, lParam);
}

CPropertySheet::GetPage

傳回這個屬性表中指定頁面的指標。

CPropertyPage* GetPage(int nPage) const;

參數

nPage
所需頁面的索引,從 0 開始。 必須介於 0 到 1 之間,小於屬性表中的頁數,包含。

傳回值

對應至 參數之頁面的 nPage 指標。

範例

請參閱 CPropertyPage::OnWizardFinish 的範例。

CPropertySheet::GetPageCount

決定屬性表中目前的頁面數目。

int GetPageCount() const;

傳回值

屬性表中的頁數。

範例

請參閱 CPropertyPage::OnWizardFinish 的範例。

CPropertySheet::GetPageIndex

擷取屬性表中指定頁面的索引編號。

int GetPageIndex(CPropertyPage* pPage);

參數

pPage
指向要找到索引的頁面。 不可以是 NULL

傳回值

頁面的索引編號。

備註

例如,您可以使用 GetPageIndex 來取得頁面索引,以便使用 SetActivePageGetPage

範例

請參閱 CPropertySheet::GetActivePage 的範例。

CPropertySheet::GetTabControl

擷取索引標籤的指標,以執行 Tab 控件特有的動作(也就是使用 中的任何 CTabCtrlAPI)。

CTabCtrl* GetTabControl() const;

傳回值

索引標籤控件的指標。

備註

例如,如果您想要在初始化期間將點陣圖新增至每個索引標籤,請呼叫這個成員函式。

範例

// Create and associate a tooltip control to the tab control of 
// CMyTTPropertySheet.  CMyTTPropertySheet is a CPropertySheet-derived
// class.
BOOL CMyTTPropertySheet::OnInitDialog()
{
   BOOL bResult = CPropertySheet::OnInitDialog();

   // Create a tooltip control.  m_pToolTipCtrl is a member variable
   // of type CToolTipCtrl* in CMyTTPropertySheet class.  It is 
   // initialized to NULL in the constructor, and destroyed in the 
   // destructor of CMyTTPropertySheet class.
   m_pToolTipCtrl = new CToolTipCtrl;
   if (!m_pToolTipCtrl->Create(this))
   {
      TRACE(_T("Unable To create ToolTip\n"));
      return bResult;
   }

   // Associate the tooltip control to the tab control
   // of CMyPropertySheet.
   CTabCtrl* ptab = GetTabControl();
   ptab->SetToolTips(m_pToolTipCtrl);

   // Get the bounding rectangle of each tab in the tab control of the
   // property sheet. Use this rectangle when registering a tool with 
   // the tool tip control.  IDS_FIRST_TOOLTIP is the first ID string 
   // resource that contains the text for the tool.
   int count = ptab->GetItemCount();
   int id = IDS_FIRST_TOOLTIP;
   for (int i = 0; i < count; i++)
   {
      CRect r;
      ptab->GetItemRect(i, &r);
      VERIFY(m_pToolTipCtrl->AddTool(ptab, id, &r, id));
      id++;
   }

   // Activate the tooltip control.
   m_pToolTipCtrl->Activate(TRUE);

   return bResult;
}

// Override PreTranslateMessage() so RelayEvent() can be 
// called to pass a mouse message to CMyTTPropertySheet's 
// tooltip control for processing.
BOOL CMyTTPropertySheet::PreTranslateMessage(MSG* pMsg)
{
   if (NULL != m_pToolTipCtrl)
      m_pToolTipCtrl->RelayEvent(pMsg);

   return CPropertySheet::PreTranslateMessage(pMsg);
}

CPropertySheet::m_psh

結構,其成員會儲存的特性 PROPSHEETHEADER

備註

使用此結構,在建構屬性表之後,但在使用 DoModal 成員函式顯示之前,初始化屬性表的外觀。 例如,將 dwSize 的成員 m_psh 設定為您想要屬性表擁有的大小。

如需此結構的詳細資訊,包括其成員的清單,請參閱 PROPSHEETHEADER Windows SDK。

範例

// This code fragment shows how to change CPropertySheet's settings 
// before it is shown.  After the changes, CPropertySheet has the 
// caption "Simple Properties", no "Apply" button, and the 
// second page (CColorPage) initially on top.  

CPropertySheet dlgPropertySheet(_T("Simple PropertySheet"));

CStylePage stylePage;
CColorPage colorPage;
CShapePage shapePage;
dlgPropertySheet.AddPage(&stylePage);
dlgPropertySheet.AddPage(&colorPage);
dlgPropertySheet.AddPage(&shapePage);

dlgPropertySheet.m_psh.dwFlags |= PSH_NOAPPLYNOW | PSH_PROPTITLE;
dlgPropertySheet.m_psh.pszCaption = _T("Simple");
dlgPropertySheet.m_psh.nStartPage = 1;

dlgPropertySheet.DoModal();

CPropertySheet::MapDialogRect

將矩形的對話框單位轉換成螢幕單位。

void MapDialogRect(LPRECT lpRect) const;

參數

lpRect
指向 RECT 包含要轉換之對話框座標的結構或 CRect 物件。

備註

對話框單位會以目前對話框基底單位來表示,這些單位衍生自用於對話框文字之字型中字元的平均寬度和高度。 一個水準單位是對話框基底寬度單位的四分之一,而一個垂直單位是對話框基底高度單位的八分之一。

Windows 函 GetDialogBaseUnits 式會傳回系統字型的大小資訊,但是如果您在資源定義檔案中使用DS_SETFONT樣式,則可以為每個屬性表指定不同的字型。 MapDialogRect Windows SDK 中所述的 Windows 函式會針對此對話框使用適當的字型。

成員 MapDialogRect 函式會將 中的 lpRect 對話框單位取代為螢幕單位(圖元),讓矩形可用來建立對話框或將控件放置在方塊內。

CPropertySheet::OnInitDialog

覆寫以增強屬性表初始化。

virtual BOOL OnInitDialog();

傳回值

指定應用程式是否已將輸入焦點設定為屬性表中的其中一個控件。 如果 OnInitDialog 傳回非零,Windows 會將輸入焦點設定為屬性表中的第一個控件。 只有當應用程式已明確將輸入焦點設定為屬性表中的其中一個控件時,應用程式才能傳回 0。

備註

呼叫此成員函式以回應 WM_INITDIALOG 訊息。 此訊息會在 或 DoModal 呼叫期間Create傳送至屬性表,該訊息會在顯示屬性表之前立即發生。

如果您需要在初始化屬性表時執行特殊處理,請覆寫此成員函式。 在覆寫的版本中,先呼叫基類 OnInitDialog ,但忽略其傳回值。 您通常會從覆寫的成員函式傳回 TRUE

您不需要此成員函式的訊息對應專案。

CPropertySheet::PressButton

模擬屬性表中指定按鈕的選擇。

void PressButton(int nButton);

參數

nButton
nButton :識別要按下的按鈕。 這個參數可以是下列其中一個 值:

  • PSBTN_BACK 選擇 [上一頁] 按鈕。

  • PSBTN_NEXT 選擇 [下一步] 按鈕。

  • PSBTN_FINISH 選擇 [完成] 按鈕。

  • PSBTN_OK 選擇 [確定] 按鈕。

  • PSBTN_APPLYNOW 選擇 [立即套用] 按鈕。

  • PSBTN_CANCEL 選擇 [取消] 按鈕。

  • PSBTN_HELP 選擇 [說明] 按鈕。

備註

如需 Windows SDK Pressbutton 訊息的詳細資訊,請參閱 PSM_PRESSBUTTON

PressButton 的呼叫不會將通知從屬性頁傳送 PSN_APPLY 至架構。 若要傳送此通知,請呼叫 CPropertyPage::OnOK

範例

// Simulate the selection of OK and Cancel buttons when Alt+K and
// Alt+C are pressed.  CMyPropertySheet is a CPropertySheet-derived 
// class.
BOOL CMyPropertySheet::PreTranslateMessage(MSG* pMsg)
{
   if (pMsg->message >= WM_KEYFIRST && pMsg->message <= WM_KEYLAST)
   {
      BOOL altkey = GetKeyState(VK_MENU) < 0;
      if (altkey)
      {
         BOOL handled = TRUE;
         switch (toupper((int)pMsg->wParam))
         {
         case 'C':                     // for Alt+C - Cancel button
            PressButton(PSBTN_CANCEL);   // or EndDialog(IDCANCEL);
            break;

         case 'K':                     // for Alt+K - OK button
            PressButton(PSBTN_OK);      // or EndDialog(IDOK);
            break;

         default:
            handled = FALSE;
         }

         if (handled)
            return TRUE;
      }
   }

   return CPropertySheet::PreTranslateMessage(pMsg);
}

CPropertySheet::RemovePage

從屬性表移除頁面,並終結相關聯的視窗。

void RemovePage(CPropertyPage* pPage);
void RemovePage(int nPage);

參數

pPage
指向要從屬性表移除的頁面。 不可以是 NULL

nPage
要移除之頁面的索引。 必須介於 0 到 1 之間,小於屬性表中的頁數,包含。

備註

物件 CPropertyPage 本身不會終結,直到視窗的 CPropertySheet 擁有者關閉為止。

CPropertySheet::SetActivePage

變更使用中頁面。

BOOL SetActivePage(int nPage);
BOOL SetActivePage(CPropertyPage* pPage);

參數

nPage
要設定的頁面索引。 它必須介於 0 到 1 之間,小於屬性表中的頁面數目,包含。

pPage
指向屬性表中要設定的頁面。 不可為 NULL

傳回值

如果屬性表已成功啟動,則為非零;否則為 0。

備註

例如, SetActivePage 如果某個頁面上的使用者動作應該會導致另一個頁面成為使用中頁面,請使用 。

範例

請參閱 CPropertySheet::GetActivePage 的範例。

CPropertySheet::SetFinishText

設定 [完成] 命令按鈕中的文字。

void SetFinishText(LPCTSTR lpszText);

參數

lpszText
指向要顯示在 [完成] 命令按鈕上的文字。

備註

呼叫 SetFinishText 以顯示 [完成] 命令按鈕上的文字,並在使用者完成精靈最後一頁的動作之後隱藏 [下一步] 和 [上一頁] 按鈕。

範例

// CShapePage is the last wizard property page. Enable the Back 
// button and change the Next button to Finish. The "Finish" button 
// will have "Done" as its caption.
BOOL CShapePage::OnSetActive()
{
   CPropertySheet* psheet = (CPropertySheet*)GetParent();
   psheet->SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);
   psheet->SetFinishText(_T("Done"));

   return CPropertyPage::OnSetActive();
}

CPropertySheet::SetTitle

指定屬性表的標題(顯示在框架視窗標題列中的文字)。

void SetTitle(
    LPCTSTR lpszText,
    UINT nStyle = 0);

參數

nStyle
指定屬性表標題的樣式。 樣式必須指定為 0 或 。PSH_PROPTITLE 如果樣式設定為 PSH_PROPTITLE,則 「Properties」 這個字會出現在指定為標題的文字之後。 例如,呼叫 SetTitle(“Simple”, PSH_PROPTITLE) 將會產生 “Simple Properties” 的屬性表標題。

lpszText
指向要當做屬性表標題列中標題的文字。

備註

根據預設,屬性表會使用屬性表建構函式中的 caption 參數。

範例

// Declare a CPropertySheet object with a caption "Simple PropertySheet".
CPropertySheet dlgPropertySheet(_T("Simple PropertySheet"));

// Add three pages to the CPropertySheet object. CStylePage, CColorPage,
// and CShapePage are CPropertyPage-derived classes created
// by the Add Class wizard.
CStylePage     stylePage;
CColorPage     colorPage;
CShapePage     shapePage;
dlgPropertySheet.AddPage(&stylePage);
dlgPropertySheet.AddPage(&colorPage);
dlgPropertySheet.AddPage(&shapePage);

// Change the caption of the CPropertySheet object 
// from "Simple PropertySheet" to "Simple Properties".
dlgPropertySheet.SetTitle(_T("Simple"), PSH_PROPTITLE);

// Show the CPropertySheet object as MODAL.
dlgPropertySheet.DoModal();

CPropertySheet::SetWizardButtons

啟用或停用精靈屬性表中的 [上一步] 或 [完成] 按鈕。

void SetWizardButtons(DWORD dwFlags);

參數

dwFlags
一組旗標,可自定義精靈按鈕的函式和外觀。 此參數可以是下列值的組合:

  • PSWIZB_BACK 上一頁按鈕

  • PSWIZB_NEXT [下一步] 按鈕

  • PSWIZB_FINISH 完成按鈕

  • PSWIZB_DISABLEDFINISH [已停用完成] 按鈕

備註

SetWizardButtons只有在對話框開啟之後呼叫,您就無法在呼叫 之前呼叫 SetWizardButtons DoModal。 一般而言,您應該從CPropertyPage::OnSetActive呼叫 SetWizardButtons

如果您要變更 [完成] 按鈕上的文字,或在使用者完成精靈之後隱藏 [下一步] 和 [上一步] 按鈕,請呼叫 SetFinishText。 請注意,[完成] 和 [下一步] 共用相同的按鈕。 您可以一次顯示 [完成] 或 [下一步] 按鈕,但不能同時顯示兩者。

範例

有三個 CPropertySheet 精靈屬性頁: CStylePageCColorPageCShapePage。 下列代碼段示範如何啟用和停用精靈屬性頁面上的 [上一 步] 和 [下一步 ] 按鈕。

// CStylePage is the first wizard property page.  Disable the Back 
// button but enable the Next button.
BOOL CStylePage::OnSetActive() 
{
   CPropertySheet* psheet = (CPropertySheet*) GetParent();   
   psheet->SetWizardButtons(PSWIZB_NEXT);
   
   return CPropertyPage::OnSetActive();
}

 

// CColorPage is the second wizard property page. Enable both the 
// Back button and the Next button.
BOOL CColorPage::OnSetActive()
{
   CPropertySheet* psheet = (CPropertySheet*)GetParent();
   psheet->SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);

   return CPropertyPage::OnSetActive();
}

 

// CShapePage is the last wizard property page. Enable the Back 
// button and change the Next button to Finish. The "Finish" button 
// will have "Done" as its caption.
BOOL CShapePage::OnSetActive()
{
   CPropertySheet* psheet = (CPropertySheet*)GetParent();
   psheet->SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);
   psheet->SetFinishText(_T("Done"));

   return CPropertyPage::OnSetActive();
}

CPropertySheet::SetWizardMode

建立屬性頁做為精靈。

void SetWizardMode();

備註

精靈屬性頁的主要特性是使用者會使用 [下一步] 或 [完成]、[上一頁] 和 [取消] 按鈕來巡覽,而不是索引卷標。

通話 之前先呼叫 SetWizardMode DoModal。 呼叫 SetWizardMode之後, DoModal 將會傳回 ID_WIZFINISH (如果使用者以 [完成] 按鈕關閉)或 IDCANCEL

SetWizardModePSH_WIZARD會設定旗標。

範例

CPropertySheet sheet(_T("Simple PropertySheet"));

CStylePage pageStyle;
CColorPage pageColor;
CShapePage pageShape;

sheet.AddPage(&pageStyle);
sheet.AddPage(&pageColor);
sheet.AddPage(&pageShape);

sheet.SetWizardMode();

sheet.DoModal();

另請參閱

MFC 範例 CMNCTRL1
MFC 範例 CMNCTRL2
MFC 範例 PROPDLG
MFC 範例 SNAPVW
CWnd
階層架構圖表