Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

917 lines
26 KiB

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // File: Registry.cpp
  4. // Created: Feb 1996
  5. // By: Martin Holladay (a-martih) and Ryan D. Marshall (a-ryanm)
  6. //
  7. // Project: MultiDesk - The NT Desktop Switcher
  8. //
  9. // Main Functions:
  10. // Profile_GetApplicationState() - retrieves the application's state variables
  11. // Profile_SetApplicationState() - sets the applicaion's state variables
  12. //
  13. //
  14. // Misc. Functions (helpers)
  15. //
  16. // Revision History:
  17. //
  18. // March 1997 - Add external icon capability
  19. //
  20. //
  21. #include <windows.h>
  22. #include <stdio.h>
  23. #include <assert.h>
  24. #include <shellapi.h>
  25. #include "DeskSpc.h"
  26. #include "desktop.h"
  27. #include "registry.h"
  28. #include "resource.h"
  29. extern APPVARS AppMember;
  30. //
  31. // Registry key names for MultiDesk params - only need file scope
  32. //
  33. #define MD_MULTIDESK TEXT("Software\\Microsoft\\MultiDesk")
  34. #define MD_CONTEXT TEXT("Software\\Microsoft\\MultiDesk\\Context")
  35. #define MD_NUMOFDESKTOPS TEXT("NumOfDesktops")
  36. #define MD_DESKTOPNAME TEXT("DesktopName")
  37. #define MD_SAIFERNAME TEXT("SaiferName")
  38. #define MD_DESKTOPICONID TEXT("DesktopIconID")
  39. #define WR_DESKTOP TEXT("Control Panel\\Desktop")
  40. #define WR_PATTERN TEXT("Pattern")
  41. #define WR_SCREENSAVER TEXT("SCRNSAVE.EXE")
  42. #define WR_ACTIVE TEXT("ScreenSaveActive")
  43. #define WR_TIMEOUT TEXT("ScreenSaveTimeOut")
  44. #define WR_SECURE TEXT("ScreenSaverIsSecure")
  45. #define WR_WALLPAPER TEXT("Wallpaper")
  46. #define WR_TILE TEXT("TileWallpaper")
  47. ///////////////////////////////////////////////////////////////////////////////
  48. //
  49. // defines and structs for updating the Color settings in the registry
  50. //
  51. //
  52. // HKEY_CURRENT_USER sub key for colors
  53. //
  54. #define COLOR_SUBKEY TEXT("Control Panel\\Colors")
  55. //
  56. // Two ORDERED Lists of NUM_COLOR_ELEMENTS which MUST go together
  57. // nColorElements and szRegColorNames
  58. // If you change one change the other and adjust NUM_COLOR_ELEMENTS
  59. //
  60. const int nColorElements[NUM_COLOR_ELEMENTS] = {
  61. COLOR_ACTIVEBORDER, // 0
  62. COLOR_ACTIVECAPTION, // 1
  63. COLOR_APPWORKSPACE, // 2
  64. COLOR_BACKGROUND, // 3
  65. COLOR_BTNFACE, // 4
  66. COLOR_BTNHILIGHT, // 5
  67. COLOR_BTNSHADOW, // 6
  68. COLOR_BTNTEXT, // 7
  69. COLOR_GRAYTEXT, // 8
  70. COLOR_HIGHLIGHT, // 9
  71. COLOR_HIGHLIGHTTEXT, // 10
  72. COLOR_INACTIVEBORDER, // 11
  73. COLOR_INACTIVECAPTION, // 12
  74. COLOR_INACTIVECAPTIONTEXT, // 13
  75. COLOR_INFOTEXT, // 14
  76. COLOR_INFOBK, // 15
  77. COLOR_MENU, // 16
  78. COLOR_MENUTEXT, // 17
  79. COLOR_SCROLLBAR, // 18
  80. COLOR_CAPTIONTEXT, // 19
  81. COLOR_WINDOW, // 20
  82. COLOR_WINDOWFRAME, // 21
  83. COLOR_WINDOWTEXT, // 22
  84. };
  85. //
  86. // List of key value names for updating the registry
  87. //
  88. LPCTSTR szRegColorNames[NUM_COLOR_ELEMENTS] = {
  89. TEXT("ActiveBorder"), // 0
  90. TEXT("ActiveTitle"), // 1
  91. TEXT("AppWorkSpace"), // 2
  92. TEXT("Background"), // 3
  93. TEXT("ButtonFace"), // 4
  94. TEXT("ButtonHilight"), // 5
  95. TEXT("ButtonShadow"), // 6
  96. TEXT("ButtonText"), // 7
  97. TEXT("GrayText"), // 8
  98. TEXT("Hilight"), // 9
  99. TEXT("HilightText"), // 10
  100. TEXT("InactiveBorder"), // 11
  101. TEXT("InactiveTitle"), // 12
  102. TEXT("InactiveTitleText"), // 13
  103. TEXT("InfoText"), // 14
  104. TEXT("InfoWindow"), // 15
  105. TEXT("Menu"), // 16
  106. TEXT("MenuText"), // 17
  107. TEXT("Scrollbar"), // 18
  108. TEXT("TitleText"), // 19
  109. TEXT("Window"), // 20
  110. TEXT("WindowFrame"), // 21
  111. TEXT("WindowText"), // 22
  112. };
  113. ////////////////////////////////////////////////////////////////////////////////
  114. //
  115. //
  116. BOOL Reg_SetSysColors(const DWORD dwColor[NUM_COLOR_ELEMENTS])
  117. {
  118. UINT i;
  119. //
  120. // If the a color element is different - then Change it
  121. //
  122. for (i = 0; i < NUM_COLOR_ELEMENTS; i++) {
  123. if (GetSysColor(nColorElements[i]) != dwColor[i]) {
  124. SetSysColors(1, &nColorElements[i], &dwColor[i]);
  125. }
  126. }
  127. return TRUE;
  128. }
  129. ////////////////////////////////////////////////////////////////////////////////
  130. //
  131. //
  132. BOOL Reg_GetSysColors(DWORD dwColor[NUM_COLOR_ELEMENTS])
  133. {
  134. UINT i;
  135. for (i = 0; i < NUM_COLOR_ELEMENTS; i++) {
  136. dwColor[i] = GetSysColor(nColorElements[i]);
  137. }
  138. return TRUE;
  139. }
  140. ////////////////////////////////////////////////////////////////////////////////
  141. //
  142. //
  143. BOOL Reg_UpdateColorRegistry(const DWORD dwColor[NUM_COLOR_ELEMENTS])
  144. {
  145. HKEY hKey;
  146. UINT i;
  147. TCHAR szTemp[12];
  148. //
  149. // Open the SubKey - return FALSE if it doesn't exist
  150. //
  151. if (RegOpenKeyEx(HKEY_CURRENT_USER, COLOR_SUBKEY, 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS) {
  152. return FALSE;
  153. }
  154. //
  155. // Format the RGB string and write it to the registry
  156. //
  157. for (i = 0; i < NUM_COLOR_ELEMENTS; i++) {
  158. wsprintf(szTemp, TEXT("%d %d %d"),
  159. GetRValue(dwColor[i]), GetGValue(dwColor[i]), GetBValue(dwColor[i]));
  160. RegSetValueEx(hKey, szRegColorNames[i], 0, REG_SZ, (LPBYTE) &szTemp,
  161. sizeof(TCHAR) * (lstrlen(szTemp) + 1));
  162. }
  163. RegCloseKey(hKey);
  164. return TRUE;
  165. }
  166. /*-------------------------------------------------------------------------------------*/
  167. /*-------------------------------------------------------------------------------------*/
  168. BOOL Profile_SetNewContext(UINT NumOfDesktops)
  169. {
  170. HKEY hKey;
  171. DWORD dwDisposition;
  172. BOOL bResult;
  173. //
  174. // Ensure that the ..\MultiDesk Subkey exists, and if not create it.
  175. //
  176. if (RegCreateKeyEx(HKEY_CURRENT_USER, MD_MULTIDESK, 0, TEXT(""), REG_OPTION_NON_VOLATILE,
  177. KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) != ERROR_SUCCESS)
  178. {
  179. return FALSE;
  180. }
  181. RegCloseKey(hKey);
  182. //
  183. // Open the ..\MultiDesk\Context subkey
  184. //
  185. if (RegCreateKeyEx(HKEY_CURRENT_USER, MD_CONTEXT, 0, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) != ERROR_SUCCESS)
  186. {
  187. return FALSE;
  188. }
  189. //
  190. // Write the number of destkops
  191. //
  192. if (RegSetValueEx(hKey, MD_NUMOFDESKTOPS, 0, REG_DWORD, (LPBYTE) &NumOfDesktops, sizeof(UINT)) != ERROR_SUCCESS)
  193. {
  194. RegCloseKey(hKey);
  195. bResult = FALSE;
  196. }
  197. RegCloseKey(hKey);
  198. return bResult;
  199. }
  200. /*-------------------------------------------------------------------------------------*/
  201. /*-------------------------------------------------------------------------------------*/
  202. BOOL Profile_GetNewContext(UINT* NumOfDesktops)
  203. {
  204. HKEY hKey;
  205. DWORD dwType;
  206. DWORD ulLen;
  207. //
  208. // Open the SubKey - return FALSE if it doesn't exist
  209. //
  210. if (RegOpenKeyEx(HKEY_CURRENT_USER, MD_CONTEXT, 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  211. {
  212. return FALSE;
  213. }
  214. //
  215. // Get the number of desktops
  216. //
  217. ulLen = sizeof(UINT);
  218. if (RegQueryValueEx(hKey, MD_NUMOFDESKTOPS, NULL, &dwType, (LPBYTE) NumOfDesktops, &ulLen) != ERROR_SUCCESS)
  219. {
  220. RegCloseKey(hKey);
  221. return FALSE;
  222. }
  223. RegCloseKey(hKey);
  224. return TRUE;
  225. }
  226. /*-------------------------------------------------------------------------------------*/
  227. /*-------------------------------------------------------------------------------------*/
  228. BOOL
  229. Profile_SaveDesktopContext
  230. (
  231. UINT DesktopNumber,
  232. LPCTSTR szDesktopName,
  233. LPCTSTR szSaiferName,
  234. UINT nIconID
  235. )
  236. {
  237. TCHAR DesktopKey[MAX_PATH];
  238. HKEY hKey;
  239. DWORD dwDisposition;
  240. //
  241. // Ensure that the ..\MultiDesk Subkey exists, and if not create it.
  242. //
  243. if (RegCreateKeyEx(HKEY_CURRENT_USER, MD_MULTIDESK, 0, TEXT(""), REG_OPTION_NON_VOLATILE,
  244. KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) != ERROR_SUCCESS)
  245. {
  246. return FALSE;
  247. }
  248. RegCloseKey(hKey);
  249. //
  250. // Ensure that the ..\MultiDesk\Context Subkey exists, and if not create it.
  251. //
  252. if (RegCreateKeyEx(HKEY_CURRENT_USER, MD_CONTEXT, 0, TEXT(""), REG_OPTION_NON_VOLATILE,
  253. KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) != ERROR_SUCCESS)
  254. {
  255. return FALSE;
  256. }
  257. RegCloseKey(hKey);
  258. //
  259. // Open the ..\MultiDesk\Context\Desktop subkey
  260. //
  261. wsprintf(DesktopKey, MD_CONTEXT TEXT("\\%02d"), DesktopNumber);
  262. if (RegCreateKeyEx(HKEY_CURRENT_USER, DesktopKey, 0, TEXT(""), REG_OPTION_NON_VOLATILE,
  263. KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) != ERROR_SUCCESS)
  264. {
  265. return FALSE;
  266. }
  267. //
  268. // Write the desktop name
  269. //
  270. if (RegSetValueEx(hKey, MD_DESKTOPNAME, 0, REG_SZ, (const LPBYTE) szDesktopName,
  271. sizeof(TCHAR) * (lstrlen(szDesktopName) + 1)) != ERROR_SUCCESS)
  272. {
  273. RegCloseKey(hKey);
  274. return FALSE;
  275. }
  276. //
  277. // Write the Saifer name
  278. //
  279. if (RegSetValueEx(hKey, MD_SAIFERNAME, 0, REG_SZ, (const LPBYTE) szSaiferName,
  280. sizeof(TCHAR) * (lstrlen(szSaiferName) + 1)) != ERROR_SUCCESS)
  281. {
  282. RegCloseKey(hKey);
  283. return FALSE;
  284. }
  285. //
  286. // Write the Icon ID
  287. //
  288. if (RegSetValueEx(hKey, MD_DESKTOPICONID, 0, REG_DWORD, (const LPBYTE) &nIconID,
  289. sizeof(UINT)) != ERROR_SUCCESS)
  290. {
  291. RegCloseKey(hKey);
  292. return FALSE;
  293. }
  294. RegCloseKey(hKey);
  295. return TRUE;
  296. }
  297. /*-------------------------------------------------------------------------------------*/
  298. /*-------------------------------------------------------------------------------------*/
  299. BOOL
  300. Profile_LoadDesktopContext
  301. (
  302. UINT DesktopNumber,
  303. LPTSTR szDesktopName,
  304. LPTSTR szSaiferName,
  305. UINT * nIconID
  306. )
  307. {
  308. TCHAR DesktopKey[MAX_PATH];
  309. HKEY hKey;
  310. DWORD dwType;
  311. DWORD ulLen;
  312. //
  313. // Open the SubKey - return FALSE if it doesn't exist
  314. //
  315. wsprintf(DesktopKey, MD_CONTEXT TEXT("\\%02d"), DesktopNumber);
  316. if (RegOpenKeyEx(HKEY_CURRENT_USER, DesktopKey, 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  317. {
  318. return FALSE;
  319. }
  320. //
  321. // Get the desktop name
  322. //
  323. ulLen = sizeof(TCHAR) * MAX_NAME_LENGTH; // must be bytes not TCHAR
  324. if (RegQueryValueEx(hKey, MD_DESKTOPNAME, NULL, &dwType, (LPBYTE) szDesktopName, &ulLen) != ERROR_SUCCESS)
  325. {
  326. RegCloseKey(hKey);
  327. return FALSE;
  328. }
  329. //
  330. // Get the Saifer name
  331. //
  332. ulLen = sizeof(TCHAR) * MAX_NAME_LENGTH; // must be bytes not TCHAR
  333. if (RegQueryValueEx(hKey, MD_SAIFERNAME, NULL, &dwType, (LPBYTE) szSaiferName, &ulLen) != ERROR_SUCCESS)
  334. {
  335. RegCloseKey(hKey);
  336. return FALSE;
  337. }
  338. //
  339. // Get the desktop UINT icon ID
  340. //
  341. ulLen = sizeof(TCHAR) * MAX_PATH; // must be bytes not TCHAR
  342. if (RegQueryValueEx(hKey, MD_DESKTOPICONID, NULL, &dwType, (LPBYTE) nIconID, &ulLen) != ERROR_SUCCESS)
  343. {
  344. *nIconID = DesktopNumber;
  345. }
  346. RegCloseKey(hKey);
  347. return TRUE;
  348. }
  349. /*-------------------------------------------------------------------------------------*/
  350. /*-------------------------------------------------------------------------------------*/
  351. BOOL Reg_GetPattern(LPTSTR szPattern)
  352. {
  353. DWORD dwType;
  354. DWORD ulLen;
  355. HKEY hKey;
  356. //
  357. // Open the pattern key
  358. //
  359. if (RegOpenKeyEx(HKEY_CURRENT_USER, WR_DESKTOP, 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  360. {
  361. return FALSE;
  362. }
  363. //
  364. // Get the pattern
  365. //
  366. ulLen = sizeof(TCHAR) * MAX_NAME_LENGTH; // must be bytes not TCHAR
  367. if (RegQueryValueEx(hKey, WR_PATTERN, NULL, &dwType, (LPBYTE) szPattern, &ulLen) != ERROR_SUCCESS)
  368. {
  369. RegCloseKey(hKey);
  370. return FALSE;
  371. }
  372. szPattern[ulLen] = TEXT('\0');
  373. RegCloseKey(hKey);
  374. return TRUE;
  375. }
  376. /*-------------------------------------------------------------------------------------*/
  377. /*-------------------------------------------------------------------------------------*/
  378. BOOL Reg_SetPattern(LPCTSTR szPattern)
  379. {
  380. TCHAR szOldPattern[MAX_NAME_LENGTH];
  381. DWORD dwType;
  382. DWORD ulLen;
  383. HKEY hKey;
  384. //
  385. // Open the pattern key
  386. //
  387. if (RegOpenKeyEx(HKEY_CURRENT_USER, WR_DESKTOP, 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  388. {
  389. return FALSE;
  390. }
  391. //
  392. // Get the pattern
  393. //
  394. ulLen = sizeof(TCHAR) * MAX_NAME_LENGTH; // must be bytes not TCHAR
  395. if (RegQueryValueEx(hKey, WR_PATTERN, NULL, &dwType, (LPBYTE) szOldPattern, &ulLen) != ERROR_SUCCESS)
  396. {
  397. RegCloseKey(hKey);
  398. return FALSE;
  399. }
  400. //
  401. // Compare the patterns
  402. //
  403. if (!lstrcmp(szPattern, szOldPattern)) return FALSE;
  404. //
  405. // Write the pattern
  406. //
  407. if (RegSetValueEx(hKey, WR_PATTERN, 0, REG_SZ, (const LPBYTE) szPattern,
  408. sizeof(TCHAR) * (lstrlen(szPattern) + 1)) != ERROR_SUCCESS)
  409. {
  410. RegCloseKey(hKey);
  411. return FALSE;
  412. }
  413. RegCloseKey(hKey);
  414. return TRUE;
  415. }
  416. /*-------------------------------------------------------------------------------------*/
  417. /*-------------------------------------------------------------------------------------*/
  418. BOOL Reg_GetScreenSaver(LPTSTR szScreenSaver, LPTSTR szSecure, LPTSTR szTimeOut, LPTSTR szActive)
  419. {
  420. DWORD dwType;
  421. DWORD ulLen;
  422. HKEY hKey;
  423. //
  424. // Open the desktop key
  425. //
  426. if (RegOpenKeyEx(HKEY_CURRENT_USER, WR_DESKTOP, 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  427. {
  428. return FALSE;
  429. }
  430. //
  431. // Get the screen saver Path
  432. //
  433. ulLen = sizeof(TCHAR) * MAX_PATH; // must be bytes not TCHAR
  434. if (RegQueryValueEx(hKey, WR_SCREENSAVER, NULL, &dwType, (LPBYTE) szScreenSaver, &ulLen) != ERROR_SUCCESS)
  435. {
  436. RegCloseKey(hKey);
  437. return FALSE;
  438. }
  439. //
  440. // Get the screen saver Secure
  441. //
  442. ulLen = sizeof(TCHAR) * MAX_NAME_LENGTH; // must be bytes not TCHAR
  443. if (RegQueryValueEx(hKey, WR_SECURE, NULL, &dwType, (LPBYTE) szSecure, &ulLen) != ERROR_SUCCESS)
  444. {
  445. RegCloseKey(hKey);
  446. return FALSE;
  447. }
  448. //
  449. // Get the screen saver TimeOut
  450. //
  451. ulLen = sizeof(TCHAR) * MAX_NAME_LENGTH; // must be bytes not TCHAR
  452. if (RegQueryValueEx(hKey, WR_TIMEOUT, NULL, &dwType, (LPBYTE) szTimeOut, &ulLen) != ERROR_SUCCESS)
  453. {
  454. RegCloseKey(hKey);
  455. return FALSE;
  456. }
  457. //
  458. // Get the screen saver Active
  459. //
  460. ulLen = sizeof(TCHAR) * MAX_NAME_LENGTH; // must be bytes not TCHAR
  461. if (RegQueryValueEx(hKey, WR_ACTIVE, NULL, &dwType, (LPBYTE) szActive, &ulLen) != ERROR_SUCCESS)
  462. {
  463. RegCloseKey(hKey);
  464. return FALSE;
  465. }
  466. RegCloseKey(hKey);
  467. return TRUE;
  468. }
  469. /*-------------------------------------------------------------------------------------*/
  470. /*-------------------------------------------------------------------------------------*/
  471. BOOL Reg_SetScreenSaver(LPCTSTR szScreenSaver, LPCTSTR szSecure, LPCTSTR szTimeOut, LPCTSTR szActive)
  472. {
  473. TCHAR szOldScreenSaver[MAX_PATH];
  474. TCHAR szOldSecure[MAX_PATH];
  475. TCHAR szOldTimeOut[MAX_PATH];
  476. TCHAR szOldActive[MAX_PATH];
  477. DWORD dwType;
  478. DWORD ulLen;
  479. HKEY hKey;
  480. //
  481. // Open the desktop key
  482. //
  483. if (RegOpenKeyEx(HKEY_CURRENT_USER, WR_DESKTOP, 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  484. {
  485. return FALSE;
  486. }
  487. //
  488. // Get the screen saver Path
  489. //
  490. ulLen = sizeof(TCHAR) * MAX_PATH;
  491. if (RegQueryValueEx(hKey, WR_SCREENSAVER, NULL, &dwType, (LPBYTE) szOldScreenSaver, &ulLen) != ERROR_SUCCESS)
  492. {
  493. RegCloseKey(hKey);
  494. return FALSE;
  495. }
  496. if (lstrcmp(szOldScreenSaver, szScreenSaver))
  497. RegSetValueEx(hKey, WR_SCREENSAVER, 0, REG_SZ, (LPBYTE) szScreenSaver,
  498. sizeof(TCHAR) * (lstrlen(szScreenSaver) + 1));
  499. //
  500. // Get the screen saver Secure
  501. //
  502. ulLen = sizeof(TCHAR) * MAX_PATH;
  503. if (RegQueryValueEx(hKey, WR_SECURE, NULL, &dwType, (LPBYTE) szOldSecure, &ulLen) != ERROR_SUCCESS)
  504. {
  505. RegCloseKey(hKey);
  506. return FALSE;
  507. }
  508. if (lstrcmp(szOldSecure, szSecure))
  509. RegSetValueEx(hKey, WR_SECURE, 0, REG_SZ, (LPBYTE) szSecure,
  510. sizeof(TCHAR) * (lstrlen(szSecure) + 1));
  511. //
  512. // Get the screen saver TimeOut
  513. //
  514. ulLen = sizeof(TCHAR) * MAX_PATH;
  515. if (RegQueryValueEx(hKey, WR_TIMEOUT, NULL, &dwType, (LPBYTE) szOldTimeOut, &ulLen) != ERROR_SUCCESS)
  516. {
  517. RegCloseKey(hKey);
  518. return FALSE;
  519. }
  520. if (lstrcmp(szOldTimeOut, szTimeOut))
  521. RegSetValueEx(hKey, WR_TIMEOUT, 0, REG_SZ, (LPBYTE) szTimeOut,
  522. sizeof(TCHAR) * (lstrlen(szTimeOut) + 1));
  523. //
  524. // Get the screen saver Active
  525. //
  526. ulLen = sizeof(TCHAR) * MAX_PATH;
  527. if (RegQueryValueEx(hKey, WR_ACTIVE, NULL, &dwType, (LPBYTE) szOldActive, &ulLen) != ERROR_SUCCESS)
  528. {
  529. RegCloseKey(hKey);
  530. return FALSE;
  531. }
  532. if (lstrcmp(szOldActive, szActive))
  533. RegSetValueEx(hKey, WR_ACTIVE, 0, REG_SZ, (LPBYTE) szActive,
  534. sizeof(TCHAR) * (lstrlen(szActive) + 1));
  535. RegCloseKey(hKey);
  536. return TRUE;
  537. }
  538. /*-------------------------------------------------------------------------------------*/
  539. /*-------------------------------------------------------------------------------------*/
  540. BOOL Reg_GetWallpaper(LPTSTR szWallpaper, LPTSTR szTile)
  541. {
  542. DWORD dwType;
  543. DWORD ulLen;
  544. HKEY hKey;
  545. //
  546. // Open the desktop key
  547. //
  548. if (RegOpenKeyEx(HKEY_CURRENT_USER, WR_DESKTOP, 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  549. {
  550. return FALSE;
  551. }
  552. //
  553. // Get the wallpaper Path
  554. //
  555. ulLen = sizeof(TCHAR) * MAX_PATH;
  556. if (RegQueryValueEx(hKey, WR_WALLPAPER, NULL, &dwType, (LPBYTE) szWallpaper, &ulLen) != ERROR_SUCCESS)
  557. {
  558. RegCloseKey(hKey);
  559. return FALSE;
  560. }
  561. //
  562. // Get the wallpaper Tile attribute
  563. //
  564. ulLen = sizeof(TCHAR) * MAX_PATH;
  565. if (RegQueryValueEx(hKey, WR_TILE, NULL, &dwType, (LPBYTE) szTile, &ulLen) != ERROR_SUCCESS)
  566. {
  567. RegCloseKey(hKey);
  568. return FALSE;
  569. }
  570. RegCloseKey(hKey);
  571. return TRUE;
  572. }
  573. /*-------------------------------------------------------------------------------------*/
  574. /*-------------------------------------------------------------------------------------*/
  575. BOOL Reg_SetWallpaper(LPCTSTR szWallpaper, LPCTSTR szTile)
  576. {
  577. TCHAR szOldWallpaper[MAX_PATH];
  578. TCHAR szOldTile[MAX_PATH];
  579. DWORD dwType;
  580. DWORD ulLen;
  581. HKEY hKey;
  582. //
  583. // Open the desktop key
  584. //
  585. if (RegOpenKeyEx(HKEY_CURRENT_USER, WR_DESKTOP, 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  586. {
  587. return FALSE;
  588. }
  589. //
  590. // Get the wallpaper Path
  591. //
  592. ulLen = sizeof(TCHAR) * MAX_PATH;
  593. if (RegQueryValueEx(hKey, WR_WALLPAPER, NULL, &dwType, (LPBYTE) szOldWallpaper, &ulLen) != ERROR_SUCCESS)
  594. {
  595. RegCloseKey(hKey);
  596. return FALSE;
  597. }
  598. if (lstrcmp(szOldWallpaper, szWallpaper))
  599. RegSetValueEx(hKey, WR_WALLPAPER, 0, REG_SZ, (const LPBYTE) szWallpaper,
  600. sizeof(TCHAR) * (lstrlen(szWallpaper) + 1));
  601. //
  602. // Get the wallpaper Tile Attribute
  603. //
  604. ulLen = sizeof(TCHAR) * MAX_PATH;
  605. if (RegQueryValueEx(hKey, WR_TILE, NULL, &dwType, (LPBYTE) szOldTile, &ulLen) != ERROR_SUCCESS)
  606. {
  607. RegCloseKey(hKey);
  608. return FALSE;
  609. }
  610. if (lstrcmp(szOldTile, szTile))
  611. RegSetValueEx(hKey, WR_TILE, 0, REG_SZ, (const LPBYTE) szTile,
  612. sizeof(TCHAR) * (lstrlen(szTile) + 1));
  613. RegCloseKey(hKey);
  614. return TRUE;
  615. }
  616. //////////////////////////////////////////////////////////////////////////////////////
  617. //
  618. //
  619. //
  620. BOOL Profile_LoadScheme(UINT DesktopNumber, PDESKTOP_SCHEME pDesktopScheme)
  621. {
  622. DWORD dwType;
  623. DWORD ulLen;
  624. HKEY hKey;
  625. TCHAR DesktopKey[MAX_PATH + 1];
  626. int i;
  627. //
  628. // Open the MultiDesk\Context\DesktopNumber key
  629. //
  630. wsprintf(DesktopKey, MD_CONTEXT TEXT("\\%02d"), DesktopNumber);
  631. if (RegOpenKeyEx(HKEY_CURRENT_USER, DesktopKey, 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  632. {
  633. return FALSE;
  634. }
  635. //
  636. // Read the color settings
  637. //
  638. for (i = 0; i < NUM_COLOR_ELEMENTS; i++) {
  639. ulLen = sizeof(DWORD);
  640. if (RegQueryValueEx(hKey, szRegColorNames[i], 0, &dwType, (LPBYTE) &pDesktopScheme->dwColor[i], &ulLen) != ERROR_SUCCESS) {
  641. RegCloseKey(hKey);
  642. return FALSE;
  643. }
  644. }
  645. //
  646. // Get the pattern
  647. //
  648. ulLen = sizeof(pDesktopScheme->szPattern); // must be bytes not TCHAR
  649. if (RegQueryValueEx(hKey, WR_PATTERN, NULL, &dwType, (LPBYTE) pDesktopScheme->szPattern, &ulLen) != ERROR_SUCCESS)
  650. {
  651. RegCloseKey(hKey);
  652. return FALSE;
  653. }
  654. //
  655. // Get the screen saver Path
  656. //
  657. ulLen = sizeof(pDesktopScheme->szScreenSaver); // must be bytes not TCHAR
  658. if (RegQueryValueEx(hKey, WR_SCREENSAVER, NULL, &dwType, (LPBYTE) pDesktopScheme->szScreenSaver, &ulLen) != ERROR_SUCCESS)
  659. {
  660. RegCloseKey(hKey);
  661. return FALSE;
  662. }
  663. //
  664. // Get the screen saver Secure
  665. //
  666. ulLen = sizeof(pDesktopScheme->szSecure); // must be bytes not TCHAR
  667. if (RegQueryValueEx(hKey, WR_SECURE, NULL, &dwType, (LPBYTE) pDesktopScheme->szSecure, &ulLen) != ERROR_SUCCESS)
  668. {
  669. RegCloseKey(hKey);
  670. return FALSE;
  671. }
  672. //
  673. // Get the screen saver TimeOut
  674. //
  675. ulLen = sizeof(pDesktopScheme->szTimeOut); // must be bytes not TCHAR
  676. if (RegQueryValueEx(hKey, WR_TIMEOUT, NULL, &dwType, (LPBYTE) pDesktopScheme->szTimeOut, &ulLen) != ERROR_SUCCESS)
  677. {
  678. RegCloseKey(hKey);
  679. return FALSE;
  680. }
  681. //
  682. // Get the screen saver Active
  683. //
  684. ulLen = sizeof(pDesktopScheme->szActive); // must be bytes not TCHAR
  685. if (RegQueryValueEx(hKey, WR_ACTIVE, NULL, &dwType, (LPBYTE) pDesktopScheme->szActive, &ulLen) != ERROR_SUCCESS)
  686. {
  687. RegCloseKey(hKey);
  688. return FALSE;
  689. }
  690. //
  691. // Get the wallpaper Path
  692. //
  693. ulLen = sizeof(pDesktopScheme->szWallpaper); // bytes not TCHAR
  694. if (RegQueryValueEx(hKey, WR_WALLPAPER, NULL, &dwType, (LPBYTE) pDesktopScheme->szWallpaper, &ulLen) != ERROR_SUCCESS)
  695. {
  696. RegCloseKey(hKey);
  697. return FALSE;
  698. }
  699. //
  700. // Get the wallpaper Tile attribute
  701. //
  702. ulLen = sizeof(pDesktopScheme->szTile); // bytes not TCHAR
  703. if (RegQueryValueEx(hKey, WR_TILE, NULL, &dwType, (LPBYTE) pDesktopScheme->szTile, &ulLen) != ERROR_SUCCESS)
  704. {
  705. RegCloseKey(hKey);
  706. return FALSE;
  707. }
  708. RegCloseKey(hKey);
  709. return TRUE;
  710. }
  711. //////////////////////////////////////////////////////////////////////////////////////
  712. //
  713. //
  714. //
  715. BOOL Profile_SaveScheme(UINT DesktopNumber, PDESKTOP_SCHEME pDesktopScheme)
  716. {
  717. DWORD dwDisposition;
  718. HKEY hKey;
  719. TCHAR DesktopKey[MAX_PATH + 1];
  720. int i;
  721. //
  722. // Ensure that the ..\MultiDesk Subkey exists, and if not create it.
  723. //
  724. if (RegCreateKeyEx(HKEY_CURRENT_USER, MD_MULTIDESK, 0, TEXT(""), REG_OPTION_NON_VOLATILE,
  725. KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) != ERROR_SUCCESS)
  726. {
  727. return FALSE;
  728. }
  729. RegCloseKey(hKey);
  730. //
  731. // As above, ensure that the ..\MultiDesk\Context subkey exist
  732. //
  733. if (RegCreateKeyEx(HKEY_CURRENT_USER, MD_CONTEXT, 0, TEXT(""), REG_OPTION_NON_VOLATILE,
  734. KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) != ERROR_SUCCESS)
  735. {
  736. return FALSE;
  737. }
  738. RegCloseKey(hKey);
  739. //
  740. // Open the Desktop key, Create it if it doesn't exist
  741. //
  742. wsprintf(DesktopKey, MD_CONTEXT TEXT("\\%02d"), DesktopNumber);
  743. if (RegCreateKeyEx(HKEY_CURRENT_USER, DesktopKey, 0, TEXT(""), REG_OPTION_NON_VOLATILE,
  744. KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) != ERROR_SUCCESS)
  745. {
  746. return FALSE;
  747. }
  748. //
  749. // Write the pattern
  750. //
  751. RegSetValueEx(hKey, WR_PATTERN, 0, REG_SZ, (LPBYTE) pDesktopScheme->szPattern,
  752. sizeof(TCHAR) * (lstrlen(pDesktopScheme->szPattern) + 1));
  753. //
  754. // Write the Screen Saver settings
  755. //
  756. RegSetValueEx(hKey, WR_SCREENSAVER, 0, REG_SZ, (LPBYTE) pDesktopScheme->szScreenSaver,
  757. sizeof(TCHAR) * (lstrlen(pDesktopScheme->szScreenSaver) + 1));
  758. RegSetValueEx(hKey, WR_SECURE, 0, REG_SZ, (LPBYTE) pDesktopScheme->szSecure,
  759. sizeof(TCHAR) * (lstrlen(pDesktopScheme->szSecure) + 1));
  760. RegSetValueEx(hKey, WR_TIMEOUT, 0, REG_SZ, (LPBYTE) pDesktopScheme->szTimeOut,
  761. sizeof(TCHAR) * (lstrlen(pDesktopScheme->szTimeOut) + 1));
  762. RegSetValueEx(hKey, WR_ACTIVE, 0, REG_SZ, (LPBYTE) pDesktopScheme->szActive,
  763. sizeof(TCHAR) * (lstrlen(pDesktopScheme->szActive) + 1));
  764. //
  765. // write the wallpaper settings
  766. //
  767. RegSetValueEx(hKey, WR_WALLPAPER, 0, REG_SZ, (LPBYTE) pDesktopScheme->szWallpaper,
  768. sizeof(TCHAR) * (lstrlen(pDesktopScheme->szWallpaper) + 1));
  769. RegSetValueEx(hKey, WR_TILE, 0, REG_SZ, (LPBYTE) pDesktopScheme->szTile,
  770. sizeof(TCHAR) * (lstrlen(pDesktopScheme->szTile) + 1));
  771. //
  772. //
  773. // Write the color settings
  774. //
  775. for (i = 0; i < NUM_COLOR_ELEMENTS; i++) {
  776. RegSetValueEx(hKey, szRegColorNames[i], 0, REG_BINARY,
  777. (LPBYTE) &pDesktopScheme->dwColor[i], sizeof(DWORD));
  778. }
  779. RegCloseKey(hKey);
  780. return TRUE;
  781. }