• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 526
  • Last Modified:

Property Sheet

I want to use Property Sheets. Can someone please write a simple Property Sheet example. I just need a simple source codes to start with.
0
redhat092798
Asked:
redhat092798
1 Solution
 
BudVVeezerCommented:
In MFC or just straight C?  C++?

~Aaron
0
 
cyberbumCommented:
This should help you get started:

CPropertySheet * pSheet = new CPropertySheet;

pSheet->Construct("My Sheet", pParentWnd);
// In your resource editor, construct a few dialogs that will be used for each page in the property sheet

// Construct your pages
CPropertyPage * pPage = new CPropertyPage;
pPage->Construct(IDD_YOURDIALOG);
pSheet->AddPage(pPage);
pSheet->DoModal();
0
 
redhat092798Author Commented:
In Plain C API
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
wyllikerCommented:
While this code snippet wouldn't be relevant to your specific application you should be able to get the idea.

Read up on the PROPSHEETPAGE, and PROPSHEETHEADER structure docs as well as the CreatePropertySheetPage and PropertySheet function docs.

In my example below I am creating a four page property sheet.

Note that I am using a variable called ThisInstance - this is the value of hInstance that was passed into WinMain.

Also, I am passing a parameter to each dialog as it is created - (LPARAM) PPCriteria - which you may not need to do depending on your requirements

Here goes ...
--------------

#define PAGE_TERMS      0
#define PAGE_CUSTOMER   1
#define PAGE_PPORDER    2
#define PAGE_HELP       3

#define TOTAL_PAGES     4


PROPSHEETPAGE  Page[TOTAL_PAGES];
HPROPSHEETPAGE hPage[TOTAL_PAGES];
PROPSHEETHEADER PropSheetHeader;

    memset(&PropSheetHeader, 0, sizeof(PROPSHEETHEADER));
    memset(&Page, 0, TOTAL_PAGES * sizeof(PROPSHEETPAGE));

    Page[PAGE_TERMS].dwSize = sizeof(PROPSHEETPAGE);
    Page[PAGE_TERMS].hInstance = ThisInstance;
    Page[PAGE_TERMS].pszTemplate = MAKEINTRESOURCE(IDD_TERMS);
    Page[PAGE_TERMS].pfnDlgProc = TermsDlgProc;
    Page[PAGE_TERMS].lParam = (LPARAM) PPCriteria;
    hPage[PAGE_TERMS] = CreatePropertySheetPage((PROPSHEETPAGE *) &Page[PAGE_TERMS]);

    Page[PAGE_CUSTOMER].dwSize = sizeof(PROPSHEETPAGE);
    Page[PAGE_CUSTOMER].hInstance = ThisInstance;
    Page[PAGE_CUSTOMER].pszTemplate = MAKEINTRESOURCE(IDD_CUSTOMER);
    Page[PAGE_CUSTOMER].pfnDlgProc = CustomerDlgProc;
    Page[PAGE_CUSTOMER].lParam = (LPARAM) PPCriteria;
    hPage[PAGE_CUSTOMER] = CreatePropertySheetPage((PROPSHEETPAGE *) &Page[PAGE_CUSTOMER]);

    Page[PAGE_PPORDER].dwSize = sizeof(PROPSHEETPAGE);
    Page[PAGE_PPORDER].hInstance = ThisInstance;
    Page[PAGE_PPORDER].pszTemplate = MAKEINTRESOURCE(IDD_PPORDER);
    Page[PAGE_PPORDER].pfnDlgProc = PPOrderDlgProc;
    Page[PAGE_PPORDER].lParam = (LPARAM) PPCriteria;
    hPage[PAGE_PPORDER] = CreatePropertySheetPage((PROPSHEETPAGE *) &Page[PAGE_PPORDER]);

    Page[PAGE_HELP].dwSize = sizeof(PROPSHEETPAGE);
    Page[PAGE_HELP].hInstance = ThisInstance;
    Page[PAGE_HELP].pszTemplate = MAKEINTRESOURCE(IDD_HELP);
    Page[PAGE_HELP].pfnDlgProc = HelpDlgProc;
    Page[PAGE_HELP].lParam = (LPARAM) PPCriteria;
    hPage[PAGE_HELP] = CreatePropertySheetPage((PROPSHEETPAGE *) &Page[PAGE_HELP]);

    PropSheetHeader.dwSize = sizeof(PROPSHEETHEADER);
    PropSheetHeader.dwFlags = PSH_NOAPPLYNOW;
    PropSheetHeader.hwndParent = HWND_DESKTOP;
    PropSheetHeader.hInstance = ThisInstance;
    PropSheetHeader.pszCaption = "Prospect Profile";
    PropSheetHeader.nPages = TOTAL_PAGES;
    PropSheetHeader.nStartPage = PAGE_TERMS;
    PropSheetHeader.phpage = (HPROPSHEETPAGE *) &hPage;

    PropertySheet(&PropSheetHeader);




