次の方法で共有


CPropertyPage クラス

タブ ダイアログ ボックスとして知られているプロパティ シートの各ページを表します。

構文

class CPropertyPage : public CDialog

メンバー

パブリック コンストラクター

名前 説明
CPropertyPage::CPropertyPage CPropertyPage オブジェクトを構築します。

パブリック メソッド

名前 説明
CPropertyPage::CancelToClose OK ボタンを変更して Close を読み取り、モーダル プロパティ シートのページで回復不能な変更を行った後、Cancel ボタンを無効にします。
CPropertyPage::Construct CPropertyPage オブジェクトを構築します。 実行時にパラメーターを指定する場合、または配列を使用している場合は、 Construct を使用します。
CPropertyPage::GetPSP CPropertyPage オブジェクトに関連付けられている Windows PROPSHEETPAGE構造体を取得します。
CPropertyPage::OnApply Apply Now ボタンがクリックされたときにフレームワークによって呼び出されます。
CPropertyPage::OnCancel Cancel ボタンがクリックされたときにフレームワークによって呼び出されます。
CPropertyPage::OnKillActive 現在のページがアクティブページでなくなったときにフレームワークによって呼び出されます。 ここでデータ検証を実行します。
CPropertyPage::OnOK OKApply Now、または Close ボタンがクリックされたときにフレームワークによって呼び出されます。
CPropertyPage::OnQueryCancel Cancel ボタンがクリックされたときに、取り消しが行われる前にフレームワークによって呼び出されます。
CPropertyPage::OnReset Cancel ボタンがクリックされたときにフレームワークによって呼び出されます。
CPropertyPage::OnSetActive ページがアクティブページになったときにフレームワークによって呼び出されます。
CPropertyPage::OnWizardBack ウィザードの種類のプロパティ シートの使用中に Back ボタンがクリックされたときにフレームワークによって呼び出されます。
CPropertyPage::OnWizardFinish ウィザードの種類のプロパティ シートを使用しているときに Finish ボタンがクリックされたときにフレームワークによって呼び出されます。
CPropertyPage::OnWizardNext ウィザードの種類のプロパティ シートの使用中に Next ボタンがクリックされたときにフレームワークによって呼び出されます。
CPropertyPage::QuerySiblings プロパティ シートの各ページにメッセージを転送します。
CPropertyPage::SetModified [今すぐ適用] ボタンをアクティブまたは非アクティブにするために呼び出します。

パブリック データ メンバー

名前 説明
CPropertyPage::m_psp Windows PROPSHEETPAGE 構造体。 基本的なプロパティ ページ パラメーターへのアクセスを提供します。

解説

標準ダイアログ ボックスと同様に、プロパティ シート内の各ページの CPropertyPage からクラスを派生させます。 CPropertyPage派生オブジェクトを使用するには、最初にCPropertySheet オブジェクトを作成してから、プロパティ シート内のページごとにオブジェクトを作成します。 シート内の各ページの CPropertySheet::AddPage を呼び出し、モーダル プロパティ シートの CPropertySheet::DoModal を呼び出すか、モードレス プロパティ シートの CPropertySheet::Create を呼び出してプロパティ シートを表示します。

ウィザードと呼ばれるタブ ダイアログ ボックスの種類を作成できます。このダイアログ ボックスは、デバイスの設定やニュースレターの作成など、操作の手順をユーザーに案内する一連のプロパティ ページを含むプロパティ シートで構成されます。 ウィザードの種類のタブ ダイアログ ボックスでは、プロパティ ページにはタブがなく、一度に表示されるプロパティ ページは 1 つだけです。 また、 OKApply Now ボタンを使用する代わりに、ウィザードの種類のタブ ダイアログ ボックスに Back ボタン、 Next または Finish ボタン、および Cancel ボタンがあります。

ウィザードとしてプロパティ シートを確立する方法の詳細については、「 CPropertySheet::SetWizardMode」を参照してください。 CPropertyPage オブジェクトの使用方法の詳細については、「プロパティ シートとプロパティ ページ」を参照してください

継承階層

CObject

CCmdTarget

CWnd

CDialog

CPropertyPage

要件

ヘッダー: afxdlgs.h

CPropertyPage::CancelToClose

この関数は、モーダル プロパティ シートのページのデータに回復不能な変更が加えられた後に呼び出します。

