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
];
131 LPCWSTR pwszSelectedTab
= NULL
;
132 LPCWSTR pwszFile
= NULL
;
133 LPCWSTR pwszAction
= NULL
;
135 UNREFERENCED_PARAMETER(wParam
);
139 if (uMsg
== CPL_STARTWPARMSW
&& lParam
)
145 argv
= CommandLineToArgvW((LPCWSTR
)lParam
, &argc
);
147 argv
= CommandLineToArgvW(GetCommandLineW(), &argc
);
152 for (i
= 0; i
<argc
; i
++)
155 if (argv
[i
][0] == L
'@')
156 pwszSelectedTab
= &argv
[i
][1];
158 if (wcsncmp(argv
[i
], L
"desk,@", 6) == 0)
159 pwszSelectedTab
= &argv
[i
][6];
161 else if (wcsncmp(argv
[i
], L
"/Action:", 8) == 0)
162 pwszAction
= &argv
[i
][8];
163 else if (wcsncmp(argv
[i
], L
"/file:", 6) == 0)
164 pwszFile
= &argv
[i
][6];
169 if(pwszAction
&& wcsncmp(pwszAction
, L
"ActivateMSTheme", 15) == 0)
171 ActivateThemeFile(pwszFile
);
175 g_GlobalData
.pwszFile
= pwszFile
;
176 g_GlobalData
.pwszAction
= pwszAction
;
177 g_GlobalData
.desktop_color
= GetSysColor(COLOR_DESKTOP
);
179 LoadString(hApplet
, IDS_CPLNAME
, Caption
, sizeof(Caption
) / sizeof(TCHAR
));
181 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
182 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
183 psh
.dwFlags
= PSH_USECALLBACK
| PSH_PROPTITLE
;
184 psh
.hwndParent
= hCPLWindow
;
185 psh
.hInstance
= hApplet
;
186 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDC_DESK_ICON
));
187 psh
.pszCaption
= Caption
;
192 /* Allow shell extensions to replace the background page */
193 hpsxa
= SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE
, REGSTR_PATH_CONTROLSFOLDER
TEXT("\\Desk"), MAX_DESK_PAGES
- psh
.nPages
);
195 for (i
= 0; i
!= sizeof(PropPages
) / sizeof(PropPages
[0]); i
++)
197 if (pwszSelectedTab
&& wcsicmp(pwszSelectedTab
, PropPages
[i
].Name
) == 0)
200 /* Override the background page if requested by a shell extension */
201 if (PropPages
[i
].idDlg
== IDD_BACKGROUND
&& hpsxa
!= NULL
&&
202 SHReplaceFromPropSheetExtArray(hpsxa
, CPLPAGE_DISPLAY_BACKGROUND
, PropSheetAddPage
, (LPARAM
)&psh
) != 0)
204 /* The shell extension added one or more pages to replace the background page.
205 Don't create the built-in page anymore! */
209 InitPropSheetPage(&psh
, PropPages
[i
].idDlg
, PropPages
[i
].DlgProc
, PropPages
[i
].Callback
);
212 /* NOTE: Don't call SHAddFromPropSheetExtArray here because this applet only allows
213 replacing the background page but not extending the applet by more pages */
219 SHDestroyPropSheetExtArray(hpsxa
);
228 /* Control Panel Callback */
230 CPlApplet(HWND hwndCPl
, UINT uMsg
, LPARAM lParam1
, LPARAM lParam2
)
232 int i
= (int)lParam1
;
244 CPLINFO
*CPlInfo
= (CPLINFO
*)lParam2
;
246 CPlInfo
->idIcon
= Applets
[i
].idIcon
;
247 CPlInfo
->idName
= Applets
[i
].idName
;
248 CPlInfo
->idInfo
= Applets
[i
].idDescription
;
253 Applets
[i
].AppletProc(hwndCPl
, uMsg
, lParam1
, lParam2
);
255 case CPL_STARTWPARMSW
:
256 return Applets
[i
].AppletProc(hwndCPl
, uMsg
, lParam1
, lParam2
);
270 WCHAR pszSystemDir
[MAX_PATH
];
272 WCHAR pszPath
[MAX_PATH
];
273 WCHAR pszFilename
[MAX_PATH
];
274 WCHAR pszExt
[MAX_PATH
];
276 UINT uCompressionType
=FILE_COMPRESSION_NONE
;
283 DPRINT("InstallScreenSaver() null file\n");
284 SetLastError(ERROR_INVALID_PARAMETER
);
287 DPRINT("InstallScreenSaver() Installing screensaver %ls\n", pszFile
);
289 rc
= SetupGetFileCompressionInfoW(pszFile
, &pszOutName
, &dwSourceSize
, &dwTargetSize
, &uCompressionType
);
290 if (ERROR_SUCCESS
!= rc
)
292 DPRINT("InstallScreenSaver() SetupGetFileCompressionInfo failed with error 0x%lx\n", rc
);
296 if (!GetSystemDirectoryW((LPWSTR
)pszSystemDir
, sizeof(pszSystemDir
)/sizeof(WCHAR
)))
299 DPRINT("InstallScreenSaver() GetSystemDirectory failed with error 0x%lx\n", GetLastError());
302 _wsplitpath(pszOutName
, pszDrive
, pszPath
, pszFilename
, pszExt
);
304 StringCbCatW(pszSystemDir
, sizeof(pszSystemDir
), L
"\\");
305 StringCbCatW(pszSystemDir
, sizeof(pszSystemDir
), pszFilename
);
306 StringCbCatW(pszSystemDir
, sizeof(pszSystemDir
), pszExt
);
307 rc
= SetupDecompressOrCopyFileW(pszFile
, pszSystemDir
, &uCompressionType
);
308 DPRINT("InstallScreenSaver() Copying to %ls, compression type %d return 0x%lx\n", pszFile
, uCompressionType
, rc
);
323 DPRINT("InstallScreenSaver() null file\n");
324 SetLastError(ERROR_INVALID_PARAMETER
);
327 DPRINT("InstallScreenSaver() Install from file %s\n", pszFile
);
328 lpwString
= pSetupMultiByteToUnicode(pszFile
, 0);
331 DPRINT("InstallScreenSaver() not enough memory to convert string to unicode\n");
332 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
335 InstallScreenSaverW(hWindow
, hInstance
, lpwString
, nCmdShow
);
340 DllMain(HINSTANCE hInstDLL
, DWORD dwReason
, LPVOID lpvReserved
)
342 UNREFERENCED_PARAMETER(lpvReserved
);
346 case DLL_PROCESS_ATTACH
:
347 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
348 RegisterPreviewControl(hInstDLL
);
349 // case DLL_THREAD_ATTACH:
353 case DLL_PROCESS_DETACH
:
354 UnregisterPreviewControl(hInstDLL
);