EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

#Previous question #Index of VC++/WIN32/MFC Questions #Next question

Overview

We have seen example of CPropertySheet and CPropertyPage class in our previous topic. However that was high level object oriented approach to implement a property sheet project. MFC OOP makes easy to implement these but the abstruction always hides the lower mechanism.

Here we are going to explore the lower layer data structures behind those classes.

PropertySheet

PropertySheet() is the main function to create a the main Property Sheet dialog. Creates a property sheet and adds the pages defined in the specified property sheet header structure.

INT_PTR PropertySheet(
   LPCPROPSHEETHEADER lppsph
);

Parameters

  • lppsph -Pointer to a PROPSHEETHEADER structure that defines the frame and pages of a property sheet.

Return value

For modal property sheets, the return value is as follows:

  • >=1 Changes were saved by the user.
  • 0 No changes were saved by the user.
  • -1 An error occurred.

PROPSHEETHEADER

PROPSHEETHEADER is the main structure to pass to PropertySheet() function. This structure contains main dialog attributes like title, dialog precedure, number of property pages, default start page index and pointer to one or more property pages. Property page pointer sould point to an array of page objects which are the attributes of individual pages.

typedef struct {
  DWORD                dwSize;     /* Size of the struct */
  DWORD                dwFlags;    /* Flag for diff members */
  HWND                 hwndParent;  /* Parent of this property sheet */
  HINSTANCE            hInstance;   /* App instance handle */
  union {
    HICON  hIcon;               /* Icon handle */
    LPCSTR pszIcon;             /* Icon name */
  };
  LPCTSTR              pszCaption;  /* Dialog caption */
  UINT                 nPages;      /* Number of pages */
  union {
    UINT    nStartPage;              /* Index of start page */
    LPCTSTR pStartPage;              /* start page as string */
  };
  union {
    LPCPROPSHEETPAGE ppsp;           /* array of property page descriptors */
    HPROPSHEETPAGE   *phpage;        /* array of property page handles */
  };
  PFNPROPSHEETCALLBACK pfnCallback;   /* Callback function pointer */
#if (_WIN32_IE >= 0x0400)
  union {
    HBITMAP hbmWatermark;
    LPCTSTR pszbmWatermark;
  };
  HPALETTE             hplWatermark;
  union {
    HBITMAP hbmHeader;
    LPCSTR  pszbmHeader;
  };
#endif 
} PROPSHEETHEADER, *LPPROPSHEETHEADER;

PROPSHEETPAGE structure

PROPSHEETPAGE is the structure to hold the attributes of individual pages. This structure contains attributes like dialog resource, title string, icon, dialog precedure. Programmers should populate all the necessary fields of the property pages. Programmer should also provide an array of this page objects when constructing PROPSHEETHEADER object for calling PropertySheet().

typedef struct {
  DWORD           dwSize;       /* Size of the struct */
  DWORD           dwFlags;      /* Flag for diff members */
  HINSTANCE       hInstance;    /* App instance handle */
  union {
    LPCSTR         pszTemplate; /* Resource template name */
    LPCDLGTEMPLATE pResource;   /* User constructed Resource */
  };
  union {
    HICON  hIcon;               /* Icon handle */
    LPCSTR pszIcon;             /* Icon name */
  };
  LPCSTR          pszTitle;          /* Title string */
  DLGPROC         pfnDlgProc;        /* Dialog presedure */
  LPARAM          lParam;            /* Dialog LPARAM */
  LPFNPSPCALLBACK pfnCallback;       /* Callback function pointer */
  UINT            *pcRefParent;
#if (_WIN32_IE >= 0x0500)
  LPCTSTR         pszHeaderTitle;
  LPCTSTR         pszHeaderSubTitle;
#endif 
#if (_WIN32_WINNT >= 0x0501)
  HANDLE          hActCtx;
#endif 
} PROPSHEETPAGE, *LPPROPSHEETPAGE;

PropertySheetPage functions

Property page objects can be passed as array or as the handle. There are few Property page related APIs to create and delete handle to property page.

CreatePropertySheetPage function

Creates a new page handle for a property sheet from the object of type PROPSHEETPAGE.

Syntax

HPROPSHEETPAGE CreatePropertySheetPage(
   LPCPROPSHEETPAGE lppsp
);

Return

Handle to the property page. An array of property page handle can be attached to PROPSHEETHEADER for creation of property sheet.

DestroyPropertySheetPage function

Destroys a property sheet page object corresponding to the handle given as input. An application must call this function to free the resource pointed by the handle. This is needed when property sheet dialog is closed and propery page is no longer needed.

Syntax

BOOL DestroyPropertySheetPage(
   HPROPSHEETPAGE hPSPage
);

Source code

VOID DoPropertySheet(HWND hwndOwner)
{
    PROPSHEETPAGE psp[2];
    
    PROPSHEETHEADER psh;
    
    psp[0].dwSize      = sizeof(PROPSHEETPAGE);
    psp[0].dwFlags     = PSP_USEICONID | PSP_USETITLE;
    psp[0].hInstance   = g_hinst;
10      psp[0].pszTemplate = MAKEINTRESOURCE(DLG_FONT);
11      psp[0].pszIcon     = MAKEINTRESOURCE(IDI_FONT);
12      psp[0].pfnDlgProc  = FontDialogProc;
13      psp[0].pszTitle    = MAKEINTRESOURCE(IDS_FONT)
14      psp[0].lParam      = 0;
15      psp[0].pfnCallback = NULL;
16    
17    
18      psp[1].dwSize      = sizeof(PROPSHEETPAGE);
19      psp[1].dwFlags     = PSP_USEICONID | PSP_USETITLE;
20      psp[1].hInstance   = g_hinst;
21      psp[1].pszTemplate = MAKEINTRESOURCE(DLG_BORDER);
22      psp[1].pszIcon     = MAKEINTRESOURCE(IDI_BORDER);
23      psp[1].pfnDlgProc  = BorderDialogProc;
24      psp[1].pszTitle    = MAKEINTRESOURCE(IDS_BORDER);
25      psp[1].lParam      = 0;
26      psp[1].pfnCallback = NULL;
27      
28      psh.dwSize      = sizeof(PROPSHEETHEADER);
29      psh.dwFlags     = PSH_USEICONID | PSH_PROPSHEETPAGE;
30      psh.hwndParent  = hwndOwner;
31      psh.hInstance   = g_hinst;
32      psh.pszIcon     = MAKEINTRESOURCE(IDI_CELL_PROPERTIES);
33      psh.pszCaption  = (LPSTR) "Cell Properties";
34      psh.nPages      = sizeof(psp) / sizeof(PROPSHEETPAGE);
35      psh.nStartPage  = 0;
36      psh.ppsp        = (LPCPROPSHEETPAGE) &psp;
37      psh.pfnCallback = NULL;
38      
39      PropertySheet(&psh);
40      
41      return;
42  }

You have viewed 1 page out of 109. Your VC++ learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

#Programming Windows, Fifth Edition (Developer Reference)
#Programming Applications for Microsoft Windows (Microsoft Programming Series)
#Programming Windows with MFC, Second Edition
#Visual C++ Programming
#Programming Microsoft Visual C++, Fifth Edition

* #1 webmaster Sun 27 Apr/2014 06:20:22(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.

Regards,
Webmaster

Your message goes here:

Name:Guest
Email:anonymous@unknown.com
My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
 
Note:
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.