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.

687 lines
21 KiB

  1. /* BKGD.C
  2. Resident Code Segment // Tweak: make non-resident?
  3. Most of this code is taken from the display CPLs adjusted to
  4. work with the Theme Switcher and cleaned up a little.
  5. Routines for painting the preview box in the main window
  6. Desktop (wallpaper/pattern/color)
  7. Icons
  8. Windows
  9. Frosting: Master Theme Selector for Windows '95
  10. Copyright (c) 1994-1998 Microsoft Corporation
  11. */
  12. // ---------------------------------------------
  13. // Brief file history:
  14. // Alpha:
  15. // Beta:
  16. // Bug fixes
  17. // ---------
  18. #include "windows.h"
  19. #include "frost.h"
  20. #include "global.h"
  21. #include "adutil.h"
  22. #include "bkgd.h"
  23. #include "LoadImag.h"
  24. #include "htmlprev.h"
  25. #include "schedule.h" // IsPlatormNT and GetCurrentUser
  26. // #define BMPOUT 333 // debugging aid
  27. #ifdef BMPOUT
  28. #define BmpOut(x,y,z); hbmDebOld=SelectObject(hdcDeb,x);BitBlt(hdcOut,0,0,y,z,hdcDeb,0,0,SRCCOPY);SelectObject(hdcDeb,hbmDebOld);
  29. #define PrevOut(); BitBlt(hdcOut,0,0,dxPreview,dyPreview,g_hdcMem,0,0,SRCCOPY);
  30. #endif
  31. // globals
  32. extern BOOL bInGrphFilter; // frost.c Currently in a graphics filter?
  33. TCHAR szCP_DT[] = TEXT("Control Panel\\Desktop");
  34. TCHAR szWP[] = TEXT("Wallpaper");
  35. TCHAR szTileWP[] = TEXT("TileWallpaper");
  36. extern TCHAR szWPStyle[];
  37. TCHAR szPat[] = TEXT("Pattern");
  38. extern TCHAR szSS_Active[];
  39. extern HPALETTE hpal3D; // fakewin.c
  40. HBITMAP g_hbmPreview = NULL; // the bitmap used for previewing
  41. HDC g_hdcMem = NULL;
  42. HBITMAP g_hbmWall = NULL; // bitmap image of wallpaper
  43. HDC g_hdcWall = NULL; // memory DC with g_hbmWall selected
  44. HPALETTE g_hpalWall = NULL; // palette that goes with hbmWall bitmap
  45. HBRUSH g_hbrBack = NULL; // brush for the desktop background
  46. HBITMAP g_hbmDefault = NULL;
  47. DWORD dwStyle = 0; // WP Style for new ActiveDesktop interface
  48. // L o c a l R o u t i n e s
  49. COLORREF GetThemeColor(LPTSTR, int);
  50. extern TCHAR szFrostSection[];
  51. extern TCHAR szThemeBPP[];
  52. extern TCHAR szImageBPP[];
  53. TCHAR szImageDither[] = TEXT("Dither");
  54. TCHAR szImageStretch[] = TEXT("Stretch");
  55. TCHAR szPlusKey[] = TEXT("Software\\Microsoft\\Plus!\\Themes");
  56. //
  57. // if the theme is 8bpp only load 8bpp images (bpp=8)
  58. // otherwise load the best for the display (bpp=-1)
  59. //
  60. // currently this is kind of bogus, we should mark the 8bit themes
  61. // as 8bit not the other way around!
  62. //
  63. // return
  64. // -1 load the image at the depth of the display
  65. // 8 load the image at 8bpp
  66. //
  67. int GetImageBPP(LPCTSTR lpszThemeFile)
  68. {
  69. int bpp = -1;
  70. if (*lpszThemeFile && bCBStates[FC_WALL]) {
  71. bpp = GetPrivateProfileInt(szFrostSection, szImageBPP, -1, lpszThemeFile);
  72. if (bpp != 8)
  73. bpp = -1;
  74. }
  75. return bpp;
  76. }
  77. //
  78. //
  79. // When applying wallpaper (if decompressed from a .jpg), first check:
  80. // are user profiles enabled?
  81. // HKLM\Network\Logon, UserProfiles=<dword> will be non-zero if
  82. // profiles are enabled.
  83. //
  84. // then
  85. // Call WNetGetUser to get the username
  86. // then look under:
  87. // HKLM\Software\Microsoft\Windows\CurrentVersion\ProfileList\<username>
  88. // there should be a value ProfileImagePath which is the local path.
  89. //
  90. //then store Plus!.bmp there
  91. void GetPlusBitmapName(LPTSTR szPlus)
  92. {
  93. HKEY hkey;
  94. DWORD dw;
  95. UINT cb;
  96. TCHAR key[80];
  97. TCHAR ach[80];
  98. if (!GetWindowsDirectory(szPlus, MAX_PATH))
  99. {
  100. szPlus[0] = 0;
  101. }
  102. if (IsPlatformNT())
  103. {
  104. // User profiles are always enabled un NT so find the correct
  105. // path
  106. TCHAR szAccount[MAX_PATH];
  107. TCHAR szDomain[MAX_PATH];
  108. GetCurrentUser(szAccount, ARRAYSIZE(szAccount),
  109. szDomain, ARRAYSIZE(szDomain),
  110. szPlus, MAX_PATH);
  111. InstantiatePath(szPlus, ARRAYSIZE(szPlus));
  112. Assert(FALSE, TEXT("Plus!.BMP path: "));
  113. Assert(FALSE, szPlus);
  114. Assert(FALSE, TEXT("\n"));
  115. }
  116. else if (RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("Network\\Logon"), &hkey) == 0)
  117. {
  118. cb = sizeof(dw); dw = 0;
  119. RegQueryValueEx(hkey, TEXT("UserProfiles"), NULL, NULL, (LPVOID)&dw, &cb);
  120. RegCloseKey(hkey);
  121. if (dw != 0)
  122. {
  123. cb = ARRAYSIZE(ach); ach[0] = 0;
  124. WNetGetUser(NULL, ach, &cb);
  125. if (ach[0])
  126. {
  127. wsprintf(key, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\ProfileList\\%s"), ach);
  128. if (RegOpenKey(HKEY_LOCAL_MACHINE, key, &hkey) == 0)
  129. {
  130. cb = sizeof(ach); ach[0] = 0;
  131. RegQueryValueEx(hkey, TEXT("ProfileImagePath"), NULL, NULL, (LPBYTE)ach, &cb);
  132. RegCloseKey(hkey);
  133. if (ach[0] && GetFileAttributes(ach) != -1)
  134. {
  135. lstrcpy(szPlus, ach);
  136. Assert(FALSE, TEXT("Plus!.BMP path: "));
  137. Assert(FALSE, szPlus);
  138. Assert(FALSE, TEXT("\n"));
  139. }
  140. }
  141. }
  142. }
  143. }
  144. lstrcat(szPlus, TEXT("\\Plus!.bmp"));
  145. }
  146. //
  147. // LoadWallpaper
  148. //
  149. HBITMAP LoadWallpaper(LPTSTR szWallpaper, LPTSTR szThemeFile, BOOL fPreview)
  150. {
  151. HBITMAP hbm=NULL;
  152. TCHAR plus_bmp[MAX_PATH]; //DSCHOTT switched from 128 to MAX_PATH
  153. TCHAR ach[MAX_PATH]; //DSCHOTT switched from 128 to MAX_PATH
  154. int dx, dy;
  155. DWORD dw;
  156. int bpp = GetImageBPP(szThemeFile);
  157. int dither = DITHER_CUSTOM;
  158. int tile = GetRegInt(HKEY_CURRENT_USER, szCP_DT, szTileWP, 0);
  159. int stretch= GetRegInt(HKEY_CURRENT_USER, szCP_DT, szWPStyle, 0) & 2;
  160. // If a theme is selected, and we are using a plus wall paper then
  161. // find out if tiling is on, and what style to use from the ini file.
  162. // Otherwise, we already got the information from the registry.
  163. if (szThemeFile && *szThemeFile && bCBStates[FC_WALL])
  164. {
  165. tile = GetPrivateProfileInt(szCP_DT, szTileWP, tile, szThemeFile);
  166. stretch= GetPrivateProfileInt(szCP_DT, szWPStyle, stretch, szThemeFile) & 2;
  167. dither = GetPrivateProfileInt(szFrostSection, szImageDither, dither, szThemeFile);
  168. stretch= GetPrivateProfileInt(szFrostSection, szImageStretch, stretch, szThemeFile);
  169. }
  170. //
  171. // allow the user to override theme switches
  172. //
  173. bpp = GetRegInt(HKEY_CURRENT_USER, szPlusKey, szImageBPP, bpp);
  174. dither = GetRegInt(HKEY_CURRENT_USER, szPlusKey, szImageDither, dither);
  175. // First try getting this stretch value from IActiveDesktop if
  176. // it's on.
  177. if (IsActiveDesktopOn()) {
  178. if (GetADWPOptions(&dw)) if (WPSTYLE_STRETCH == dw) stretch = 1;
  179. }
  180. // AD is off so get the Stretch value from the registry
  181. else stretch= GetRegInt(HKEY_CURRENT_USER, szPlusKey,
  182. szImageStretch, stretch);
  183. // If our wallpaper is an HTML page we need to force stretching
  184. // on and tiling off
  185. if (szWallpaper && ((lstrcmpi(FindExtension(szWallpaper),TEXT(".htm")) == 0) ||
  186. (lstrcmpi(FindExtension(szWallpaper),TEXT(".html")) == 0)))
  187. {
  188. tile = 0;
  189. stretch = 1;
  190. }
  191. //
  192. // if the stretch wallpaper option is set (style & 2) then load the
  193. // wallpaper the size of our preview window, else we need to load the
  194. // wallpaper in the right proportion (passing a <0 size to
  195. // LoadImageFromFile will cause it to stretch it)
  196. //
  197. if (!tile && stretch)
  198. {
  199. dx = fPreview ? dxPreview : GetSystemMetrics(SM_CXSCREEN);
  200. dy = fPreview ? dyPreview : GetSystemMetrics(SM_CYSCREEN);
  201. }
  202. else
  203. {
  204. dx = fPreview ? -dxPreview : 0;
  205. dy = fPreview ? -dyPreview : 0;
  206. }
  207. // Build a full path to the plus!.bmp file
  208. GetPlusBitmapName(plus_bmp);
  209. ach[0] = 0;
  210. dw = GetImageTitle(plus_bmp, ach, sizeof(ach));
  211. //
  212. // see if we can use Plus!.bmp
  213. //
  214. if (ach[0] && lstrcmpi(ach, szWallpaper) == 0 && (dx==0 || (int)dw==MAKELONG(dx,dy)))
  215. {
  216. szWallpaper = plus_bmp;
  217. }
  218. return CacheLoadImageFromFile(szWallpaper, dx, dy, bpp, dither);
  219. }
  220. // PaintPreview
  221. //
  222. // This is the routine that draws the entire preview area: the
  223. // background image, three icons, and the sample window preview.
  224. // The sample window is drawn with MS-supplied code.
  225. //
  226. void FAR PaintPreview(HWND hDlg, HDC hdc, PRECT prect)
  227. {
  228. HBITMAP hbmOld;
  229. //
  230. // inits
  231. //
  232. hbmOld = SelectObject(g_hdcMem, g_hbmPreview);
  233. if (g_hpalWall)
  234. {
  235. SelectPalette(hdc, g_hpalWall, FALSE);
  236. RealizePalette(hdc);
  237. }
  238. //
  239. // painting: assume clip rect set correctly already
  240. BitBlt(hdc, rView.left, rView.top, dxPreview, dyPreview, g_hdcMem, 0, 0, SRCCOPY);
  241. //
  242. // cleanup
  243. if (g_hpalWall)
  244. SelectPalette(hdc, GetStockObject(DEFAULT_PALETTE), TRUE);
  245. SelectObject(g_hdcMem, hbmOld);
  246. }
  247. /*--------------------------------------------------------------------
  248. ** Build the preview bitmap.
  249. Gets the settings from the current theme file and inits
  250. a preview bitmap for later painting.
  251. Start with the pattern or wallpaper or bkgd color.
  252. Add the icons and then the sample windows.
  253. Started with control panel code and did a lot of customization,
  254. including more comments, especially where made additions.
  255. Uses settings either from cur theme file, or if that is null
  256. then from system settings (i.e. for Cur Win Settings).
  257. Not as robust as I'd like, but seems to be acceptable for CPL.
  258. Tried to speed some things up, since this gets called on each
  259. combo box selection.
  260. **--------------------------------------------------------------------*/
  261. // virtual boolean: null theme name means Cur Win Settings, not from theme file
  262. #define bThemed (*lpszThemeFile)
  263. void FAR PASCAL BuildPreviewBitmap(LPTSTR lpszThemeFile)
  264. {
  265. UINT uret;
  266. UINT style;
  267. UINT tile;
  268. HBRUSH hbr = NULL;
  269. HBITMAP hbmTemp;
  270. HBITMAP hbmOld;
  271. BITMAP bm;
  272. COLORREF clrOldBk, clrOldText;
  273. WORD patbits[CXYDESKPATTERN] = {0, 0, 0, 0, 0, 0, 0, 0};
  274. int i;
  275. int dxWall; // size of wallpaper
  276. int dyWall;
  277. #ifdef BMPOUT
  278. HDC hdcOut;
  279. HDC hdcDeb;
  280. HBITMAP hbmDebOld;
  281. hdcOut = GetDC(NULL);
  282. hdcDeb = CreateCompatibleDC(hdcOut);
  283. #endif
  284. Assert(FALSE, TEXT("Building Preview bitmap: "));
  285. Assert(FALSE, szCurThemeName);
  286. Assert(FALSE, TEXT("\n"));
  287. hbmOld = SelectObject(g_hdcMem, g_hbmPreview);
  288. /*
  289. ** first, fill in the pattern all over the bitmap
  290. */
  291. // get rid of old brush if there was one
  292. if (g_hbrBack)
  293. DeleteObject(g_hbrBack);
  294. g_hbrBack = NULL;
  295. // get pattern from current theme file
  296. if (bThemed && bCBStates[FC_WALL]) { // theme file and checkbox
  297. uret = (UINT) GetPrivateProfileString((LPTSTR)szCP_DT, (LPTSTR)szPat,
  298. (LPTSTR)szNULL,
  299. (LPTSTR)pValue, MAX_VALUELEN,
  300. lpszThemeFile);
  301. Assert(uret, TEXT("problem getting stored pattern for preview bmp\n"));
  302. }
  303. // or, from the system
  304. else { // cur system settings
  305. // If ActiveDesktop is enabled we'll get the current settings
  306. // from the IActiveDesktop interface otherwise we'll do it
  307. // the "old" way by reading directly from the registry.
  308. if (IsActiveDesktopOn()) {
  309. if (!GetADWPPattern(pValue)) {
  310. // Failed to get pattern so invalidate the pattern
  311. // by making string look like (None).
  312. pValue[0] = TEXT('(');
  313. }
  314. }
  315. else {
  316. // No AD so do it the old way.
  317. GetRegString(HKEY_CURRENT_USER, szCP_DT, szPat,
  318. szNULL, pValue, (MAX_VALUELEN * sizeof(TCHAR)));
  319. }
  320. }
  321. // if you got a pattern, use it
  322. if (*pValue && (pValue[0] != TEXT('('))) // INTERNATIONAL? null or (None) cases
  323. // 5/95: "(None)" no longer written to registry by Win95
  324. {
  325. TranslatePattern(pValue, patbits);
  326. hbmTemp = CreateBitmap(8, 8, 1, 1, patbits);
  327. if (hbmTemp)
  328. {
  329. #ifdef BMPOUT
  330. BmpOut(hbmTemp,8,8);
  331. #endif
  332. g_hbrBack = CreatePatternBrush(hbmTemp);
  333. DeleteObject(hbmTemp);
  334. }
  335. }
  336. else // no pattern, so make a background brush
  337. {
  338. if (bThemed && bCBStates[FC_COLORS]) // theme file and checkbox
  339. g_hbrBack = CreateSolidBrush(GetThemeColor(lpszThemeFile, COLOR_BACKGROUND));
  340. else // cur system settings
  341. g_hbrBack = CreateSolidBrush(GetSysColor(COLOR_BACKGROUND));
  342. }
  343. if (!g_hbrBack)
  344. g_hbrBack = GetStockObject(BLACK_BRUSH);
  345. //
  346. // now do the actual pattern painting
  347. if (bThemed && bCBStates[FC_COLORS]) { // theme file and checkbox
  348. clrOldText = SetTextColor(g_hdcMem, GetThemeColor(lpszThemeFile, COLOR_BACKGROUND));
  349. clrOldBk = SetBkColor(g_hdcMem, GetThemeColor(lpszThemeFile, COLOR_WINDOWTEXT));
  350. }
  351. else { // cur system settings
  352. clrOldText = SetTextColor(g_hdcMem, GetSysColor(COLOR_BACKGROUND));
  353. clrOldBk = SetBkColor(g_hdcMem, GetSysColor(COLOR_WINDOWTEXT));
  354. }
  355. hbr = SelectObject(g_hdcMem, g_hbrBack);
  356. PatBlt(g_hdcMem, 0, 0, dxPreview, dyPreview, PATCOPY);
  357. SelectObject(g_hdcMem, hbr);
  358. #ifdef BMPOUT
  359. BmpOut(g_hbmPreview,dxPreview,dyPreview);
  360. PrevOut();
  361. #endif
  362. SetTextColor(g_hdcMem, clrOldText);
  363. SetBkColor(g_hdcMem, clrOldBk);
  364. /*
  365. ** now, position the wallpaper appropriately
  366. */
  367. // get rid of old wallpaper if there is any
  368. if (g_hbmWall)
  369. {
  370. SelectObject(g_hdcWall, g_hbmDefault);
  371. CacheDeleteBitmap(g_hbmWall);
  372. g_hbmWall = NULL;
  373. if (g_hpalWall)
  374. {
  375. if (g_hpalWall != hpal3D)
  376. DeleteObject(g_hpalWall);
  377. g_hpalWall = NULL;
  378. }
  379. }
  380. // call this early so hpal3D get setup (we will need it
  381. // to build the preview bitmap)
  382. FakewinSetTheme(lpszThemeFile);
  383. // get wallpaper bitmap from current theme file
  384. if (bThemed && bCBStates[FC_WALL]) { // theme file and checkbox
  385. uret = (UINT) GetPrivateProfileString((LPTSTR)szCP_DT, (LPTSTR)szWP,
  386. (LPTSTR)szNULL,
  387. (LPTSTR)pValue, MAX_VALUELEN,
  388. lpszThemeFile);
  389. // Assert(uret, TEXT("problem getting stored wallpaper file for preview bmp\n"));
  390. InstantiatePath((LPTSTR)pValue, MAX_VALUELEN);
  391. // search for file if necessary, see if found
  392. if (ConfirmFile((LPTSTR)pValue, TRUE) == CF_NOTFOUND) {
  393. GetRegString(HKEY_CURRENT_USER, szCP_DT, szWP, NULL, pValue, (MAX_VALUELEN * sizeof(TCHAR)));
  394. }
  395. }
  396. // or, from the system
  397. else { // cur system settings
  398. // If ActiveDesktop is enabled we'll get the current settings
  399. // from the IActiveDesktop interface otherwise we'll do it
  400. // the "old" way by reading directly from the registry.
  401. if (IsActiveDesktopOn()) {
  402. if (!GetADWallpaper(pValue)) {
  403. // Failed to get Wallpaper so invalidate the Wallpaper
  404. pValue[0] = TEXT('\0');
  405. }
  406. }
  407. else {
  408. // No AD so do it the old way.
  409. GetRegString(HKEY_CURRENT_USER, szCP_DT, szWP, NULL,
  410. pValue, (MAX_VALUELEN * sizeof(TCHAR)));
  411. }
  412. }
  413. // If ActiveDesktop is on get the Wallpaper options (Tile/Stretch/Center)
  414. // from the AD interface. Otherwise read directly from the registry.
  415. tile = 0;
  416. style = 0;
  417. if (IsActiveDesktopOn()) {
  418. if (GetADWPOptions(&dwStyle)) {
  419. if (WPSTYLE_TILE == dwStyle) tile = 1;
  420. if (WPSTYLE_STRETCH == dwStyle) style = 2; // 2 means stretch
  421. // Don't care about center apparently.
  422. }
  423. }
  424. else {
  425. // AD is not on so get this information from the registry.
  426. tile = GetRegInt(HKEY_CURRENT_USER, szCP_DT, szTileWP, 0);
  427. style = GetRegInt(HKEY_CURRENT_USER, szCP_DT, szWPStyle, 0);
  428. }
  429. // check tile flag, get information from theme file
  430. if (bThemed && bCBStates[FC_WALL]) { // theme file and checkbox
  431. tile = GetPrivateProfileInt(szCP_DT, szTileWP, tile, lpszThemeFile);
  432. style = GetPrivateProfileInt(szCP_DT, szWPStyle, style, lpszThemeFile);
  433. }
  434. if (*pValue && (pValue[0] != TEXT('(')))
  435. // PLUS98 BUG 1093
  436. // Don't call into the graphics filter if we're currently in the
  437. // graphics filter. Doing so will fault.
  438. if (!bInGrphFilter) {
  439. EnableWindow(GetDlgItem(hWndApp, DDL_THEME), FALSE);
  440. bInGrphFilter = TRUE;
  441. g_hbmWall = LoadWallpaper(pValue, lpszThemeFile, TRUE);
  442. bInGrphFilter = FALSE;
  443. EnableWindow(GetDlgItem(hWndApp, DDL_THEME), TRUE);
  444. SetFocus(hWndApp);
  445. SendMessage(hWndApp, DM_SETDEFID, IDOK, 0);
  446. }
  447. if (g_hbmWall) {
  448. SelectObject(g_hdcWall, g_hbmWall); // bitmap stays in this DC
  449. GetObject(g_hbmWall, sizeof(bm), &bm);
  450. }
  451. // get palette if appropriate
  452. if (GetDeviceCaps(g_hdcMem, RASTERCAPS) & RC_PALETTE) {
  453. DWORD adw[256+20+1];
  454. int n=0;
  455. if (g_hbmWall) {
  456. g_hpalWall = PaletteFromDS(g_hdcWall);
  457. // use the Halftone palette if the bitmap does not have one.
  458. if (g_hpalWall == NULL && bm.bmBitsPixel >= 8)
  459. g_hpalWall = CreateHalftonePalette(g_hdcMem);
  460. // now merge the 3D palette and the wallpaper palette.
  461. // we want the 3D (ie button shadow colors) to be first
  462. // and the wallpaper colors to be next.
  463. Assert(g_hpalWall, TEXT("null palette for bmp\n"));
  464. Assert(GetObject(hpal3D, sizeof(n), &n) && n==20, TEXT("hpal3D not valid or does not have 20 colors\n"));
  465. GetObject(g_hpalWall, sizeof(n), &n);
  466. GetPaletteEntries(hpal3D, 0, 20, (LPPALETTEENTRY)&adw[1]);
  467. GetPaletteEntries(g_hpalWall, 0, n, (LPPALETTEENTRY)&adw[21]);
  468. adw[0] = MAKELONG(0x0300, n+20);
  469. DeleteObject(g_hpalWall); // we dont need this anymore
  470. g_hpalWall = CreatePalette((LPLOGPALETTE)adw);
  471. Assert(g_hpalWall, TEXT("CreatePalette failed\n"));
  472. }
  473. else {
  474. g_hpalWall = hpal3D;
  475. }
  476. }
  477. if (g_hpalWall)
  478. {
  479. //make sure to select into a windowDC first
  480. //so a WM_PALETTECHANGE happens.
  481. HDC hdc = GetDC(hWndApp);
  482. SelectPalette(hdc, g_hpalWall, FALSE);
  483. RealizePalette(hdc);
  484. ReleaseDC(hWndApp, hdc);
  485. SelectPalette(g_hdcMem, g_hpalWall, FALSE);
  486. RealizePalette(g_hdcMem);
  487. }
  488. // do the painting
  489. if (g_hbmWall)
  490. {
  491. GetObject(g_hbmWall, sizeof(bm), &bm);
  492. // dxWall = MulDiv(bm.bmWidth, dxPreview, GetDeviceCaps(g_hdcMem, HORZRES));
  493. // dyWall = MulDiv(bm.bmHeight, dyPreview, GetDeviceCaps(g_hdcMem, VERTRES));
  494. dxWall = bm.bmWidth;
  495. dyWall = bm.bmHeight;
  496. if (dxWall < 1) dxWall = 1;
  497. if (dyWall < 1) dyWall = 1;
  498. IntersectClipRect(g_hdcMem, 0, 0, dxPreview, dyPreview);
  499. SetStretchBltMode(g_hdcMem, COLORONCOLOR);
  500. if (tile) // TRUE for tile flag set
  501. {
  502. StretchBlt(g_hdcMem, 0, 0, dxWall, dyWall,
  503. g_hdcWall, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
  504. for (i = dxWall; i < dxPreview; i+= dxWall)
  505. BitBlt(g_hdcMem, i, 0, dxWall, dyWall, g_hdcMem, 0, 0, SRCCOPY);
  506. for (i = 0; i < dyPreview; i += dyWall)
  507. BitBlt(g_hdcMem, 0, i, dxPreview, dyWall, g_hdcMem, 0, 0, SRCCOPY);
  508. }
  509. else if (style & 2)
  510. {
  511. StretchBlt(g_hdcMem, 0, 0, dxPreview, dyPreview,
  512. g_hdcWall, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
  513. }
  514. else
  515. {
  516. StretchBlt(g_hdcMem, (dxPreview - dxWall)/2, (dyPreview - dyWall)/2,
  517. dxWall, dyWall, g_hdcWall, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
  518. }
  519. #ifdef BMPOUT
  520. BmpOut(g_hbmPreview,dxPreview,dyPreview);
  521. PrevOut();
  522. #endif
  523. // restore dc
  524. SelectObject(g_hdcWall, g_hbmDefault);
  525. SelectPalette(g_hdcMem, GetStockObject(DEFAULT_PALETTE), TRUE);
  526. SelectClipRgn(g_hdcMem, NULL);
  527. }
  528. //
  529. // Now you can add the windows and icons on top of the background
  530. //
  531. // icons first
  532. IconsPreviewDraw(g_hdcMem, lpszThemeFile);
  533. // sample windows
  534. // FakewinSetTheme(lpszThemeFile);
  535. FakewinDraw(g_hdcMem);
  536. //
  537. // final cleanup
  538. SelectObject(g_hdcMem, hbmOld);
  539. // force repaint of preview area
  540. InvalidateRect(hWndApp, (LPRECT)&rView, FALSE);
  541. #ifdef BMPOUT
  542. DeleteDC(hdcDeb);
  543. ReleaseDC(NULL, hdcOut);
  544. #endif
  545. }
  546. //
  547. // GetThemeColor
  548. //
  549. // Utility routine that gets a color from the theme.
  550. //
  551. TCHAR szBkgdKey[] = TEXT("Background");
  552. TCHAR szTextKey[] = TEXT("WindowText");
  553. COLORREF GetThemeColor(LPTSTR lpszTheme, int iColorIndex)
  554. {
  555. COLORREF crRet;
  556. UINT uret;
  557. switch (iColorIndex) {
  558. case COLOR_BACKGROUND:
  559. uret = (UINT) GetPrivateProfileString((LPTSTR)szColorApp, (LPTSTR)szBkgdKey,
  560. (LPTSTR)szNULL,
  561. (LPTSTR)pValue, MAX_VALUELEN,
  562. lpszTheme);
  563. Assert(uret, TEXT("problem getting stored theme bkgd color\n"));
  564. break;
  565. case COLOR_WINDOWTEXT:
  566. uret = (UINT) GetPrivateProfileString((LPTSTR)szColorApp, (LPTSTR)szTextKey,
  567. (LPTSTR)szNULL,
  568. (LPTSTR)pValue, MAX_VALUELEN,
  569. lpszTheme);
  570. Assert(uret, TEXT("problem getting stored theme wintext color\n"));
  571. break;
  572. default:
  573. Assert(0, TEXT("unexpected color request in GetThemeColor()\n"));
  574. break;
  575. }
  576. if (*pValue)
  577. crRet = RGBStringToColor((LPTSTR)pValue);
  578. else
  579. crRet = RGB(0,0,0);
  580. return (crRet);
  581. }