0
 
wyllikerCommented:
I want to make this clear ...

(LPARAM) PPCriteria

.... is a pointer to my own defined structure that all of the pages share so that the data collected on each page can be updated in a central place.

This is not part of Property Pages but part of my implementation.
0
 
wyllikerCommented:
Here is the Property sheet dialog handler for the PAGE_ORDER (IDD_ORDER) page ....

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

static PCRITERIA Criteria = (PCRITERIA) NULL;


BOOL CALLBACK PPOrderDlgProc ( HWND hwndDlg,    UINT Message,
                               WPARAM wParam, LPARAM lParam )
{
LRESULT RC = 0;
PPROPSHEETPAGE PropSheetPage = (PPROPSHEETPAGE) NULL;
NMHDR * pNotification = (NMHDR *) NULL;
unsigned int TextLen = 0;
LOGBRUSH LogBrush;

    switch(Message)
    {
        case WM_INITDIALOG:
             PropSheetPage = (PPROPSHEETPAGE) lParam;
             Criteria = (PCRITERIA) PropSheetPage->lParam;
             return (LRESULT) 1;
             break;

        case WM_CTLCOLORSTATIC:
             if(GetWindowLong((HWND) lParam, GWL_ID) == IDC_COPYRIGHTMSG)
             {
                 SetTextColor((HDC) wParam, 0x000000FF);
                 SetBkColor((HDC) wParam, GetBkColor((HDC) wParam));
                 SetBkMode((HDC) wParam, TRANSPARENT);
                 LogBrush.lbStyle = BS_SOLID;
                 LogBrush.lbColor = GetSysColor(COLOR_3DFACE);
                 return (BOOL) CreateBrushIndirect(&LogBrush);
             }
             else
                 return FALSE;

        case WM_NOTIFY:
             pNotification = (NMHDR *) lParam;
             if(pNotification->code == PSN_KILLACTIVE)
             {
                 TextLen = GetDlgItemText(hwndDlg,IDC_PROSPECTNAME,
                                          &Criteria->ProspectName[0], MAXLEN_PROSPECTNAME);

                 if(TextLen)
                     Criteria->fProspectInformation = 1;

                 TextLen = GetDlgItemText(hwndDlg, IDC_PROSPECTADDRESS,
                                          Criteria->ProspectAddress, MAXLEN_PROSPECTADDRESS);

                 if(TextLen)
                     Criteria->fProspectInformation = 1;

                 TextLen = GetDlgItemText(hwndDlg, IDC_PROSPECTCITY,
                                          Criteria->ProspectCity, MAXLEN_PROSPECTCITY);

                 if(TextLen)
                     Criteria->fProspectInformation = 1;

                 TextLen = GetDlgItemText(hwndDlg, IDC_PROSPECTSTATE,
                                          Criteria->ProspectState, MAXLEN_PROSPECTSTATE);

                 if(TextLen)
                     Criteria->fProspectInformation = 1;

                 TextLen = GetDlgItemText(hwndDlg, IDC_PROSPECTZIP,
                                          Criteria->ProspectZip, MAXLEN_PROSPECTZIP);

                 if(TextLen)
                     Criteria->fProspectInformation = 1;

                 TextLen = GetDlgItemText(hwndDlg, IDC_PROSPECTTELEPHONE,
                                          Criteria->ProspectTelephone, MAXLEN_PROSPECTTELEPHONE);

                 if(TextLen)
                     Criteria->fProspectInformation = 1;
                 
                 TextLen = GetDlgItemText(hwndDlg, IDC_PROSPECTPRODUCTORSERVICE,
                                          Criteria->ProspectProductOrService, MAXLEN_PROSPECTPRODUCTORSERVICE);
                 if(TextLen)
                     Criteria->fProspectInformation = 1;

               
                 SetWindowLong(hwndDlg, DWL_MSGRESULT, (LONG) FALSE);
                 return (LRESULT) TRUE;
             }
             else
             if(pNotification->code == PSN_APPLY)
             {
                 SendToDB(hwndDlg, Criteria);
                 return (LRESULT) TRUE;
             }
             break;
    }

    return (LRESULT) 0;
}
0
 
redhat092798Author Commented:
thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now