void CancelToClose();

解説

この関数は、[OK] ボタンを [閉じる] に変更し、[キャンセル] ボタンを無効にします。 この変更は、変更が永続的であり、変更をキャンセルできないことをユーザーに通知します。

モードレス プロパティ シートには既定で Cancel ボタンがないため、CancelToClose メンバー関数はモードレス プロパティ シートでは何も行いません。

CPropertyPage::QuerySiblings の例を参照してください。

CPropertyPage::Construct

このメンバー関数を呼び出して、 CPropertyPage オブジェクトを構築します。

void Construct(
    UINT nIDTemplate,
    UINT nIDCaption = 0);

void Construct(
    LPCTSTR lpszTemplateName,
    UINT nIDCaption = 0);

void Construct(
    UINT nIDTemplate,
    UINT nIDCaption,
    UINT nIDHeaderTitle,
    UINT nIDHeaderSubTitle = 0);

void Construct(
    LPCTSTR lpszTemplateName,
    UINT nIDCaption,
    UINT nIDHeaderTitle,
    UINT nIDHeaderSubTitle = 0);

パラメーター

nIDTemplate
このページで使用されるテンプレートの ID。

nIDCaption
このページのタブに配置する名前の ID。 0 の場合、このページのダイアログ テンプレートから名前が取得されます。

lpszTemplateName
テンプレート リソースの名前である null で終わる文字列を格納します。

nIDHeaderTitle
プロパティ ページ ヘッダーのタイトルの場所に配置する名前の ID。 既定では 0 です。

nIDHeaderSubTitle
プロパティ ページ ヘッダーのサブタイトルの場所に配置する名前の ID。 既定では 0 です。

解説

オブジェクトは、次のすべての条件が満たされた後に表示されます。

  • ページは、 CPropertySheet::AddPageを使用してプロパティ シートに追加されました。

  • プロパティ シートの DoModal または Create 関数が呼び出されました。

  • ユーザーがこのページを選択 (タブ表示) しています。

他のクラス コンストラクターのいずれかが呼び出されていない場合は、 Construct を呼び出します。 Constructメンバー関数は柔軟です。パラメーター ステートメントを空白のままにし、コード内の任意の時点で複数のパラメーターと構築を指定できます。

配列を操作するときは Construct を使用する必要があります。また、データ メンバーに適切な値が割り当てることができるように、配列の各メンバーに対して Construct を呼び出す必要があります。

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

// Create three CPropertyPage objects whose template IDs are specified
// in rgID array, and add each page to the CPropertySheet object. 
const int c_cPages = 3;
CPropertyPage   pages[c_cPages];
UINT rgID[c_cPages] = { IDD_STYLE, IDD_COLOR, IDD_SHAPE };
for (int i = 0; i < c_cPages; i++)
{
   pages[i].Construct(rgID[i]);
   sheet.AddPage(&pages[i]);
}

// Display a modal CPropertySheet dialog.
sheet.DoModal();

CPropertyPage::CPropertyPage

CPropertyPage オブジェクトを構築します。

CPropertyPage();

explicit CPropertyPage(
    UINT nIDTemplate,
    UINT nIDCaption = 0,
    DWORD dwSize = sizeof(PROPSHEETPAGE));

explicit CPropertyPage(
    LPCTSTR lpszTemplateName,
    UINT nIDCaption = 0,
    DWORD dwSize = sizeof(PROPSHEETPAGE));

CPropertyPage(
    UINT nIDTemplate,
    UINT nIDCaption,
    UINT nIDHeaderTitle,
    UINT nIDHeaderSubTitle = 0,
    DWORD dwSize = sizeof(PROPSHEETPAGE));

CPropertyPage(
    LPCTSTR lpszTemplateName,
    UINT nIDCaption,
    UINT nIDHeaderTitle,
    UINT nIDHeaderSubTitle = 0,
    DWORD dwSize = sizeof(PROPSHEETPAGE));

パラメーター

nIDTemplate
このページで使用されるテンプレートの ID。

nIDCaption
このページのタブに配置する名前の ID。 0 の場合、このページのダイアログ テンプレートから名前が取得されます。

dwSize
lpszTemplateName このページのテンプレートの名前を含む文字列を指します。 NULL にすることはあり得ません。

nIDHeaderTitle
プロパティ ページ ヘッダーのタイトルの場所に配置する名前の ID。

