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
;
114 { IDD_BACKGROUND
, BackgroundPageProc
, NULL
},
115 { IDD_SCREENSAVER
, ScreenSaverPageProc
, NULL
},
116 { IDD_APPEARANCE
, AppearancePageProc
, NULL
},
117 { IDD_SETTINGS
, SettingsPageProc
, SettingsPageCallbackProc
},
122 DisplayApplet(HWND hwnd
, UINT uMsg
, LPARAM wParam
, LPARAM lParam
)
124 HPROPSHEETPAGE hpsp
[MAX_DESK_PAGES
];
131 UNREFERENCED_PARAMETER(lParam
);
132 UNREFERENCED_PARAMETER(wParam
);
133 UNREFERENCED_PARAMETER(uMsg
);
134 UNREFERENCED_PARAMETER(hwnd
);
136 g_GlobalData
.desktop_color
= GetSysColor(COLOR_DESKTOP
);
138 LoadString(hApplet
, IDS_CPLNAME
, Caption
, sizeof(Caption
) / sizeof(TCHAR
));
140 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
141 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
142 psh
.dwFlags
= PSH_USECALLBACK
| PSH_PROPTITLE
;
143 psh
.hwndParent
= hCPLWindow
;
144 psh
.hInstance
= hApplet
;
145 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDC_DESK_ICON
));
146 psh
.pszCaption
= Caption
;
151 /* Allow shell extensions to replace the background page */
152 hpsxa
= SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE
, REGSTR_PATH_CONTROLSFOLDER
TEXT("\\Desk"), MAX_DESK_PAGES
- psh
.nPages
);
154 for (i
= 0; i
!= sizeof(PropPages
) / sizeof(PropPages
[0]); i
++)
156 /* Override the background page if requested by a shell extension */
157 if (PropPages
[i
].idDlg
== IDD_BACKGROUND
&& hpsxa
!= NULL
&&
158 SHReplaceFromPropSheetExtArray(hpsxa
, CPLPAGE_DISPLAY_BACKGROUND
, PropSheetAddPage
, (LPARAM
)&psh
) != 0)
160 /* The shell extension added one or more pages to replace the background page.
161 Don't create the built-in page anymore! */
165 InitPropSheetPage(&psh
, PropPages
[i
].idDlg
, PropPages
[i
].DlgProc
, PropPages
[i
].Callback
);
168 /* NOTE: Don't call SHAddFromPropSheetExtArray here because this applet only allows
169 replacing the background page but not extending the applet by more pages */
171 ret
= (LONG
)(PropertySheet(&psh
) != -1);
174 SHDestroyPropSheetExtArray(hpsxa
);
180 /* Control Panel Callback */
182 CPlApplet(HWND hwndCPl
, UINT uMsg
, LPARAM lParam1
, LPARAM lParam2
)
184 int i
= (int)lParam1
;
196 CPLINFO
*CPlInfo
= (CPLINFO
*)lParam2
;
198 CPlInfo
->idIcon
= Applets
[i
].idIcon
;
199 CPlInfo
->idName
= Applets
[i
].idName
;
200 CPlInfo
->idInfo
= Applets
[i
].idDescription
;
205 hCPLWindow
= hwndCPl
;
206 Applets
[i
].AppletProc(hwndCPl
, uMsg
, lParam1
, lParam2
);
221 WCHAR pszSystemDir
[MAX_PATH
];
223 WCHAR pszPath
[MAX_PATH
];
224 WCHAR pszFilename
[MAX_PATH
];
225 WCHAR pszExt
[MAX_PATH
];
227 UINT uCompressionType
=FILE_COMPRESSION_NONE
;
234 DPRINT("InstallScreenSaver() null file\n");
235 SetLastError(ERROR_INVALID_PARAMETER
);
238 DPRINT("InstallScreenSaver() Installing screensaver %ls\n", pszFile
);
240 rc
= SetupGetFileCompressionInfoW(pszFile
, &pszOutName
, &dwSourceSize
, &dwTargetSize
, &uCompressionType
);
241 if (ERROR_SUCCESS
!= rc
)
243 DPRINT("InstallScreenSaver() SetupGetFileCompressionInfo failed with error 0x%lx\n", rc
);
247 if (!GetSystemDirectoryW((LPWSTR
)pszSystemDir
, sizeof(pszSystemDir
)/sizeof(WCHAR
)))
250 DPRINT("InstallScreenSaver() GetSystemDirectory failed with error 0x%lx\n", GetLastError());
253 _wsplitpath(pszOutName
, pszDrive
, pszPath
, pszFilename
, pszExt
);
255 StringCbCatW(pszSystemDir
, sizeof(pszSystemDir
), L
"\\");
256 StringCbCatW(pszSystemDir
, sizeof(pszSystemDir
), pszFilename
);
257 StringCbCatW(pszSystemDir
, sizeof(pszSystemDir
), pszExt
);
258 rc
= SetupDecompressOrCopyFileW(pszFile
, pszSystemDir
, &uCompressionType
);
259 DPRINT("InstallScreenSaver() Copying to %ls, compression type %d return 0x%lx\n", pszFile
, uCompressionType
, rc
);
274 DPRINT("InstallScreenSaver() null file\n");
275 SetLastError(ERROR_INVALID_PARAMETER
);
278 DPRINT("InstallScreenSaver() Install from file %s\n", pszFile
);
279 lpwString
= pSetupMultiByteToUnicode(pszFile
, 0);
282 DPRINT("InstallScreenSaver() not enough memory to convert string to unicode\n");
283 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
286 InstallScreenSaverW(hWindow
, hInstance
, lpwString
, nCmdShow
);
291 DllMain(HINSTANCE hInstDLL
, DWORD dwReason
, LPVOID lpvReserved
)
293 UNREFERENCED_PARAMETER(lpvReserved
);
297 case DLL_PROCESS_ATTACH
:
298 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
299 RegisterPreviewControl(hInstDLL
);
300 // case DLL_THREAD_ATTACH:
304 case DLL_PROCESS_DETACH
:
305 UnregisterPreviewControl(hInstDLL
);