1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS Display Control Panel 4 * FILE: dll/cpl/desk/advmon.c 5 * PURPOSE: Advanced monitor/display settings 6 */ 7 8 #include "desk.h" 9 10 #define MAX_ADVANCED_PAGES 32 11 12 static BOOL CALLBACK 13 PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam) 14 { 15 PROPSHEETHEADER *ppsh = (PROPSHEETHEADER *)lParam; 16 if (ppsh != NULL && ppsh->nPages < MAX_ADVANCED_PAGES) 17 { 18 ppsh->phpage[ppsh->nPages++] = hpage; 19 return TRUE; 20 } 21 22 return FALSE; 23 } 24 25 static BOOL 26 DisplayAdvancedSettingsInitPropSheetPage(PROPSHEETHEADER *ppsh, WORD idDlg, DLGPROC DlgProc, LPARAM lParam) 27 { 28 HPROPSHEETPAGE hPage; 29 PROPSHEETPAGE psp; 30 31 if (ppsh->nPages < MAX_ADVANCED_PAGES) 32 { 33 ZeroMemory(&psp, sizeof(psp)); 34 psp.dwSize = sizeof(psp); 35 psp.dwFlags = PSP_DEFAULT; 36 psp.hInstance = hApplet; 37 psp.pszTemplate = MAKEINTRESOURCE(idDlg); 38 psp.pfnDlgProc = DlgProc; 39 psp.lParam = lParam; 40 41 hPage = CreatePropertySheetPage(&psp); 42 if (hPage != NULL) 43 { 44 return PropSheetAddPage(hPage, (LPARAM)ppsh); 45 } 46 } 47 48 return FALSE; 49 } 50 51 static VOID 52 BuildAdvPropTitle(IDataObject *pdo, LPTSTR lpBuffer, DWORD dwBufferLen) 53 { 54 UINT uiMonitorName, uiDisplayName; 55 LPTSTR lpMonitorName, lpDisplayName; 56 TCHAR szFormatBuff[32]; 57 58 if (!LoadString(hApplet, IDS_ADVANCEDTITLEFMT, szFormatBuff, sizeof(szFormatBuff) / sizeof(szFormatBuff[0]))) 59 { 60 szFormatBuff[0] = _T('\0'); 61 } 62 63 uiMonitorName = RegisterClipboardFormat(DESK_EXT_MONITORNAME); 64 uiDisplayName = RegisterClipboardFormat(DESK_EXT_DISPLAYNAME); 65 66 lpMonitorName = QueryDeskCplString(pdo, uiMonitorName); 67 lpDisplayName = QueryDeskCplString(pdo, uiDisplayName); 68 69 _sntprintf(lpBuffer, dwBufferLen, szFormatBuff, lpMonitorName, lpDisplayName); 70 71 if (lpMonitorName != NULL) 72 LocalFree((HLOCAL)lpMonitorName); 73 if (lpDisplayName != NULL) 74 LocalFree((HLOCAL)lpDisplayName); 75 } 76 77 78 typedef HPSXA (WINAPI * CPSEAE)(HKEY,LPCWSTR,UINT,IDataObject*); 79 80 BOOL 81 DisplayAdvancedSettings(HWND hWndParent, PDISPLAY_DEVICE_ENTRY DisplayDevice) 82 { 83 TCHAR szCaption[128]; 84 HPROPSHEETPAGE hpsp[MAX_ADVANCED_PAGES]; 85 PROPSHEETHEADER psh; 86 HPSXA hpsxaDev, hpsxaDisp; 87 BOOL Ret; 88 IDataObject *pdo; 89 #ifdef _MSC_VER 90 HMODULE hShell32 = NULL; 91 CPSEAE msvc_SHCreatePropSheetExtArrayEx; 92 #endif 93 94 /* FIXME: Build the "%s and %s" caption string for the monitor and adapter name */ 95 szCaption[0] = _T('\0'); 96 97 ZeroMemory(&psh, sizeof(PROPSHEETHEADER)); 98 psh.dwSize = sizeof(PROPSHEETHEADER); 99 psh.dwFlags = PSH_PROPTITLE; 100 psh.hwndParent = hWndParent; 101 psh.hInstance = hApplet; 102 psh.pszCaption = szCaption; 103 psh.phpage = hpsp; 104 105 DisplayAdvancedSettingsInitPropSheetPage(&psh, IDD_ADVANCED_GENERAL, AdvGeneralPageProc, (LPARAM)DisplayDevice); 106 107 pdo = CreateDevSettings(DisplayDevice); 108 109 if (pdo != NULL) 110 BuildAdvPropTitle(pdo, szCaption, sizeof(szCaption) / sizeof(szCaption[0])); 111 112 #ifdef _MSC_VER 113 hShell32 = LoadLibrary(_T("shell32.dll")); 114 if (hShell32 == NULL) 115 return FALSE; 116 msvc_SHCreatePropSheetExtArrayEx = (CPSEAE)GetProcAddress(hShell32, (LPCSTR)194); 117 hpsxaDev = msvc_SHCreatePropSheetExtArrayEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Device"), MAX_ADVANCED_PAGES - psh.nPages, pdo); 118 #else 119 hpsxaDev = SHCreatePropSheetExtArrayEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Device"), MAX_ADVANCED_PAGES - psh.nPages, pdo); 120 #endif 121 if (hpsxaDev != NULL) 122 SHAddFromPropSheetExtArray(hpsxaDev, PropSheetAddPage, (LPARAM)&psh); 123 124 #ifdef _MSC_VER 125 hpsxaDisp = msvc_SHCreatePropSheetExtArrayEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Device"), MAX_ADVANCED_PAGES - psh.nPages, pdo); 126 #else 127 hpsxaDisp = SHCreatePropSheetExtArrayEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Display"), MAX_ADVANCED_PAGES - psh.nPages, pdo); 128 #endif 129 if (hpsxaDisp != NULL) 130 SHAddFromPropSheetExtArray(hpsxaDisp, PropSheetAddPage, (LPARAM)&psh); 131 132 Ret = (LONG)(PropertySheet(&psh) != -1); 133 134 if (hpsxaDisp != NULL) 135 SHDestroyPropSheetExtArray(hpsxaDisp); 136 137 if (hpsxaDev != NULL) 138 SHDestroyPropSheetExtArray(hpsxaDev); 139 140 IDataObject_Release(pdo); 141 142 #ifdef _MSC_VER 143 FreeLibrary(hShell32); 144 #endif 145 146 return Ret; 147 } 148