nIDHeaderSubTitle
プロパティ ページ ヘッダーのサブタイトルの場所に配置する名前の ID。

解説

オブジェクトは、次のすべての条件が満たされた後に表示されます。

  • ページは、 CPropertySheet::AddPageを使用してプロパティ シートに追加されました。

  • プロパティ シートの DoModal または Create 関数が呼び出されました。

  • ユーザーがこのページを選択 (タブ表示) しています。

複数のパラメーターがある場合 (配列を使用している場合など)、CPropertyPageの代わりにCPropertySheet::Constructを使用します。

// Declare a CStylePage object, which is a CPropertyPage-derived class.
CStylePage stylePage;

// Declare a CPropertyPage object with IDD_SHAPE, the ID of the 
// template used for this page. 
CPropertyPage shapePage(IDD_SHAPE);

CPropertyPage::GetPSP

CPropertyPage オブジェクトに関連付けられている Windows PROPSHEETPAGE構造体を取得します。

const PROPSHEETPAGE& GetPSP() const;

PROPSHEETPAGE& GetPSP();

戻り値

PROPSHEETPAGE構造体への参照。

CPropertyPage::m_psp

m_psp は、メンバーに PROPSHEETPAGE の特性が格納されている構造体です。

PROPSHEETPAGE m_psp;

解説

この構造体を使用して、構築後にプロパティ ページの外観を初期化します。

メンバーの一覧など、この構造の詳細については、Windows SDK の PROPSHEETPAGE を参照してください。

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

// Change the settings of the three pages to enable property sheet's 
// Help button when the page is active.  CStylePage, CShapePage, and 
// CColorPage are CPropertyPage-derived classes.
CStylePage pageStyle;
pageStyle.m_psp.dwFlags |= PSP_HASHELP;

CColorPage pageColor;
pageColor.m_psp.dwFlags |= PSP_HASHELP;

CShapePage pageShape;
pageShape.m_psp.dwFlags |= PSP_HASHELP;

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

sheet.SetWizardMode();

sheet.DoModal();

CPropertyPage::OnApply

このメンバー関数は、ユーザーが OK または Apply Now ボタンを選択すると、フレームワークによって呼び出されます。

virtual BOOL OnApply();

戻り値

変更を受け入れる場合は 0 以外、それ以外の場合は 0。

解説

フレームワークがこの関数を呼び出すと、プロパティ シート内のすべてのプロパティ ページに加えられた変更が受け入れられ、プロパティ シートはフォーカスを保持し、 OnApplyTRUE (値 1) を返します。 フレームワークによって OnApply 呼び出される前に、 SetModified を呼び出し、そのパラメーターを TRUE に設定する必要があります。 これにより、ユーザーがプロパティ ページを変更するとすぐに [今すぐ適用] ボタンがアクティブになります。

このメンバー関数をオーバーライドして、ユーザーが Apply Now ボタンを選択したときにプログラムが実行するアクションを指定します。 オーバーライドする場合、関数は変更を受け入れるために TRUE を返し、変更が有効にならないように FALSE する必要があります。

OnApply の既定の実装では、OnOK が呼び出されます。

ユーザーがプロパティ シートの Apply Now または OK ボタンを押したときに送信される通知メッセージの詳細については、Windows SDK の PSN_APPLY を参照してください。

CPropertyPage::OnOK の例を参照してください。

CPropertyPage::OnCancel

このメンバー関数は、 Cancel ボタンが選択されたときにフレームワークによって呼び出されます。

virtual void OnCancel();

解説

このメンバー関数をオーバーライドして、 Cancel ボタンのアクションを実行します。 既定値は、行われたすべての変更を否定します。

// Discard any selection the user made to this page.  The object
// in the view will be painted with the initial color when the
// CPropertySheet dialog is first shown. CColorPage is a 
// CPropertyPage-derived class.
void CColorPage::OnCancel()
{
   // Reset the color saved in the document class.  m_InitialColor
   // is a member variable of CColorPage and it is the color shown 
   // in the view before CPropertySheet is shown.
   // doc->m_Color is the color saved in the document class, and 
   // this is the color to be used by the view class.
   CMDIFrameWnd* pFrame = (CMDIFrameWnd*)AfxGetMainWnd();
   CMDIChildWnd* pChild = pFrame->MDIGetActive();
   CPSheetDoc* doc = (CPSheetDoc*)pChild->GetActiveDocument();
   doc->m_Color = m_InitialColor;

   // Tell the view to paint with the initial color.
   CView* view = pChild->GetActiveView();
   view->Invalidate();

   CPropertyPage::OnCancel();
}

