Partager via


Implement a Dialog Box Procedure for Each Property Page

This topic discusses how to implement Step 5 of the procedure, "To extend a primary snap-in property sheet", from the Microsoft Management Console (MMC) topic, Extending the Property Sheet of a Primary Snap-in.

To implement a dialog box procedure for each property page, the pfnDlgProc member of each property page PROPSHEETPAGE structure should be set to the address of this procedure.

Code Example

In the following code example that creates a property sheet, the pfnDlgProc member of the property page is set to the address of the dialog box procedure, DialogProc. The pszTemplate member of the property page is set to the resource definition of the dialog box UI features, IDD_PROPPAGE_LARGE, which includes a checkbox with a label of Setting.

   if ( SUCCEEDED( hr ) )
   {
      if ( bAddPage )
      {
         PROPSHEETPAGE psp;
         HPROPSHEETPAGE hPage = NULL;

         psp.dwSize = sizeof(PROPSHEETPAGE);
         psp.dwFlags = PSP_DEFAULT | PSP_HASHELP; 
            // | PSP_USETITLE; // | PSP_USEICONID;
         psp.hInstance = g_hinst;
         psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGE_LARGE);
         psp.pfnDlgProc = DialogProc;
         psp.lParam = reinterpret_cast<LPARAM>(this);
         psp.pszTitle = NULL; // MAKEINTRESOURCE(IDS_TAB_GENERAL);
         psp.pszIcon = NULL; // MAKEINTRESOURCE(IDI_ICON_GENERAL);

         hPage = CreatePropertySheetPage(&amp;psp);

         _ASSERT(hPage);

         hr = lpProvider->AddPage(hPage);
      }
   }

The dialog box procedure is defined in the full code example in AppExt.cpp. The following code example shows initialization of the dialog box.

      case WM_INITDIALOG:
      {
         // Enable Windows themes:
         InitCommonControls();

         if ( pThis == NULL )
         {
            // Invalid parent object pointer! exit! abort!
            EndDialog( hwndDlg, IDABORT );
            
            break;
         }         

         //
         // TODO: Get properties data:
         //

         //
         // An example of a checkbox value:
         //
                  
         IXMLDOMNode* pElmExampleProp = NULL;

         // find the "Reg" property element:
         HRESULT hr = pThis->m_pXmlDom->selectSingleNode( 
            L"/Application/Properties/Reg[@id='exampleSetting']", 
            &amp;pElmExampleProp );
         
         if ( hr == S_OK )
         {
            BSTR bstrValue;
            
            // Get the registry property value:
            GetAttribute( pElmExampleProp, _T( "value" ), bstrValue );

            int nResult = _wcsicmp( bstrValue, _T( "1" ) );
            
            bool bChecked =  ( nResult == STRING_MATCH );

            // Set the state of the control:
            CheckDlgButton( hwndDlg, IDC_CHECK1, 
               bChecked ? BST_CHECKED : BST_UNCHECKED ); 

            pElmExampleProp->Release();
            ::SysFreeString(bstrValue);
         }
         else
         {
            // Set the default state of the control:
            CheckDlgButton( hwndDlg, IDC_CHECK1, BST_UNCHECKED ); 
         } 
         
         break;
      }