Example #1
0
void OptionsPageMore::updateHasChanged()
{
	if (m_oldSettings == m_newSettings)
	{
		PropSheet_UnChanged(GetParent(m_hwnd), m_hwnd);
	}
	else {
		PropSheet_Changed(GetParent(m_hwnd), m_hwnd);
	}
}
static void CheckEnableApply()
{
    BOOL bEnable = FALSE;
	
    bEnable = (bFsRunning != bFsOn) || (bDbRunning != bDbOn) || (bBakRunning != bBakOn) ||
	(bScsRunning != bScsOn) || (bSccRunning != bSccOn);

    if (bEnable)
	PropSheet_Changed(GetParent(hDlg), hDlg);
    else
	PropSheet_UnChanged(GetParent(hDlg), hDlg);
}	
Example #3
0
/* This function handles the WM_NOTIFY message.
 */ 
LRESULT FASTCALL RASBlinkProperties_OnNotify( HWND hwnd, int code, LPNMHDR lpnmhdr )
{
   switch( lpnmhdr->code )
      {
      case PSN_HELP:
         HtmlHelp( hwnd, szHelpFile, HH_HELP_CONTEXT, idsBLINK_RAS );
         break;

      case PSN_APPLY: {
         LPBLINKENTRY lpbe;
         HWND hwndTab;

         /* Update the blink entry structure.
          */
         lpbe = (LPBLINKENTRY)GetWindowLong( hwnd, DWL_USER );
         hwndTab = PropSheet_GetTabControl( GetParent( hwnd ) );
         if( !TabCtrl_GetEnable( hwndTab, idRasTab ) )
            lpbe->rd.fUseRAS = FALSE;
         else
            lpbe->rd.fUseRAS = IsDlgButtonChecked( hwnd, IDD_USERAS );

         /* If we use RAS, we'll need the entry name.
          */
         if( lpbe->rd.fUseRAS )
            {
            HWND hwndList;

            /* Get the entry name.
             */
            hwndList = GetDlgItem( hwnd, IDD_LIST );
            ComboBox_GetText( hwndList, lpbe->rd.szRASEntryName, RAS_MaxEntryName+1 );

            /* Get username and password.
             */
            Edit_GetText( GetDlgItem( hwnd, IDD_USERNAME ), lpbe->rd.szRASUserName, UNLEN+1 );
            Edit_GetText( GetDlgItem( hwnd, IDD_PASSWORD ), lpbe->rd.szRASPassword, PWLEN+1 );
            if( ( strlen( lpbe->rd.szRASEntryName ) == 0 ) || ( strlen( lpbe->rd.szRASUserName ) == 0 ) || ( strlen( lpbe->rd.szRASPassword ) == 0 ) )
            {
               fMessageBox( hwnd, 0, GS(IDS_STR1242), MB_OK|MB_ICONEXCLAMATION );
               return( PSNRET_INVALID_NOCHANGEPAGE );
            }
            Amuser_Encrypt( lpbe->rd.szRASPassword, rgEncodeKey );
            }

         /* Force the Apply button to be disabled.
          */
         PropSheet_UnChanged( GetParent( hwnd ), hwnd );
         return( PSNRET_NOERROR );
         }
      }
   return( FALSE );
}
Example #4
0
/* Property page dialog callback */
INT_PTR CALLBACK
AdvancedPageProc(HWND hwndDlg,
                 UINT uMsg,
                 WPARAM wParam,
                 LPARAM lParam)
{
    PGLOBALDATA pGlobalData;

    pGlobalData = (PGLOBALDATA)GetWindowLongPtr(hwndDlg, DWLP_USER);

    switch (uMsg)
    {
        case WM_INITDIALOG:
            pGlobalData = (PGLOBALDATA)((LPPROPSHEETPAGE)lParam)->lParam;
            SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);

            InitLanguagesList(hwndDlg, pGlobalData);
            InitCodePagesList(hwndDlg);
            break;

        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
                case IDC_LANGUAGE_COMBO:
                    if (HIWORD(wParam) == CBN_SELCHANGE)
                    {
                        LCID lcid;
                        INT iIndex;

                        iIndex = SendMessage(hLangList, CB_GETCURSEL, 0, 0);
                        if (iIndex == CB_ERR)
                            break;

                        lcid = SendMessage(hLangList, CB_GETITEMDATA, iIndex, 0);
                        if (lcid == (LCID)CB_ERR)
                            break;

                        pGlobalData->SystemLCID = lcid;

                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
                    }
                    break;

                case IDC_APPLY_CUR_USER_DEF_PROFILE:
                    if (HIWORD(wParam) == BN_CLICKED)
                    {
                        if (SendDlgItemMessageW(hwndDlg, IDC_APPLY_CUR_USER_DEF_PROFILE, BM_GETCHECK, 0, 0))
                        {
                            ResourceMessageBox(hwndDlg,
                                               MB_OK | MB_ICONWARNING,
                                               IDS_APPLY_DEFAULT_TITLE,
                                               IDS_APPLY_DEFAULT_TEXT);
                            pGlobalData->bApplyToDefaultUser = TRUE;
                        }
                        else
                        {
                            pGlobalData->bApplyToDefaultUser = FALSE;
                        }

                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
                    }
                    break;
            }
            break;

        case WM_NOTIFY:
        {
            LPNMHDR lpnm = (LPNMHDR)lParam;

            if (lpnm->code == (UINT)PSN_APPLY)
            {
                PropSheet_UnChanged(GetParent(hwndDlg), hwndDlg);

                SaveSystemSettings(pGlobalData);
                SaveFontSubstitutionSettings(hwndDlg, pGlobalData);
                SaveFontLinkingSettings(hwndDlg, pGlobalData);
            }
        }
        break;
    }

    return FALSE;
}
Example #5
0
/* Property page dialog callback */
INT_PTR CALLBACK
GeneralPageProc(HWND hwndDlg,
                UINT uMsg,
                WPARAM wParam,
                LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_INITDIALOG:
            CreateLanguagesList(GetDlgItem(hwndDlg, IDC_LANGUAGELIST));
            UpdateLocaleSample(hwndDlg, LOCALE_USER_DEFAULT);
            CreateLocationsList(GetDlgItem(hwndDlg, IDC_LOCATION_COMBO));
            if (IsUnattendedSetupEnabled)
            {
                if (VerifyUnattendLCID(hwndDlg))
                {
                    SetNewLocale(UnattendLCID);
                    PostQuitMessage(0);
                }
                return TRUE;
            }
            break;

        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
                case IDC_LANGUAGELIST:
                    if (HIWORD(wParam) == CBN_SELCHANGE)
                    {
                        LCID NewLcid;
                        INT iCurSel;

                        iCurSel = SendMessage(hList,
                                              CB_GETCURSEL,
                                              0,
                                              0);
                        if (iCurSel == CB_ERR)
                            break;

                        NewLcid = SendMessage(hList,
                                              CB_GETITEMDATA,
                                              iCurSel,
                                              0);
                        if (NewLcid == (LCID)CB_ERR)
                            break;

                        UpdateLocaleSample(hwndDlg, NewLcid);

                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
                    }
                    break;

                case IDC_LOCATION_COMBO:
                    if (HIWORD(wParam) == CBN_SELCHANGE)
                    {
                        PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
                    }
                    break;
                case IDC_SETUP_BUTTON:
                    {
                        LCID NewLcid;
                        INT iCurSel;

                        iCurSel = SendMessage(hList,
                                              CB_GETCURSEL,
                                              0,
                                              0);
                        if (iCurSel == CB_ERR)
                            break;

                        NewLcid = SendMessage(hList,
                                              CB_GETITEMDATA,
                                              iCurSel,
                                              0);
                        if (NewLcid == (LCID)CB_ERR)
                            break;

                         SetupApplet(GetParent(hwndDlg), NewLcid);
                    }
                    break;
            }
            break;

        case WM_NOTIFY:
            {
                LPNMHDR lpnm = (LPNMHDR)lParam;

                if (lpnm->code == (UINT)PSN_APPLY)
                {
                    /* Apply changes */
                    LCID NewLcid;
                    GEOID NewGeoID;
                    INT iCurSel;

                    PropSheet_UnChanged(GetParent(hwndDlg), hwndDlg);

                    /* Acquire new value */
                    iCurSel = SendMessage(hList,
                                          CB_GETCURSEL,
                                          0,
                                          0);
                    if (iCurSel == CB_ERR)
                        break;

                    NewLcid = SendMessage(hList,
                                          CB_GETITEMDATA,
                                          iCurSel,
                                          0);
                    if (NewLcid == (LCID)CB_ERR)
                        break;

                    iCurSel = SendMessage(GetDlgItem(hwndDlg, IDC_LOCATION_COMBO),
                                          CB_GETCURSEL,
                                          0,
                                          0);
                    if (iCurSel == CB_ERR)
                        break;

                    NewGeoID = SendMessage(GetDlgItem(hwndDlg, IDC_LOCATION_COMBO),
                                           CB_GETITEMDATA,
                                           iCurSel,
                                           0);
                    if (NewGeoID == (GEOID)CB_ERR)
                        break;

                    /* Set new locale */
                    SetNewLocale(NewLcid);
                    AddNewKbLayoutsByLcid(NewLcid);
                    SetUserGeoID(NewGeoID);
                    SetNonUnicodeLang(hwndDlg, NewLcid);
                }
            }
            break;
    }

    return FALSE;
}
Example #6
0
/*++

Routine Name:

    CDocPropPage::DlgProc

Routine Description:

    Dialog proccedure for the property page.
    This handles all windows messages that are sent to the property page.

Arguments:

    hDlg - Handle of the property page.
    uiMessage - Specifies the message.
    wParam - Specifies additional message-specific information.
    lParam - Specifies additional message-specific information.

Return Value:

    The return value is the result of the message processing and depends on the message sent.

--*/
INT_PTR CALLBACK
CDocPropPage::DlgProc(
    __in CONST HWND   hDlg,
    __in CONST UINT   uiMessage,
    __in CONST WPARAM wParam,
    __in CONST LPARAM lParam
    )
{
    HRESULT hr = S_OK;
    BOOL retVal = FALSE;

    switch (uiMessage)
    {
        case WM_INITDIALOG:
        {
            //
            // Store the class instance
            //
            PROPSHEETPAGE* pPage = reinterpret_cast<PROPSHEETPAGE*>(lParam);

            if (SUCCEEDED(hr = CHECK_POINTER(pPage, E_POINTER)))
            {
                if (pPage->lParam != NULL)
                {
                    CDocPropPage* thisInst = reinterpret_cast<CDocPropPage*>(pPage->lParam);

                    if (SUCCEEDED(hr = CHECK_POINTER(thisInst, E_FAIL)))
                    {
                        if (SUCCEEDED(hr = thisInst->StoreThis(hDlg)))
                        {
                            hr = thisInst->SendInit(hDlg);
                        }
                    }
                }
                else
                {
                    hr = E_FAIL;
                }
            }

            //
            // Set the keyboard focus to the control specified by wParam
            //
            retVal = TRUE;
        }
        break;

        case WM_COMMAND:
        {
            switch (HIWORD(wParam))
            {
                case EN_CHANGE:
                case BN_CLICKED:
                case CBN_SELCHANGE:
                // case LBN_SELCHANGE: CBN_SELCHANGE=LBN_SELCHANGE
                {
                    CDocPropPage* thisInst;

                    if (SUCCEEDED(hr = RetrieveThis(hDlg, &thisInst)))
                    {
                        if (SUCCEEDED(hr = CHECK_POINTER(thisInst, E_FAIL)))
                        {
                            hr = thisInst->SendCommand(hDlg, wParam);
                        }
                    }

                    //
                    // Set to FALSE to indiate that the message has been handled.
                    //
                    retVal = FALSE;
                }
                break;

                default:
                {
                    //
                    // Unhandled command so return TRUE
                    //
                    retVal = TRUE;
                }
                break;
            }
        }
        break;

        case WM_NOTIFY:
        {
            NMHDR* pHdr = reinterpret_cast<NMHDR*>(lParam);
            if (SUCCEEDED(hr = CHECK_POINTER(pHdr, E_POINTER)))
            {
                switch (pHdr->code)
                {
                    case PSN_SETACTIVE:
                    {
                        CDocPropPage* thisInst;

                        if (SUCCEEDED(hr = RetrieveThis(hDlg, &thisInst)) &&
                            SUCCEEDED(hr = CHECK_POINTER(thisInst, E_FAIL)))
                        {
                            hr = thisInst->SendSetActive(hDlg);
                        }

                        //
                        // Return FALSE to accept the page activation
                        //
                        retVal = FALSE;
                    }
                    break;

                    case PSN_KILLACTIVE:
                    {
                        //
                        // Return FALSE to allow the page to lose activation
                        //
                        retVal = FALSE;
                    }
                    break;

                    case PSN_APPLY:
                    {
                        PFNCOMPROPSHEET pfnComPropSheet = NULL;

                        CDocPropPage* thisInst;

                        if (SUCCEEDED(hr = RetrieveThis(hDlg, &thisInst)) &&
                            SUCCEEDED(hr = CHECK_POINTER(thisInst, E_FAIL)) &&
                            SUCCEEDED(hr = thisInst->GetComPropSheetFunc(&pfnComPropSheet)) &&
                            SUCCEEDED(hr = CHECK_POINTER(pfnComPropSheet, E_FAIL)))
                        {
                            //
                            // Ensure that the last error is in a known state.
                            //
                            SetLastError(0);

                            //
                            // We do not need to validate any settings so set PSNRET_NOERROR
                            //
                            if (SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR) == 0)
                            {
                                //
                                // A return value of 0 does not necessarily indicate a failure.
                                //
                                hr = HRESULT_FROM_WIN32(GetLastError());
                            }

                            if (SUCCEEDED(hr))
                            {
                                //
                                // We have applied the change...
                                //
                                PropSheet_UnChanged(GetParent(hDlg), hDlg);

                                //
                                // Inform the propsheet
                                //
                                pfnComPropSheet(thisInst->GetComPropSheetHandle(),
                                                CPSFUNC_SET_RESULT,
                                                reinterpret_cast<LPARAM>(thisInst->GetPageHandle()),
                                                (LPARAM)CPSUI_OK);
                            }
                        }

                        retVal = TRUE;
                    }
                    break;

                    case UDN_DELTAPOS:
                    {
                        CDocPropPage* thisInst;

                        if (SUCCEEDED(hr = RetrieveThis(hDlg, &thisInst)) &&
                            SUCCEEDED(hr = CHECK_POINTER(thisInst, E_FAIL)))
                        {
                            hr = thisInst->SendNotify(hDlg, pHdr);
                        }

                        //
                        // Set return to FALSE to allow the control value
                        //
                        retVal = FALSE;
                    }
                    break;
                }
            }
        }
        break;

        case WM_NCDESTROY:
        {
            CDocPropPage* thisInst;

            if (SUCCEEDED(hr = CDocPropPage::RetrieveThis(hDlg, &thisInst)) &&
                SUCCEEDED(hr = CHECK_POINTER(thisInst, E_FAIL)))
            {
                hr = thisInst->RemoveThis(hDlg);
            }

            //
            // Set return to FALSE to indicate that the message was processed
            //
            retVal = FALSE;
        }
        break;
    }

    ERR_ON_HR(hr);
    return retVal;
}
Example #7
0
INT_PTR CALLBACK
ToolsPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
        {
            hToolsPage     = hDlg;
            hToolsListCtrl = GetDlgItem(hToolsPage, IDC_TOOLS_LIST);

            //
            // Initialize the styles.
            //
            DWORD dwStyle = ListView_GetExtendedListViewStyle(hToolsListCtrl);
            ListView_SetExtendedListViewStyle(hToolsListCtrl, dwStyle | LVS_EX_FULLROWSELECT);
            SetWindowTheme(hToolsListCtrl, L"Explorer", NULL);

            //
            // Initialize the application page's controls.
            //
            LVCOLUMN column = {};

            // First column : Tool's name.
            column.mask = LVCF_TEXT | LVCF_WIDTH;
            column.pszText = LoadResourceString(hInst, IDS_TOOLS_COLUMN_NAME);
            column.cx = 150;
            ListView_InsertColumn(hToolsListCtrl, 0, &column);
            MemFree(column.pszText);

            // Second column : Whether the tool is a standard one or not.
            column.mask = LVCF_TEXT | LVCF_WIDTH;
            column.pszText = LoadResourceString(hInst, IDS_TOOLS_COLUMN_STANDARD);
            column.cx = 60;
            ListView_InsertColumn(hToolsListCtrl, 1, &column);
            MemFree(column.pszText);

            // Third column : Description.
            column.mask = LVCF_TEXT | LVCF_WIDTH;
            column.pszText = LoadResourceString(hInst, IDS_TOOLS_COLUMN_DESCR);
            column.cx = 500;
            ListView_InsertColumn(hToolsListCtrl, 2, &column);
            MemFree(column.pszText);

            //
            // Populate and sort the list.
            //
            FillListView();
            ListView_Sort(hToolsListCtrl, 0);

            // Force an update in case of an empty list (giving focus on it when empty won't emit a LVN_ITEMCHANGED message).
            Update_States(-1 /* Wrong index to initialize all the controls with their default state (i.e. disabled) */);

            PropSheet_UnChanged(GetParent(hToolsPage), hToolsPage);

            return TRUE;
        }

        case WM_DESTROY:
        {
            LVITEM lvitem = {};
            lvitem.mask  = LVIF_PARAM;
            lvitem.iItem = -1; // From the beginning.

            while ((lvitem.iItem = ListView_GetNextItem(hToolsListCtrl, lvitem.iItem, LVNI_ALL)) != -1)
            {
                // ListView_Update();   // Updates a list-view item.
                // ListView_FindItem(); // peut être intéressant pour faire de la recherche itérative à partir du nom (ou partie du...) de l'item.

                ListView_GetItem(hToolsListCtrl, &lvitem);

                delete reinterpret_cast<TOOL*>(lvitem.lParam);
                lvitem.lParam = NULL;
            }
            ListView_DeleteAllItems(hToolsListCtrl);

            return 0;
        }

        case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
                case IDC_BTN_RUN:
                {
                    RunSelectedTool();
                    return TRUE;
                }

                case IDC_CBX_TOOLS_ADVOPT:
                {
                    Update_States(ListView_GetSelectionMark(hToolsListCtrl));
                    return TRUE;
                }

                default:
                    return FALSE;
            }
            return FALSE;
        }

        case WM_NOTIFY:
        {
            if (((LPNMHDR)lParam)->hwndFrom == hToolsListCtrl)
            {
                switch (((LPNMHDR)lParam)->code)
                {
                    case LVN_ITEMCHANGED:
                    {
                        if ( (((LPNMLISTVIEW)lParam)->uChanged  & LVIF_STATE) && /* The state has changed */
                             (((LPNMLISTVIEW)lParam)->uNewState & LVIS_SELECTED) /* The item has been (de)selected */ )
                        {
                            Update_States(((LPNMLISTVIEW)lParam)->iItem);
                        }

                        return TRUE;
                    }

                    case NM_DBLCLK:
                    case NM_RDBLCLK:
                    {
                        RunSelectedTool();
                        return TRUE;
                    }

                    case LVN_COLUMNCLICK:
                    {
                        int iSortingColumn = ((LPNMLISTVIEW)lParam)->iSubItem;

                        ListView_SortEx(hToolsListCtrl, iSortingColumn, iToolsPageSortedColumn);
                        iToolsPageSortedColumn = iSortingColumn;

                        return TRUE;
                    }

                    default:
                        break;
                }
            }
            else
            {
                switch (((LPNMHDR)lParam)->code)
                {
                    case PSN_APPLY:
                    {
                        // Since there are nothing to modify, applying modifications
                        // cannot return any error.
                        SetWindowLongPtr(hToolsPage, DWLP_MSGRESULT, PSNRET_NOERROR);
                        PropSheet_UnChanged(GetParent(hToolsPage), hToolsPage);
                        return TRUE;
                    }

                    case PSN_HELP:
                    {
                        MessageBoxW(hToolsPage, L"Help not implemented yet!", L"Help", MB_ICONINFORMATION | MB_OK);
                        return TRUE;
                    }

                    case PSN_KILLACTIVE: // Is going to lose activation.
                    {
                        // Changes are always valid of course.
                        SetWindowLongPtr(hToolsPage, DWLP_MSGRESULT, FALSE);
                        return TRUE;
                    }

                    case PSN_QUERYCANCEL:
                    {
                        // Allows cancellation since there are nothing to cancel...
                        SetWindowLongPtr(hToolsPage, DWLP_MSGRESULT, FALSE);
                        return TRUE;
                    }

                    case PSN_QUERYINITIALFOCUS:
                    {
                        // Give the focus on and select the first item.
                        ListView_SetItemState(hToolsListCtrl, 0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);

                        SetWindowLongPtr(hToolsPage, DWLP_MSGRESULT, (LONG_PTR)hToolsListCtrl);
                        return TRUE;
                    }

                    //
                    // DO NOT TOUCH THESE NEXT MESSAGES, THEY ARE OK LIKE THIS...
                    //
                    case PSN_RESET: // Perform final cleaning, called before WM_DESTROY.
                        return TRUE;

                    case PSN_SETACTIVE: // Is going to gain activation.
                    {
                        SetWindowLongPtr(hToolsPage, DWLP_MSGRESULT, 0);
                        return TRUE;
                    }

                    default:
                        break;
                }
            }

            return FALSE;
        }

        default:
            return FALSE;
    }

    // return FALSE;
}
Example #8
0
INT_PTR CALLBACK
PrintSizeDlgProc(HWND hdlg, UINT wmsg, WPARAM wparam, LPARAM lparam)
{
    TCHAR buf[8];
    HWND hPropSheetDlg = GetParent(hdlg);
    GP_LPPRINT lpr = (GP_LPPRINT) GetWindowLongPtr(hdlg, GWLP_USERDATA);

    switch (wmsg) {
    case WM_INITDIALOG:
	lpr = (GP_LPPRINT) ((PROPSHEETPAGE *) lparam)->lParam;
	SetWindowLongPtr(hdlg, GWLP_USERDATA, (LONG_PTR) lpr);
	wsprintf(buf, TEXT("%d"), lpr->pdef.x);
	SetDlgItemText(hdlg, PSIZE_DEFX, buf);
	wsprintf(buf, TEXT("%d"), lpr->pdef.y);
	SetDlgItemText(hdlg, PSIZE_DEFY, buf);
	wsprintf(buf, TEXT("%d"), lpr->poff.x);
	SetDlgItemText(hdlg, PSIZE_OFFX, buf);
	wsprintf(buf, TEXT("%d"), lpr->poff.y);
	SetDlgItemText(hdlg, PSIZE_OFFY, buf);
	wsprintf(buf, TEXT("%d"), lpr->psize.x);
	SetDlgItemText(hdlg, PSIZE_X, buf);
	wsprintf(buf, TEXT("%d"), lpr->psize.y);
	SetDlgItemText(hdlg, PSIZE_Y, buf);
	CheckDlgButton(hdlg, PSIZE_DEF, TRUE);
	EnableWindow(GetDlgItem(hdlg, PSIZE_X), FALSE);
	EnableWindow(GetDlgItem(hdlg, PSIZE_Y), FALSE);
	return TRUE;
    case WM_COMMAND:
	switch (LOWORD(wparam)) {
	case PSIZE_DEF:
	    if (HIWORD(wparam) == BN_CLICKED) {
		EnableWindow(GetDlgItem(hdlg, PSIZE_X), FALSE);
		EnableWindow(GetDlgItem(hdlg, PSIZE_Y), FALSE);
		PropSheet_Changed(hPropSheetDlg, hdlg);
	    }
	    return FALSE;
	case PSIZE_OTHER:
	    if (HIWORD(wparam) == BN_CLICKED) {
		EnableWindow(GetDlgItem(hdlg, PSIZE_X), TRUE);
		EnableWindow(GetDlgItem(hdlg, PSIZE_Y), TRUE);
		PropSheet_Changed(hPropSheetDlg, hdlg);
	    }
	    return FALSE;
	case PSIZE_X:
	case PSIZE_Y:
	case PSIZE_OFFX:
	case PSIZE_OFFY:
	    if (HIWORD(wparam) == EN_UPDATE)
		PropSheet_Changed(hPropSheetDlg, hdlg);
	    return FALSE;
	} /* switch (wparam) */
	break;
    case WM_NOTIFY:
	switch (((LPNMHDR) lparam)->code) {
	case PSN_APPLY:  /* apply changes */
	    /* FIXME: Need to check for valid input.
	    */
	    if (SendDlgItemMessage(hdlg, PSIZE_OTHER, BM_GETCHECK, 0, 0L)) {
		SendDlgItemMessage(hdlg, PSIZE_X, WM_GETTEXT, 7, (LPARAM) buf);
		GetInt(buf, (LPINT)&lpr->psize.x);
		SendDlgItemMessage(hdlg, PSIZE_Y, WM_GETTEXT, 7, (LPARAM) buf);
		GetInt(buf, (LPINT)&lpr->psize.y);
	    } else {
		lpr->psize.x = lpr->pdef.x;
		lpr->psize.y = lpr->pdef.y;
	    }
	    SendDlgItemMessage(hdlg, PSIZE_OFFX, WM_GETTEXT, 7, (LPARAM) buf);
	    GetInt(buf, (LPINT)&lpr->poff.x);
	    SendDlgItemMessage(hdlg, PSIZE_OFFY, WM_GETTEXT, 7, (LPARAM) buf);
	    GetInt(buf, (LPINT)&lpr->poff.y);

	    if (lpr->psize.x <= 0)
		lpr->psize.x = lpr->pdef.x;
	    if (lpr->psize.y <= 0)
		lpr->psize.y = lpr->pdef.y;

	    PropSheet_UnChanged(hPropSheetDlg, hdlg);
	    SetWindowLongPtr(hdlg, DWLP_MSGRESULT, PSNRET_NOERROR);
	    return TRUE;
	}
	case PSN_SETACTIVE: /* display: intialize according to printer */
	    if (lpr->psize.x < 0 || lpr->bDriverChanged) {
		/* FIXME: also if settings changed (paper size, orientation) */
		IPrintDialogServices * services = (IPrintDialogServices *) lpr->services;

		/* Set size to full paper size of current printer */
		if (services) {
		    LPTSTR lpPrinterName = NULL;
		    LPTSTR lpPortName = NULL;
		    LPDEVMODE lpDevMode = NULL;
		    UINT size;
		    HRESULT hr;

		    /* Note:  The Windows 8.1 SDK says that these functions expect LPWSTR
			      arguments, in contrast to the MSDN documentation, MinGW, and
			      what was actually seen in a debugger on Windows 10.
			      So warnings about type mismatch can be safely ignored.
		    */
		    size = 0;
		    hr = services->lpVtbl->GetCurrentPrinterName(services, NULL, &size);
		    if (SUCCEEDED(hr) && size > 0) {
			lpPrinterName = (LPTSTR) malloc(size * sizeof(TCHAR));
			hr = services->lpVtbl->GetCurrentPrinterName(services, lpPrinterName, &size);
		    }

		    size = 0;
		    hr = services->lpVtbl->GetCurrentPortName(services, NULL, &size);
		    if (SUCCEEDED(hr) && size > 0) {
			lpPortName = (LPTSTR) malloc(size * sizeof(TCHAR));
			hr = services->lpVtbl->GetCurrentPortName(services, lpPortName, &size);
		    }

		    size = 0;
		    hr = services->lpVtbl->GetCurrentDevMode(services, NULL, &size);
		    if (SUCCEEDED(hr) && size > 0) {
			lpDevMode = (LPDEVMODE) malloc(size * sizeof(TCHAR));
			hr = services->lpVtbl->GetCurrentDevMode(services, lpDevMode, &size);
		    }

		    if (SUCCEEDED(hr) && size > 0 && lpPortName != NULL && lpPrinterName != NULL) {
			HDC printer = CreateDC(TEXT("WINSPOOL"), lpPrinterName, lpPortName, lpDevMode);
			lpr->psize.x = GetDeviceCaps(printer, HORZSIZE);
			lpr->psize.y = GetDeviceCaps(printer, VERTSIZE);
			DeleteDC(printer);
		    }

		    free(lpPrinterName);
		    free(lpPortName);
		    free(lpDevMode);
		}
	    }
	    if (lpr->psize.x < 0) {
		/* something went wrong */
		lpr->psize.x = lpr->pdef.x;
		lpr->psize.y = lpr->pdef.y;
	    }
	    /* apply changes */
	    wsprintf(buf, TEXT("%d"), lpr->psize.x);
	    SetDlgItemText(hdlg, PSIZE_X, buf);
	    wsprintf(buf, TEXT("%d"), lpr->psize.y);
	    SetDlgItemText(hdlg, PSIZE_Y, buf);
	    lpr->bDriverChanged = FALSE;

	    SetWindowLongPtr(hdlg, DWLP_MSGRESULT, 0); /* accept activation */
	    return TRUE;
	break;
    } /* switch (msg) */
    return FALSE;
}