// The default MFC implementation of OnReset() would call OnCancel().
void CColorPage::OnReset()
{
   CPropertyPage::OnReset();
}

CPropertyPage::OnKillActive

このメンバー関数は、ページがアクティブページでなくなったときにフレームワークによって呼び出されます。

virtual BOOL OnKillActive();

戻り値

データが正常に更新された場合は 0 以外、それ以外の場合は 0。

解説

特別なデータ検証タスクを実行するには、このメンバー関数をオーバーライドします。

このメンバー関数の既定の実装では、プロパティ ページのコントロールからプロパティ ページのメンバー変数に設定をコピーします。 ダイアログ データ検証 (DDV) エラーが原因でデータが正常に更新されなかった場合、ページはフォーカスを保持します。

このメンバー関数が正常に返されると、フレームワークはページの OnOK 関数を呼び出します。

// Validate the value entered to the "Number" edit control. Its
// value must be at least one. If not, tell the user and set the
// focus to the "Number" edit control. CStylePage is a 
// CPropertyPage-derived class.
BOOL CStylePage::OnKillActive() 
{
   int num = GetDlgItemInt(IDC_NUMOBJECTS);
   if (num <= 0)
   {
      AfxMessageBox(_T("Number of objects must be at least 1."));
      CEdit* edit = (CEdit*) GetDlgItem(IDC_NUMOBJECTS);
      edit->SetFocus();
      edit->SetSel(0, -1);
      return 0;
   }

   return CPropertyPage::OnKillActive();
}

CPropertyPage::OnOK

このメンバー関数は、フレームワークがOnKillActiveを呼び出した直後に、ユーザーが OK または Apply Now ボタンを選択すると、フレームワークによって呼び出されます。

virtual void OnOK();

解説

ユーザーが OK または Apply Now ボタンを選択すると、フレームワークはプロパティ ページから PSN_APPLY 通知を受け取ります。 CPropertySheet::PressButtonを呼び出した場合、OnOKの呼び出しは行われません。その場合、プロパティ ページは通知を送信しないためです。

ユーザーがプロパティ シート全体を閉じるときに、現在アクティブなページに固有の追加の動作を実装するには、このメンバー関数をオーバーライドします。

このメンバー関数の既定の実装では、 OnKillActive 関数でデータが更新されたことを反映するために、ページを "クリーン" としてマークします。

// Accept the new color selection and dismiss the CPropertySheet
// dialog. The view's object will be painted with the new selected
// color. CColorPage is a CPropertyPage-derived class.
void CColorPage::OnOK() 
{
   // Store the new selected color to a member variable of 
   // document class.  m_Color is a member varible of CColorPage 
   // and it stores the new selected color.  doc->m_Color is 
   // the color saved in the document class and it is the color 
   // used by the view class.
   CMDIFrameWnd* pframe = (CMDIFrameWnd*) AfxGetMainWnd();
   CMDIChildWnd* pchild = pframe->MDIGetActive();
   CPSheetDoc* doc = (CPSheetDoc*) pchild->GetActiveDocument();
   doc->m_Color = m_Color;

   // Tell the view to paint with the new selected color.
   CView* view = pchild->GetActiveView();
   view->Invalidate();
  
   CPropertyPage::OnOK();
}

// The default MFC implementation of OnApply() would call OnOK().
BOOL CColorPage::OnApply() 
{
   return CPropertyPage::OnApply();
}

CPropertyPage::OnQueryCancel

このメンバー関数は、ユーザーが Cancel ボタンを選択し、キャンセル アクションが実行される前に、フレームワークによって呼び出されます。

virtual BOOL OnQueryCancel();

戻り値

取り消し操作を禁止する FALSE または許可する TRUE を返します。

解説

ユーザーが Cancel ボタンを選択したときにプログラムが実行するアクションを指定するには、このメンバー関数をオーバーライドします。

OnQueryCancelの既定の実装では、TRUEが返されます。

