How to handle results from a PropertySheet?

95 views Asked by At

I find different examples in the Internet of how to program a PropertySheet in WinAPI, but they are not complete. The code I am using is shown below. I have a PropertySheet with 3 Tabs, each one with a Dialog. The different Dialogs are called, when I click the Tabs, so far it is working. However, when I leave the PropertySheet pressing OK button, how do I get the contents in the Textboxes etc. of each Dialog? Normally I used to do that in the DialogProc when WM_COMMAND/IDOK was received using: GetDlgItemText( hDlg,IDC_TEXTBOX1, buf, 100); But in the PropertySheet there is only one OK Button for all dialogs, no WM_COMMAND/IDOK is received in the DialogProc. What shall I do?

Resource_file:

IDD_DIALOG_1 DIALOGEX 0, 0, 385, 186
    STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    BEGIN
        LTEXT           "param",IDC_STATIC,6,23,39,10
        EDITTEXT        IDC_TEXTBOX1,48,20,237,15
    END

C Source:

LRESULT CALLBACK
Dialog1(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
char buf[500];
char* ptr;
int p; // =lParam, rin of edited person
int f;
    switch (message)
    {
        case WM_INITDIALOG:
        {
            SetDlgItemText(hDlg, IDC_TEXTBOX1, "something");
            return 0; 
        }

        case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
            case IDOK: // never reached (OK Button belongs to the PropertySheet!)
            }
        }
    }
    return FALSE;
} /* Dialog1 */

INT_PTR DoPropertySheet(HWND hwndOwner, LPARAM p)
{
    PROPSHEETPAGE psp[3];

    PROPSHEETHEADER psh;

    memset(psp,0,sizeof(psp));

    for(int i=0;i<3; i++)
    {
        psp[i].dwSize      = sizeof(PROPSHEETPAGE);
        psp[i].dwFlags = PSP_USETITLE;
        psp[i].hInstance   = hInstance;
        psp[i].lParam      = p;
    }
    psp[0].pszTemplate = MAKEINTRESOURCE(IDD_DIALOG_1);
    psp[0].pfnDlgProc  = (DLGPROC)Dialog1;
    psp[1].pszTemplate = MAKEINTRESOURCE(IDD_DIALOG_2);
    psp[1].pfnDlgProc  = (DLGPROC)Dialog2;
    psp[2].pszTemplate = MAKEINTRESOURCE(IDD_DIALOG_3);
    psp[2].pfnDlgProc  = (DLGPROC)Dialog3;

    psh.dwSize      = sizeof(PROPSHEETHEADER);
    psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
    psh.hwndParent  = hwndOwner;
    psh.hInstance   = hInstance;
    psh.pszIcon     = 0;
    psh.nPages      = sizeof(psp) / sizeof(PROPSHEETPAGE);
    psh.nStartPage  = 0;
    psh.ppsp        = (LPCPROPSHEETPAGE) &psp;
    psh.pfnCallback = NULL;

    if (PropertySheet(&psh)) // 0:cancel, otherwise:1
    {
       //get contens of propertySheet here?? how??
    }
    return 0;
}
1

There are 1 answers

0
RbMm On BEST ANSWER

when user press OK or Apply all your pages got PSN_APPLY notification code. so you need look for WM_NOTIFY with PSN_APPLY code

when user press cancel you got PSN_RESET notification

INT_PTR CALLBACK PPDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
    union {
        LPARAM lp;
        NMHDR* hdr;
        PSHNOTIFY* psn;
    };

    switch (umsg)
    {
    case WM_NOTIFY:
        lp = lParam;
        switch (hdr->code)
        {
        case PSN_APPLY:
            DbgPrint("apply");
            break;
        case PSN_RESET:
            DbgPrint("cancel\n");
            break;
        }
        break;
    }
    return 0;
}