ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

deskadp.c
Go to the documentation of this file.
00001 #include "precomp.h"
00002 
00003 #define NDEBUG
00004 #include <debug.h>
00005 
00006 static HINSTANCE hInstance;
00007 
00008 typedef INT_PTR (WINAPI *PDEVICEPROPERTIESW)(HWND,LPCWSTR,LPCWSTR,BOOL);
00009 
00010 static VOID
00011 GetColorDescription(PDEVMODEW lpDevMode,
00012                     LPTSTR lpBuffer,
00013                     DWORD dwBufferLen)
00014 {
00015     UINT uid = 0;
00016 
00017     switch (lpDevMode->dmBitsPerPel)
00018     {
00019         case 4:
00020             uid = IDS_4BPP;
00021             break;
00022         case 8:
00023             uid = IDS_8BPP;
00024             break;
00025         case 15:
00026             uid = IDS_15BPP;
00027             break;
00028         case 16:
00029             uid = IDS_16BPP;
00030             break;
00031         case 24:
00032             uid = IDS_24BPP;
00033             break;
00034         case 32:
00035             uid = IDS_32BPP;
00036             break;
00037     }
00038 
00039     if (uid == 0 ||
00040         !LoadString(hInstance,
00041                     uid,
00042                     lpBuffer,
00043                     dwBufferLen))
00044     {
00045         lpBuffer[0] = TEXT('\0');
00046     }
00047 }
00048 
00049 static VOID
00050 GetRefreshRateDescription(PDEVMODEW lpDevMode,
00051                           LPTSTR lpBuffer,
00052                           DWORD dwBufferLen)
00053 {
00054     TCHAR szFormat[64];
00055 
00056     if (lpDevMode->dmDisplayFrequency <= 1)
00057     {
00058         if (!LoadString(hInstance,
00059                         IDS_DEFREFRESHRATE,
00060                         lpBuffer,
00061                         dwBufferLen))
00062         {
00063             lpBuffer[0] = TEXT('\0');
00064         }
00065     }
00066     else
00067     {
00068         if (!LoadString(hInstance,
00069                         IDES_REFRESHRATEFMT,
00070                         szFormat,
00071                         sizeof(szFormat) / sizeof(szFormat[0])))
00072         {
00073             szFormat[0] = TEXT('\0');
00074         }
00075 
00076         _sntprintf(lpBuffer,
00077                    dwBufferLen,
00078                    szFormat,
00079                    lpDevMode->dmDisplayFrequency);
00080     }
00081 }
00082 
00083 static VOID
00084 InitListAllModesDialog(PDESKDISPLAYADAPTER This,
00085                        HWND hwndListAllModesDlg)
00086 {
00087     TCHAR szFormat[64], szBuffer[64], szColors[64], szRefreshRate[64];
00088     PDEVMODEW lpDevMode, lpCurrentDevMode;
00089     DWORD dwIndex = 0;
00090     INT i;
00091 
00092     if (This->DeskExtInterface != NULL)
00093     {
00094         if (!LoadString(hInstance,
00095                         IDS_MODEFMT,
00096                         szFormat,
00097                         sizeof(szFormat) / sizeof(szFormat[0])))
00098         {
00099             szFormat[0] = TEXT('\0');
00100         }
00101 
00102         lpCurrentDevMode = This->DeskExtInterface->GetCurrentMode(This->DeskExtInterface->Context);
00103 
00104         do
00105         {
00106             lpDevMode = This->DeskExtInterface->EnumAllModes(This->DeskExtInterface->Context,
00107                                                              dwIndex++);
00108             if (lpDevMode != NULL)
00109             {
00110                 GetColorDescription(lpDevMode,
00111                                     szColors,
00112                                     sizeof(szColors) / sizeof(szColors[0]));
00113 
00114                 GetRefreshRateDescription(lpDevMode,
00115                                           szRefreshRate,
00116                                           sizeof(szRefreshRate) / sizeof(szRefreshRate[0]));
00117 
00118                 _sntprintf(szBuffer,
00119                            sizeof(szBuffer) / sizeof(szBuffer[0]),
00120                            szFormat,
00121                            lpDevMode->dmPelsWidth,
00122                            lpDevMode->dmPelsHeight,
00123                            szColors,
00124                            szRefreshRate);
00125 
00126                 i = (INT)SendDlgItemMessage(hwndListAllModesDlg,
00127                                             IDC_ALLVALIDMODES,
00128                                             LB_ADDSTRING,
00129                                             0,
00130                                             (LPARAM)szBuffer);
00131                 if (i >= 0)
00132                 {
00133                     SendDlgItemMessage(hwndListAllModesDlg,
00134                                        IDC_ALLVALIDMODES,
00135                                        LB_SETITEMDATA,
00136                                        (WPARAM)i,
00137                                        (LPARAM)lpDevMode);
00138 
00139                     if (lpDevMode == lpCurrentDevMode)
00140                     {
00141                         SendDlgItemMessage(hwndListAllModesDlg,
00142                                            IDC_ALLVALIDMODES,
00143                                            LB_SETCURSEL,
00144                                            (WPARAM)i,
00145                                            0);
00146                     }
00147                 }
00148             }
00149 
00150         } while (lpDevMode != NULL);
00151     }
00152 }
00153 
00154 static BOOL
00155 ChangeSelectedMode(PDESKDISPLAYADAPTER This,
00156                    HWND hwndListAllModesDlg)
00157 {
00158     INT i;
00159     PDEVMODEW lpSelDevMode = NULL;
00160     BOOL bRet = FALSE;
00161 
00162     i = (INT)SendDlgItemMessage(hwndListAllModesDlg,
00163                                 IDC_ALLVALIDMODES,
00164                                 LB_GETCURSEL,
00165                                 0,
00166                                 0);
00167 
00168     if (i >= 0)
00169     {
00170         lpSelDevMode = (PDEVMODEW)SendDlgItemMessage(hwndListAllModesDlg,
00171                                                      IDC_ALLVALIDMODES,
00172                                                      LB_GETITEMDATA,
00173                                                      (WPARAM)i,
00174                                                      0);
00175     }
00176 
00177     if (lpSelDevMode != NULL)
00178     {
00179         This->lpSelDevMode = lpSelDevMode;
00180         bRet = TRUE;
00181     }
00182 
00183     return bRet;
00184 }
00185 
00186 static INT_PTR CALLBACK
00187 ListAllModesDlgProc(HWND hwndDlg,
00188                     UINT uMsg,
00189                     WPARAM wParam,
00190                     LPARAM lParam)
00191 {
00192     PDESKDISPLAYADAPTER This;
00193     INT_PTR Ret = 0;
00194 
00195     if (uMsg != WM_INITDIALOG)
00196     {
00197         This = (PDESKDISPLAYADAPTER)GetWindowLongPtr(hwndDlg,
00198                                                      DWL_USER);
00199     }
00200 
00201     switch (uMsg)
00202     {
00203         case WM_INITDIALOG:
00204             This = (PDESKDISPLAYADAPTER)lParam;
00205             SetWindowLongPtr(hwndDlg,
00206                              DWL_USER,
00207                              (LONG_PTR)This);
00208 
00209             InitListAllModesDialog(This,
00210                                    hwndDlg);
00211             Ret = TRUE;
00212             break;
00213 
00214         case WM_COMMAND:
00215             switch (LOWORD(wParam))
00216             {
00217                 case IDOK:
00218                     if (ChangeSelectedMode(This,
00219                                            hwndDlg))
00220                     {
00221                         EndDialog(hwndDlg,
00222                                   IDOK);
00223                     }
00224                     break;
00225 
00226                 case IDCANCEL:
00227                     EndDialog(hwndDlg,
00228                               IDCANCEL);
00229                     break;
00230             }
00231             break;
00232 
00233         case WM_CLOSE:
00234             EndDialog(hwndDlg,
00235                       IDCANCEL);
00236             break;
00237     }
00238 
00239     return Ret;
00240 }
00241 
00242 static VOID
00243 ShowListAllModes(PDESKDISPLAYADAPTER This)
00244 {
00245     PDEVMODEW lpPrevSel;
00246 
00247     lpPrevSel = This->lpSelDevMode;
00248 
00249     if (This->DeskExtInterface != NULL &&
00250         DialogBoxParam(hInstance,
00251                        MAKEINTRESOURCE(IDD_LISTALLMODES),
00252                        This->hwndDlg,
00253                        ListAllModesDlgProc,
00254                        (LPARAM)This) == IDOK)
00255     {
00256         if (lpPrevSel != This->lpSelDevMode)
00257         {
00258             (void)PropSheet_Changed(GetParent(This->hwndDlg),
00259                                     This->hwndDlg);
00260             This->DeskExtInterface->SetCurrentMode(This->DeskExtInterface->Context,
00261                                                    This->lpSelDevMode);
00262         }
00263     }
00264 }
00265 
00266 static VOID
00267 ShowAdapterProperties(PDESKDISPLAYADAPTER This)
00268 {
00269     HMODULE hDevMgr;
00270     PDEVICEPROPERTIESW pDevicePropertiesW;
00271 
00272     hDevMgr = LoadLibrary(TEXT("devmgr.dll"));
00273     if (hDevMgr != NULL)
00274     {
00275         pDevicePropertiesW = (PDEVICEPROPERTIESW)GetProcAddress(hDevMgr,
00276                                                                 "DevicePropertiesW");
00277         if (pDevicePropertiesW != NULL)
00278         {
00279             pDevicePropertiesW(This->hwndDlg,
00280                                NULL,
00281                                This->lpDeviceId,
00282                                FALSE);
00283         }
00284 
00285         FreeLibrary(hDevMgr);
00286     }
00287 }
00288 
00289 static VOID
00290 InitDisplayAdapterDialog(PDESKDISPLAYADAPTER This)
00291 {
00292     LPTSTR lpAdapterName;
00293 
00294     This->lpDeviceId = QueryDeskCplString(This->pdtobj,
00295                                           RegisterClipboardFormat(DESK_EXT_DISPLAYID));
00296     EnableWindow(GetDlgItem(This->hwndDlg,
00297                             IDC_ADAPTERPROPERTIES),
00298                  This->lpDeviceId != NULL && This->lpDeviceId[0] != TEXT('\0'));
00299     lpAdapterName = QueryDeskCplString(This->pdtobj,
00300                                        RegisterClipboardFormat(DESK_EXT_DISPLAYNAME));
00301     if (lpAdapterName != NULL)
00302     {
00303         SetDlgItemText(This->hwndDlg,
00304                        IDC_ADAPTERNAME,
00305                        lpAdapterName);
00306 
00307         LocalFree((HLOCAL)lpAdapterName);
00308     }
00309 
00310     if (This->DeskExtInterface != NULL)
00311     {
00312         SetDlgItemTextW(This->hwndDlg,
00313                         IDC_CHIPTYPE,
00314                         This->DeskExtInterface->ChipType);
00315         SetDlgItemTextW(This->hwndDlg,
00316                         IDC_DACTYPE,
00317                         This->DeskExtInterface->DacType);
00318         SetDlgItemTextW(This->hwndDlg,
00319                         IDC_MEMORYSIZE,
00320                         This->DeskExtInterface->MemorySize);
00321         SetDlgItemTextW(This->hwndDlg,
00322                         IDC_ADAPTERSTRING,
00323                         This->DeskExtInterface->AdapterString);
00324         SetDlgItemTextW(This->hwndDlg,
00325                         IDC_BIOSINFORMATION,
00326                         This->DeskExtInterface->BiosString);
00327 
00328         This->lpDevModeOnInit = This->DeskExtInterface->GetCurrentMode(This->DeskExtInterface->Context);
00329     }
00330     else
00331         This->lpDevModeOnInit = NULL;
00332 
00333     This->lpSelDevMode = This->lpDevModeOnInit;
00334 }
00335 
00336 static LONG
00337 ApplyDisplayAdapterChanges(PDESKDISPLAYADAPTER This)
00338 {
00339     LONG lChangeRet;
00340 
00341     if (This->DeskExtInterface != NULL)
00342     {
00343         /* Change the display settings through desk.cpl */
00344         lChangeRet = DeskCplExtDisplaySaveSettings(This->DeskExtInterface,
00345                                                    This->hwndDlg);
00346         if (lChangeRet == DISP_CHANGE_SUCCESSFUL)
00347         {
00348             /* Save the new mode */
00349             This->lpDevModeOnInit = This->DeskExtInterface->GetCurrentMode(This->DeskExtInterface->Context);
00350             This->lpSelDevMode = This->lpDevModeOnInit;
00351             return PSNRET_NOERROR;
00352         }
00353         else if (lChangeRet == DISP_CHANGE_RESTART)
00354         {
00355             /* Notify desk.cpl that the user needs to reboot */
00356             PropSheet_RestartWindows(GetParent(This->hwndDlg));
00357             return PSNRET_NOERROR;
00358         }
00359     }
00360 
00361     return PSNRET_INVALID_NOCHANGEPAGE;
00362 }
00363 
00364 static VOID
00365 ResetDisplayAdapterChanges(PDESKDISPLAYADAPTER This)
00366 {
00367     if (This->DeskExtInterface != NULL && This->lpDevModeOnInit != NULL)
00368     {
00369         This->DeskExtInterface->SetCurrentMode(This->DeskExtInterface->Context,
00370                                                This->lpDevModeOnInit);
00371     }
00372 }
00373 
00374 static INT_PTR CALLBACK
00375 DisplayAdapterDlgProc(HWND hwndDlg,
00376                       UINT uMsg,
00377                       WPARAM wParam,
00378                       LPARAM lParam)
00379 {
00380     PDESKDISPLAYADAPTER This;
00381     INT_PTR Ret = 0;
00382 
00383     if (uMsg != WM_INITDIALOG)
00384     {
00385         This = (PDESKDISPLAYADAPTER)GetWindowLongPtr(hwndDlg,
00386                                                      DWL_USER);
00387     }
00388 
00389     switch (uMsg)
00390     {
00391         case WM_INITDIALOG:
00392             This = (PDESKDISPLAYADAPTER)((LPCPROPSHEETPAGE)lParam)->lParam;
00393             This->hwndDlg = hwndDlg;
00394             SetWindowLongPtr(hwndDlg,
00395                              DWL_USER,
00396                              (LONG_PTR)This);
00397 
00398             InitDisplayAdapterDialog(This);
00399             Ret = TRUE;
00400             break;
00401 
00402         case WM_COMMAND:
00403             switch (LOWORD(wParam))
00404             {
00405                 case IDC_ADAPTERPROPERTIES:
00406                     ShowAdapterProperties(This);
00407                     break;
00408 
00409                 case IDC_LISTALLMODES:
00410                     ShowListAllModes(This);
00411                     break;
00412             }
00413 
00414             break;
00415 
00416         case WM_NOTIFY:
00417         {
00418             NMHDR *nmh = (NMHDR *)lParam;
00419 
00420             switch (nmh->code)
00421             {
00422                 case PSN_APPLY:
00423                 {
00424                     SetWindowLongPtr(hwndDlg,
00425                                      DWL_MSGRESULT,
00426                                      ApplyDisplayAdapterChanges(This));
00427                     break;
00428                 }
00429 
00430                 case PSN_RESET:
00431                     ResetDisplayAdapterChanges(This);
00432                     break;
00433             }
00434             break;
00435         }
00436     }
00437 
00438     return Ret;
00439 }
00440 
00441 static VOID
00442 IDeskDisplayAdapter_Destroy(PDESKDISPLAYADAPTER This)
00443 {
00444     if (This->pdtobj != NULL)
00445     {
00446         IDataObject_Release(This->pdtobj);
00447         This->pdtobj = NULL;
00448     }
00449 
00450     if (This->DeskExtInterface != NULL)
00451     {
00452         LocalFree((HLOCAL)This->DeskExtInterface);
00453         This->DeskExtInterface = NULL;
00454     }
00455 
00456     if (This->lpDeviceId != NULL)
00457     {
00458         LocalFree((HLOCAL)This->lpDeviceId);
00459         This->lpDeviceId = NULL;
00460     }
00461 }
00462 
00463 ULONG
00464 IDeskDisplayAdapter_AddRef(PDESKDISPLAYADAPTER This)
00465 {
00466     ULONG ret;
00467 
00468     ret = InterlockedIncrement((PLONG)&This->ref);
00469     if (ret == 1)
00470         InterlockedIncrement(&dll_refs);
00471 
00472     return ret;
00473 }
00474 
00475 ULONG
00476 IDeskDisplayAdapter_Release(PDESKDISPLAYADAPTER This)
00477 {
00478     ULONG ret;
00479 
00480     ret = InterlockedDecrement((PLONG)&This->ref);
00481     if (ret == 0)
00482     {
00483         IDeskDisplayAdapter_Destroy(This);
00484         InterlockedDecrement(&dll_refs);
00485 
00486         HeapFree(GetProcessHeap(),
00487                  0,
00488                  This);
00489     }
00490 
00491     return ret;
00492 }
00493 
00494 HRESULT STDMETHODCALLTYPE
00495 IDeskDisplayAdapter_QueryInterface(PDESKDISPLAYADAPTER This,
00496                                    REFIID iid,
00497                                    PVOID *pvObject)
00498 {
00499     *pvObject = NULL;
00500 
00501     if (IsEqualIID(iid,
00502                    &IID_IShellPropSheetExt) ||
00503         IsEqualIID(iid,
00504                    &IID_IUnknown))
00505     {
00506         *pvObject = impl_to_interface(This, IShellPropSheetExt);
00507     }
00508     else if (IsEqualIID(iid,
00509                         &IID_IShellExtInit))
00510     {
00511         *pvObject = impl_to_interface(This, IShellExtInit);
00512     }
00513     else if (IsEqualIID(iid,
00514                         &IID_IClassFactory))
00515     {
00516         *pvObject = impl_to_interface(This, IClassFactory);
00517     }
00518     else
00519     {
00520         DPRINT1("IDeskDisplayAdapter::QueryInterface(%p,%p): E_NOINTERFACE\n", iid, pvObject);
00521         return E_NOINTERFACE;
00522     }
00523 
00524     IDeskDisplayAdapter_AddRef(This);
00525     return S_OK;
00526 }
00527 
00528 HRESULT
00529 IDeskDisplayAdapter_Initialize(PDESKDISPLAYADAPTER This,
00530                                LPCITEMIDLIST pidlFolder,
00531                                IDataObject *pdtobj,
00532                                HKEY hkeyProgID)
00533 {
00534     DPRINT1("IDeskDisplayAdapter::Initialize(%p,%p,%p)\n", pidlFolder, pdtobj, hkeyProgID);
00535 
00536     if (pdtobj != NULL)
00537     {
00538         IDataObject_AddRef(pdtobj);
00539         This->pdtobj = pdtobj;
00540 
00541         /* Get a copy of the desk.cpl extension interface */
00542         This->DeskExtInterface = QueryDeskCplExtInterface(This->pdtobj);
00543         if (This->DeskExtInterface != NULL)
00544             return S_OK;
00545     }
00546 
00547     return S_FALSE;
00548 }
00549 
00550 HRESULT
00551 IDeskDisplayAdapter_AddPages(PDESKDISPLAYADAPTER This,
00552                              LPFNADDPROPSHEETPAGE pfnAddPage,
00553                              LPARAM lParam)
00554 {
00555     HPROPSHEETPAGE hpsp;
00556     PROPSHEETPAGE psp;
00557 
00558     DPRINT1("IDeskDisplayAdapter::AddPages(%p,%p)\n", pfnAddPage, lParam);
00559 
00560     psp.dwSize = sizeof(psp);
00561     psp.dwFlags = PSP_DEFAULT;
00562     psp.hInstance = hInstance;
00563     psp.pszTemplate = MAKEINTRESOURCE(IDD_DISPLAYADAPTER);
00564     psp.pfnDlgProc = DisplayAdapterDlgProc;
00565     psp.lParam = (LPARAM)This;
00566 
00567     hpsp = CreatePropertySheetPage(&psp);
00568     if (hpsp != NULL && pfnAddPage(hpsp, lParam))
00569         return S_OK;
00570 
00571     return S_FALSE;
00572 }
00573 
00574 HRESULT
00575 IDeskDisplayAdapter_ReplacePage(PDESKDISPLAYADAPTER This,
00576                                 EXPPS uPageID,
00577                                 LPFNADDPROPSHEETPAGE pfnReplacePage,
00578                                 LPARAM lParam)
00579 {
00580     DPRINT1("IDeskDisplayAdapter::ReplacePage(%u,%p,%p)\n", uPageID, pfnReplacePage, lParam);
00581     return E_NOTIMPL;
00582 }
00583 
00584 HRESULT
00585 IDeskDisplayAdapter_Constructor(REFIID riid,
00586                                 LPVOID *ppv)
00587 {
00588     PDESKDISPLAYADAPTER This;
00589     HRESULT hRet = E_OUTOFMEMORY;
00590 
00591     DPRINT1("IDeskDisplayAdapter::Constructor(%p,%p)\n", riid, ppv);
00592 
00593     This = HeapAlloc(GetProcessHeap(),
00594                      0,
00595                      sizeof(*This));
00596     if (This != NULL)
00597     {
00598         ZeroMemory(This,
00599                    sizeof(*This));
00600 
00601         IDeskDisplayAdapter_InitIface(This);
00602 
00603         hRet = IDeskDisplayAdapter_QueryInterface(This,
00604                                                   riid,
00605                                                   ppv);
00606         if (!SUCCEEDED(hRet))
00607             IDeskDisplayAdapter_Release(This);
00608     }
00609 
00610     return hRet;
00611 }
00612 
00613 BOOL WINAPI
00614 DllMain(HINSTANCE hinstDLL,
00615         DWORD dwReason,
00616         LPVOID lpvReserved)
00617 {
00618     switch (dwReason)
00619     {
00620         case DLL_PROCESS_ATTACH:
00621             hInstance = hinstDLL;
00622             DisableThreadLibraryCalls(hInstance);
00623             break;
00624     }
00625 
00626     return TRUE;
00627 }

Generated on Sat May 26 2012 04:21:04 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.