// Query the user whether to abort the changes if the new selected
// color (m_Color) is different from the initial color 
// (m_InitialColor) when the CPropertySheet dialog is first shown.
// CColorPage is a CPropertyPage-derived class.
BOOL CColorPage::OnQueryCancel() 
{
   if (m_InitialColor != m_Color)
   {
      if (AfxMessageBox(_T("Abort the changes?"), MB_YESNO) == IDNO)
         return FALSE;  
   }

   return CPropertyPage::OnQueryCancel();
}

CPropertyPage::OnReset

このメンバー関数は、ユーザーが Cancel ボタンを選択したときにフレームワークによって呼び出されます。

virtual void OnReset();

解説

フレームワークがこの関数を呼び出すと、以前に Apply Now ボタンを選択したユーザーによって行われたすべてのプロパティ ページに対する変更は破棄され、プロパティ シートはフォーカスを保持します。

ユーザーが Cancel ボタンを選択したときにプログラムが実行するアクションを指定するには、このメンバー関数をオーバーライドします。

OnResetの既定の実装では何も行われません。

CPropertyPage::OnCancel の例を参照してください。

CPropertyPage::OnSetActive

このメンバー関数は、ユーザーがページを選択してアクティブなページになったときに、フレームワークによって呼び出されます。

virtual BOOL OnSetActive();

戻り値

ページが正常にアクティブに設定された場合は 0 以外、それ以外の場合は 0。

解説

ページがアクティブ化されたときにタスクを実行するには、このメンバー関数をオーバーライドします。 このメンバー関数のオーバーライドは、通常、データ メンバーの更新後に既定のバージョンを呼び出して、ページ コントロールを新しいデータで更新できるようにします。

既定の実装では、以前に作成されていない場合はページのウィンドウが作成され、アクティブなページになります。

CPropertySheet::SetFinishText の例を参照してください。

CPropertyPage::OnWizardBack

このメンバー関数は、ユーザーがウィザードで Back ボタンを選択すると、フレームワークによって呼び出されます。

virtual LRESULT OnWizardBack();

戻り値

自動的に次のページに進むには0。ページが変更されないようにするには、-1 を指定します。 次のページ以外のページにジャンプするには、表示するダイアログの識別子を返します。

解説

このメンバー関数をオーバーライドして、 Back ボタンが押されたときにユーザーが実行する必要があるアクションを指定します。

ウィザードタイプのプロパティ シートを作成する方法の詳細については、「 CPropertySheet::SetWizardMode」を参照してください。

// The Back button is selected from the propertysheet.  Get the selected 
// radio button of the page by looping through all buttons on the 
// pages.  m_radioColor is a member variable of 
// CColorPage (a CPropertyPage-derived class).  Its initial value 
// is initialized in OnInitDialog().
LRESULT CColorPage::OnWizardBack()
{
   for (int id = IDC_RADIOBLACK; id <= IDC_RADIOGREEN; id++)
   {
      CButton* button = (CButton*)GetDlgItem(id);
      if (button->GetCheck() == 1)
      {
         m_radioColor = id - IDC_RADIOBLACK;
         break;
      }
   }

   return CPropertyPage::OnWizardBack();
}

CPropertyPage::OnWizardFinish

このメンバー関数は、ユーザーがウィザードで Finish ボタンを選択すると、フレームワークによって呼び出されます。

virtual BOOL OnWizardFinish();

戻り値

ウィザードが完了したときにプロパティ シートが破棄される場合は 0 以外、それ以外の場合は 0。

解説

ユーザーがウィザードで Finish ボタンを選択すると、フレームワークはこの関数を呼び出します。 OnWizardFinishTRUE (0 以外の値) を返すと、プロパティ シートを破棄できます (ただし、実際には破棄されません)。 プロパティ シートを破棄する DestroyWindow を呼び出します。 OnWizardFinishからDestroyWindowを呼び出さないでください。これを行うと、ヒープの破損やその他のエラーが発生します。

このメンバー関数をオーバーライドして、 Finish ボタンが押されたときにユーザーが実行する必要があるアクションを指定できます。 この関数をオーバーライドする場合は、プロパティ シートが破棄されないように、 FALSE を返します。

ユーザーがウィザードのプロパティ シートの [ Finish ] ボタンを押したときに送信される通知メッセージの詳細については、Windows SDK の PSN_WIZFINISH を参照してください。

