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.

191 lines
5.0 KiB

  1. /* BKGDUTIL.C
  2. Buncha extra routines from CPL code.
  3. Frosting: Master Theme Selector for Windows '95
  4. Copyright (c) 1994-1998 Microsoft Corporation
  5. */
  6. #include "windows.h"
  7. #include "frost.h"
  8. #include "bkgd.h"
  9. #include "loadimag.h"
  10. #include <shlobj.h>
  11. extern HWND hWndApp; // Handle to Desktop Themes window
  12. /*----------------------------------------------------------------------------*\
  13. \*----------------------------------------------------------------------------*/
  14. HPALETTE FAR PaletteFromDS(HDC hdc)
  15. {
  16. DWORD adw[257];
  17. int i,n;
  18. n = GetDIBColorTable(hdc, 0, 256, (LPRGBQUAD)&adw[1]);
  19. adw[0] = MAKELONG(0x300, n);
  20. for (i=1; i<=n; i++)
  21. adw[i] = RGB(GetBValue(adw[i]),GetGValue(adw[i]),GetRValue(adw[i]));
  22. if (n == 0)
  23. return NULL;
  24. else
  25. return CreatePalette((LPLOGPALETTE)&adw[0]);
  26. }
  27. /*-------------------------------------------------------------
  28. ** given a pattern string from an ini file, return the pattern
  29. ** in a binary (ie useful) form.
  30. **-------------------------------------------------------------*/
  31. void FAR PASCAL TranslatePattern(LPTSTR lpStr, WORD FAR *patbits)
  32. {
  33. short i, val;
  34. /* Get eight groups of numbers seprated by non-numeric characters. */
  35. for (i = 0; i < CXYDESKPATTERN; i++)
  36. {
  37. val = 0;
  38. if (*lpStr != 0)
  39. {
  40. /* Skip over any non-numeric characters. */ // and watch for EOS
  41. while (*lpStr && !(*lpStr >= TEXT('0') && *lpStr <= TEXT('9'))) // JDK fixed CPL code bug
  42. lpStr++;
  43. /* Get the next series of digits. */
  44. while (*lpStr >= TEXT('0') && *lpStr <= TEXT('9'))
  45. val = val*10 + *lpStr++ - TEXT('0');
  46. }
  47. patbits[i] = val;
  48. }
  49. return;
  50. }
  51. BOOL FAR PASCAL PreviewInit(void)
  52. {
  53. HDC hdc;
  54. HBITMAP hbm;
  55. HBRUSH hbr;
  56. // numbers
  57. dxPreview = rView.right-rView.left;
  58. dyPreview = rView.bottom-rView.top;
  59. // use hDlg DC as reference
  60. hdc = GetDC(hWndApp);
  61. // DCs
  62. g_hdcWall = CreateCompatibleDC(hdc);
  63. g_hdcMem = CreateCompatibleDC(hdc);
  64. // bitmap
  65. g_hbmPreview = CreateCompatibleBitmap(hdc, dxPreview, dyPreview);
  66. ReleaseDC(NULL, hdc);
  67. // check up on new toys
  68. if (!g_hdcWall || !g_hdcMem || !g_hbmPreview)
  69. return FALSE;
  70. // default bitmap
  71. hbm = CreateBitmap(1, 1, 1, 1, NULL);
  72. g_hbmDefault = SelectObject(g_hdcWall, hbm); // cpl code never deletes this
  73. SelectObject(g_hdcWall, g_hbmDefault);
  74. DeleteObject(hbm);
  75. // init the bitmap with something
  76. hbm = SelectObject(g_hdcWall, g_hbmPreview);
  77. hbr = SelectObject(g_hdcWall, GetSysColorBrush(COLOR_DESKTOP));
  78. PatBlt(g_hdcWall, 0, 0, dxPreview, dyPreview, PATCOPY);
  79. SelectObject(g_hdcWall, hbm);
  80. SelectObject(g_hdcWall, hbr);
  81. // catch fake sample window and icons init, too
  82. return (FakewinInit() && IconsPreviewInit());
  83. }
  84. void FAR PASCAL PreviewDestroy(void)
  85. {
  86. if (g_hbmPreview)
  87. {
  88. DeleteObject(g_hbmPreview);
  89. g_hbmPreview = NULL;
  90. }
  91. if (g_hbmWall)
  92. {
  93. SelectObject(g_hdcWall, g_hbmDefault);
  94. CacheDeleteBitmap(g_hbmWall);
  95. g_hbmWall = NULL;
  96. }
  97. if (g_hpalWall)
  98. {
  99. extern HPALETTE hpal3D; // fakewin.c
  100. SelectPalette(g_hdcWall, GetStockObject(DEFAULT_PALETTE), TRUE);
  101. if (g_hpalWall != hpal3D)
  102. DeleteObject(g_hpalWall);
  103. g_hpalWall = NULL;
  104. }
  105. if (g_hdcWall)
  106. {
  107. DeleteDC(g_hdcWall);
  108. g_hdcWall = NULL;
  109. }
  110. if (g_hbrBack)
  111. {
  112. DeleteObject(g_hbrBack);
  113. g_hbrBack = NULL;
  114. }
  115. // catch fake sample window and icons destroy, too
  116. FakewinDestroy();
  117. IconsPreviewDestroy();
  118. CacheLoadImageFromFile(NULL, 0, 0, 0, 0);
  119. }
  120. //
  121. // ExtractPlusColorIcon
  122. //
  123. // Extract Icon from a file in proper Hi or Lo color for current system display
  124. //
  125. // from FrancisH on 6/22/95 with mods by TimBragg
  126. HRESULT ExtractPlusColorIcon(LPCTSTR szPath, int nIndex, HICON *phIcon,
  127. UINT uSizeLarge, UINT uSizeSmall)
  128. {
  129. IShellLink *psl;
  130. HRESULT hres;
  131. HICON hIcons[2]; // MUST! - provide for TWO return icons
  132. if ( !gfCoInitDone )
  133. {
  134. if (SUCCEEDED(CoInitialize(NULL)))
  135. gfCoInitDone = TRUE;
  136. }
  137. *phIcon = NULL;
  138. if (SUCCEEDED(hres = CoCreateInstance(&CLSID_ShellLink, NULL,
  139. CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl)))
  140. {
  141. if (SUCCEEDED(hres = psl->lpVtbl->SetIconLocation(psl, szPath, nIndex)))
  142. {
  143. IExtractIcon *pei;
  144. if (SUCCEEDED(hres = psl->lpVtbl->QueryInterface(psl,
  145. &IID_IExtractIcon, &pei)))
  146. {
  147. if (SUCCEEDED(hres = pei->lpVtbl->Extract(pei, szPath, nIndex,
  148. &hIcons[0], &hIcons[1], (UINT)MAKEWPARAM((WORD)uSizeLarge,
  149. (WORD)uSizeSmall))))
  150. {
  151. *phIcon = hIcons[0]; // Return first icon to caller
  152. }
  153. pei->lpVtbl->Release(pei);
  154. }
  155. }
  156. psl->lpVtbl->Release(psl);
  157. }
  158. return hres;
  159. } // end ExtractPlusColorIcon()