[KSPROXY]
[reactos.git] / reactos / dll / cpl / desk / advmon.c
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 InitPropSheetPage(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 #endif
92 CPSEAE msvc_SHCreatePropSheetExtArrayEx;
93
94 /* silence gcc warning */
95 msvc_SHCreatePropSheetExtArrayEx = NULL;
96
97 /* FIXME: Build the "%s and %s" caption string for the monitor and adapter name */
98 szCaption[0] = _T('\0');
99
100 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
101 psh.dwSize = sizeof(PROPSHEETHEADER);
102 psh.dwFlags = PSH_PROPTITLE;
103 psh.hwndParent = hWndParent;
104 psh.hInstance = hApplet;
105 psh.pszCaption = szCaption;
106 psh.phpage = hpsp;
107
108 InitPropSheetPage(&psh, IDD_ADVANCED_GENERAL, AdvGeneralPageProc, (LPARAM)DisplayDevice);
109
110 pdo = CreateDevSettings(DisplayDevice);
111
112 if (pdo != NULL)
113 BuildAdvPropTitle(pdo, szCaption, sizeof(szCaption) / sizeof(szCaption[0]));
114
115 #ifdef _MSC_VER
116 hShell32 = LoadLibrary(_T("shell32.dll"));
117 if(hShell32 == NULL)
118 return FALSE;
119 msvc_SHCreatePropSheetExtArrayEx = (CPSEAE)GetProcAddress(hShell32, (LPCSTR)194);
120 hpsxaDev = msvc_SHCreatePropSheetExtArrayEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Device"), MAX_ADVANCED_PAGES - psh.nPages, pdo);
121 #else
122 hpsxaDev = SHCreatePropSheetExtArrayEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Device"), MAX_ADVANCED_PAGES - psh.nPages, pdo);
123 #endif
124 if (hpsxaDev != NULL)
125 SHAddFromPropSheetExtArray(hpsxaDev, PropSheetAddPage, (LPARAM)&psh);
126
127 #ifdef _MSC_VER
128 hpsxaDisp = msvc_SHCreatePropSheetExtArrayEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Device"), MAX_ADVANCED_PAGES - psh.nPages, pdo);
129 #else
130 hpsxaDisp = SHCreatePropSheetExtArrayEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Display"), MAX_ADVANCED_PAGES - psh.nPages, pdo);
131 #endif
132 if (hpsxaDisp != NULL)
133 SHAddFromPropSheetExtArray(hpsxaDisp, PropSheetAddPage, (LPARAM)&psh);
134
135 Ret = (LONG)(PropertySheet(&psh) != -1);
136
137 if (hpsxaDisp != NULL)
138 SHDestroyPropSheetExtArray(hpsxaDisp);
139
140 if (hpsxaDev != NULL)
141 SHDestroyPropSheetExtArray(hpsxaDev);
142
143 IDataObject_Release(pdo);
144
145 #ifdef _MSC_VER
146 if (hShell32)
147 FreeLibrary(hShell32);
148 #endif
149
150 return Ret;
151 }