ウィザードタイプのプロパティ シートを作成する方法の詳細については、「 CPropertySheet::SetWizardMode」を参照してください。

// Inform users regarding the selections they have made by 
// navigating the pages in propertysheet.
BOOL CShapePage::OnWizardFinish()
{
   CString report = _T("You have selected the following options:\n");

   // Get the number of property pages from CPropertySheet.
   CPropertySheet* sheet = (CPropertySheet*)GetParent();
   int count = sheet->GetPageCount();

   // Get the formatted string from each page. This formatted string 
   // will be shown in a message box. Each page knows about the 
   // string to be displayed. For simplicity, we derive a class 
   // from CPropertyPage called CMyPropertyPage. CMyPropertyPage 
   // has a pure virtual member function called GetPageSelections().
   // All pages in the property sheet must be derived from 
   // CMyPropertyPage so we loop through each page to get the 
   // formatted string by calling the GetPageSelections() function.
   for (int i = 0; i < count; i++)
   {
      CMyPropertyPage* page = (CMyPropertyPage*)sheet->GetPage(i);

      CString str;
      page->GetPageSelections(str);
      report += _T("\n") + str;
   }

   AfxMessageBox(report);

   return CPropertyPage::OnWizardFinish();
}

 

// An example of implementing the GetPageSelections() for CStylePage.
// CStylePage is a CMyPropertyPage-derived class, which in turn is a 
// CPropertyPage-derived class.
void CStylePage::GetPageSelections(CString& str)
{
   str.Format(_T("Number of objects to be created = %d"), m_NumObjects);
}

 

// An example of implementing the GetPageSelections() for CColorPage.
// CColorPage is a CMyPropertyPage-derived class, which in turn is a 
// CPropertyPage-derived class.
void CColorPage::GetPageSelections(CString& str)
{
   str = _T("Color selected is ");
   switch (m_Color)
   {
   case RGB(0, 0, 0):
      str += _T("Black");
      break;

   case RGB(255, 0, 0):
      str += _T("Red");
      break;

   case RGB(0, 255, 0):
      str += _T("Green");
      break;

   case RGB(0, 0, 255):
      str += _T("Blue");
      break;

   default:
      str += _T("Custom");
      break;
   }
}

 

// An example of implementing the GetPageSelections() for CShapePage.
// CShapePage is a CMyPropertyPage-derived class, which in turn is a 
// CPropertyPage-derived class.
void CShapePage::GetPageSelections(CString& str)
{
   CString shapename;
   switch (m_Selection)
   {
   case IDC_RECTANGLE:
      shapename = _T("Rectangle");
      break;

   case IDC_ROUND_RECTANGLE:
      shapename = _T("Round Rectangle");
      break;

   case IDC_ELLIPSE:
      shapename = _T("Ellipse");
      break;
   }

   str.Format(_T("Shape to be created is %s"), shapename);
}

CPropertyPage::OnWizardNext

このメンバー関数は、ユーザーがウィザードで Next ボタンを選択すると、フレームワークによって呼び出されます。

virtual LRESULT OnWizardNext();

戻り値

自動的に次のページに進むには0。ページが変更されないようにするには、-1 を指定します。 次のページ以外のページにジャンプするには、表示するダイアログの識別子を返します。

解説

このメンバー関数をオーバーライドして、 Next ボタンが押されたときにユーザーが実行する必要があるアクションを指定します。

ウィザードタイプのプロパティ シートを作成する方法の詳細については、「 CPropertySheet::SetWizardMode」を参照してください。

// The Next button is selected from the propertysheet. Show the 
// second page of the propertysheet ONLY if a non-zero value is 
// entered to the Number edit control of the CStylePage. Otherwise
// display a message to the user and stay on the current page.

LRESULT CStylePage::OnWizardNext()
{
   // Get the number from the edit control
   int num = GetDlgItemInt(IDC_NUMOBJECTS);

   if (num == 0)
   {
      // Display a message to the user
      AfxMessageBox(_T("Supply a non-zero number on the edit control"), MB_OK);

      // Stay on the current page
      return -1;
   }

   // CPropertyPage::OnWizardNext returns zero and causes
   // the property sheet to display the next page
   return CPropertyPage::OnWizardNext();
}

CPropertyPage::QuerySiblings

プロパティ シートの各ページにメッセージを転送するには、このメンバー関数を呼び出します。

