2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * FILE: dll/cpl/desk/desk.c
5 * PURPOSE: ReactOS Display Control Panel
7 * PROGRAMMERS: Trevor McCort (lycan359@gmail.com)
15 #define NUM_APPLETS (1)
17 static LONG APIENTRY
DisplayApplet(HWND hwnd
, UINT uMsg
, LPARAM wParam
, LPARAM lParam
);
19 INT_PTR CALLBACK
BackgroundPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
20 INT_PTR CALLBACK
ScreenSaverPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
21 INT_PTR CALLBACK
AppearancePageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
22 INT_PTR CALLBACK
SettingsPageProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
23 UINT CALLBACK
SettingsPageCallbackProc(HWND hwnd
, UINT uMsg
, LPPROPSHEETPAGE ppsp
);
25 HINSTANCE hApplet
= 0;
29 APPLET Applets
[NUM_APPLETS
] =
40 LoadPopupMenu(IN HINSTANCE hInstance
,
41 IN LPCTSTR lpMenuName
)
43 HMENU hMenu
, hSubMenu
= NULL
;
45 hMenu
= LoadMenu(hInstance
,
50 hSubMenu
= GetSubMenu(hMenu
,
52 if (hSubMenu
!= NULL
&&
67 PropSheetAddPage(HPROPSHEETPAGE hpage
, LPARAM lParam
)
69 PROPSHEETHEADER
*ppsh
= (PROPSHEETHEADER
*)lParam
;
70 if (ppsh
!= NULL
&& ppsh
->nPages
< MAX_DESK_PAGES
)
72 ppsh
->phpage
[ppsh
->nPages
++] = hpage
;
80 InitPropSheetPage(PROPSHEETHEADER
*ppsh
, WORD idDlg
, DLGPROC DlgProc
, LPFNPSPCALLBACK pfnCallback
)
85 if (ppsh
->nPages
< MAX_DESK_PAGES
)
87 ZeroMemory(&psp
, sizeof(psp
));
88 psp
.dwSize
= sizeof(psp
);
89 psp
.dwFlags
= PSP_DEFAULT
;
90 if (pfnCallback
!= NULL
)
91 psp
.dwFlags
|= PSP_USECALLBACK
;
92 psp
.hInstance
= hApplet
;
93 psp
.pszTemplate
= MAKEINTRESOURCE(idDlg
);
94 psp
.pfnDlgProc
= DlgProc
;
95 psp
.pfnCallback
= pfnCallback
;
97 hPage
= CreatePropertySheetPage(&psp
);
100 return PropSheetAddPage(hPage
, (LPARAM
)ppsh
);
111 LPFNPSPCALLBACK Callback
;
115 { IDD_BACKGROUND
, BackgroundPageProc
, NULL
, L
"Desktop" },
116 { IDD_SCREENSAVER
, ScreenSaverPageProc
, NULL
, L
"Screen Saver" },
117 { IDD_APPEARANCE
, AppearancePageProc
, NULL
, L
"Appearance" },
118 { IDD_SETTINGS
, SettingsPageProc
, SettingsPageCallbackProc
, L
"Settings" },
123 DisplayApplet(HWND hwnd
, UINT uMsg
, LPARAM wParam
, LPARAM lParam
)
125 HPROPSHEETPAGE hpsp
[MAX_DESK_PAGES
];
132 LPCWSTR pwszSelectedTab
= NULL
;
133 LPCWSTR pwszFile
= NULL
;
134 LPCWSTR pwszAction
= NULL
;
136 UNREFERENCED_PARAMETER(wParam
);
140 if (uMsg
== CPL_STARTWPARMSW
&& lParam
)
144 LPCWSTR pszCommandLine
= (LPCWSTR
)lParam
;
146 argv
= CommandLineToArgvW(pszCommandLine
, &argc
);
150 for (i
= 0; i
<argc
; i
++)
152 if (argv
[i
][0] == L
'@')
153 pwszSelectedTab
= &argv
[i
][1];
154 else if (wcsncmp(argv
[i
], L
"/Action:", 8) == 0)
155 pwszAction
= &argv
[i
][8];
156 else if (wcsncmp(argv
[i
], L
"/file:", 6) == 0)
157 pwszFile
= &argv
[i
][6];
161 /* HACK: shell32 doesn't give the correct params to CPL_STARTWPARMSW so we need to ... improvise */
162 if (wcsncmp(pszCommandLine
, L
"/file:", 6) == 0)
164 LPCWSTR pwszType
= wcsrchr(pszCommandLine
, L
'.');
165 if (pwszType
&& wcsicmp(pwszType
, L
".msstyles") == 0)
167 pwszFile
= &pszCommandLine
[6];
168 pwszSelectedTab
= L
"Appearance";
169 pwszAction
= L
"OpenMSTheme";
174 g_GlobalData
.pwszFile
= pwszFile
;
175 g_GlobalData
.pwszAction
= pwszAction
;
176 g_GlobalData
.desktop_color
= GetSysColor(COLOR_DESKTOP
);
178 LoadString(hApplet
, IDS_CPLNAME
, Caption
, sizeof(Caption
) / sizeof(TCHAR
));
180 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
181 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
182 psh
.dwFlags
= PSH_USECALLBACK
| PSH_PROPTITLE
;
183 psh
.hwndParent
= hCPLWindow
;
184 psh
.hInstance
= hApplet
;
185 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDC_DESK_ICON
));
186 psh
.pszCaption
= Caption
;
191 /* Allow shell extensions to replace the background page */
192 hpsxa
= SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE
, REGSTR_PATH_CONTROLSFOLDER
TEXT("\\Desk"), MAX_DESK_PAGES
- psh
.nPages
);
194 for (i
= 0; i
!= sizeof(PropPages
) / sizeof(PropPages
[0]); i
++)
196 if (pwszSelectedTab
&& wcsicmp(pwszSelectedTab
, PropPages
[i
].Name
) == 0)
199 /* Override the background page if requested by a shell extension */
200 if (PropPages
[i
].idDlg
== IDD_BACKGROUND
&& hpsxa
!= NULL
&&
201 SHReplaceFromPropSheetExtArray(hpsxa
, CPLPAGE_DISPLAY_BACKGROUND
, PropSheetAddPage
, (LPARAM
)&psh
) != 0)
203 /* The shell extension added one or more pages to replace the background page.
204 Don't create the built-in page anymore! */
208 InitPropSheetPage(&psh
, PropPages
[i
].idDlg
, PropPages
[i
].DlgProc
, PropPages
[i
].Callback
);
211 /* NOTE: Don't call SHAddFromPropSheetExtArray here because this applet only allows
212 replacing the background page but not extending the applet by more pages */
214 ret
= (LONG
)(PropertySheet(&psh
) != -1);
217 SHDestroyPropSheetExtArray(hpsxa
);
226 /* Control Panel Callback */
228 CPlApplet(HWND hwndCPl
, UINT uMsg
, LPARAM lParam1
, LPARAM lParam2
)
230 int i
= (int)lParam1
;
242 CPLINFO
*CPlInfo
= (CPLINFO
*)lParam2
;
244 CPlInfo
->idIcon
= Applets
[i
].idIcon
;
245 CPlInfo
->idName
= Applets
[i
].idName
;
246 CPlInfo
->idInfo
= Applets
[i
].idDescription
;
251 Applets
[i
].AppletProc(hwndCPl
, uMsg
, lParam1
, lParam2
);
253 case CPL_STARTWPARMSW
:
254 return Applets
[i
].AppletProc(hwndCPl
, uMsg
, lParam1
, lParam2
);
268 WCHAR pszSystemDir
[MAX_PATH
];
270 WCHAR pszPath
[MAX_PATH
];
271 WCHAR pszFilename
[MAX_PATH
];
272 WCHAR pszExt
[MAX_PATH
];
274 UINT uCompressionType
=FILE_COMPRESSION_NONE
;
281 DPRINT("InstallScreenSaver() null file\n");
282 SetLastError(ERROR_INVALID_PARAMETER
);
285 DPRINT("InstallScreenSaver() Installing screensaver %ls\n", pszFile
);
287 rc
= SetupGetFileCompressionInfoW(pszFile
, &pszOutName
, &dwSourceSize
, &dwTargetSize
, &uCompressionType
);
288 if (ERROR_SUCCESS
!= rc
)
290 DPRINT("InstallScreenSaver() SetupGetFileCompressionInfo failed with error 0x%lx\n", rc
);
294 if (!GetSystemDirectoryW((LPWSTR
)pszSystemDir
, sizeof(pszSystemDir
)/sizeof(WCHAR
)))
297 DPRINT("InstallScreenSaver() GetSystemDirectory failed with error 0x%lx\n", GetLastError());
300 _wsplitpath(pszOutName
, pszDrive
, pszPath
, pszFilename
, pszExt
);
302 StringCbCatW(pszSystemDir
, sizeof(pszSystemDir
), L
"\\");
303 StringCbCatW(pszSystemDir
, sizeof(pszSystemDir
), pszFilename
);
304 StringCbCatW(pszSystemDir
, sizeof(pszSystemDir
), pszExt
);
305 rc
= SetupDecompressOrCopyFileW(pszFile
, pszSystemDir
, &uCompressionType
);
306 DPRINT("InstallScreenSaver() Copying to %ls, compression type %d return 0x%lx\n", pszFile
, uCompressionType
, rc
);
321 DPRINT("InstallScreenSaver() null file\n");
322 SetLastError(ERROR_INVALID_PARAMETER
);
325 DPRINT("InstallScreenSaver() Install from file %s\n", pszFile
);
326 lpwString
= pSetupMultiByteToUnicode(pszFile
, 0);
329 DPRINT("InstallScreenSaver() not enough memory to convert string to unicode\n");
330 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
333 InstallScreenSaverW(hWindow
, hInstance
, lpwString
, nCmdShow
);
338 DllMain(HINSTANCE hInstDLL
, DWORD dwReason
, LPVOID lpvReserved
)
340 UNREFERENCED_PARAMETER(lpvReserved
);
344 case DLL_PROCESS_ATTACH
:
345 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
346 RegisterPreviewControl(hInstDLL
);
347 // case DLL_THREAD_ATTACH:
351 case DLL_PROCESS_DETACH
:
352 UnregisterPreviewControl(hInstDLL
);