LRESULT QuerySiblings(
    WPARAM wParam,
    LPARAM lParam);

パラメーター

wParam
メッセージに依存する追加の情報を指定します。

lParam
メッセージに依存する追加の情報を指定します

戻り値

プロパティ シート内のページの 0 以外の値。すべてのページが値 0 を返す場合は 0。

解説

ページから 0 以外の値が返された場合、プロパティ シートは後続のページにメッセージを送信しません。

// Validate the value entered in the Number edit control. If its 
// value is not a natural number, request CPropertySheet (i.e. parent
// window of the page) to send a PSM_QUERYSIBLINGS message to each
// LOADED page (a page won't be loaded in memory until it is shown).
// If one of the pages returns a nonzero value in response to the 
// PSM_QUERYSIBLINGS message, then inform the user and change the OK
// to Close and disable the Cancel button. CStylePage is a 
// CPropertyPage-derived class.
BOOL CStylePage::OnApply()
{
   int num = GetDlgItemInt(IDC_NUMOBJECTS);
   if (num <= 0)
   {
      if (QuerySiblings(num, 0L))
      {
         AfxMessageBox(_T("Invalid data is entered.  Choose Close ")
            _T("button to close the dialog."));
         CancelToClose();
      }
   }

   return CPropertyPage::OnApply();
}

 

// This is an example of trapping the PSM_QUERYSIBLINGS in one of
// the pages. CColorPage is a CPropertyPage-derived class.  Upon 
// receiving this message, wParam contains the value passed to 
// QuerySiblings() call. CColorPage will check this value and return
// FALSE only if the value is greater than 1.
ON_MESSAGE(PSM_QUERYSIBLINGS, &CColorPage::OnQuerySiblings)

 

LRESULT CColorPage::OnQuerySiblings(WPARAM wParam, LPARAM lParam)
{
   UNREFERENCED_PARAMETER(lParam);
   return (wParam <= 0);
}

CPropertyPage::SetModified

プロパティ ページの設定を適切な外部オブジェクトに適用する必要があるかどうかに基づいて、[今すぐ適用] を有効または無効にするには、このメンバー関数を呼び出します。

void SetModified(BOOL bChanged = TRUE);

パラメーター

bChanged
TRUE プロパティ ページの設定が最後に適用されてから変更されたことを示す場合。 FALSE プロパティ ページの設定が適用されているか、無視する必要があることを示します。

解説

フレームワークは、どのページが "ダーティ" であるか、つまり、 SetModified( TRUE )呼び出したプロパティ ページを追跡します。 いずれかのページで SetModified( TRUE ) を呼び出すと、[今すぐ適用] ボタンは常に有効になります。 いずれかのページで SetModified( FALSE ) を呼び出し、他のページはいずれも "ダーティ" ではない場合にのみ、[今すぐ適用] ボタンは無効になります。

// OnColorClicked() is a member function of CColorPage (a
// CPropertyPage-derived class). It is called whenever a radio button
// is selected on the page. Call SetModified() to enable the Apply 
// button whenever a new selection is made. m_Color is a member
// variable of CColorPage and it is to store the selected RGB color.
// Its entry in the message map looks like this:
// ON_CONTROL_RANGE(BN_CLICKED, IDC_BLACK, IDC_GREEN, CColorPage::OnColorClicked)
void CColorPage::OnColorClicked(UINT nCmdID)
{
   COLORREF color = m_Color;
   switch (nCmdID)
   {
   case IDC_RADIOBLACK:
      color = RGB(0, 0, 0);
      m_radioColor = crBlack;
      break;

   case IDC_RADIORED:
      color = RGB(255, 0, 0);
      m_radioColor = crRed;
      break;

   case IDC_RADIOGREEN:
      color = RGB(0, 255, 0);
      m_radioColor = crGreen;
      break;

   case IDC_RADIOBLUE:
      color = RGB(0, 0, 255);
      m_radioColor = crBlue;
      break;
   }

   if (color != m_Color)
   {
      m_Color = color;
      SetModified();    // Enable Apply Now button.
   }

   UpdateData(FALSE);
}

関連項目

MFC サンプル CMNCTRL1
MFC サンプル CMNCTRL2
MFC サンプル PROPDLG
MFC サンプル SNAPVW
CDialog クラス
階層図
CPropertySheet クラス