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.

177 lines
4.9 KiB

  1. // this file should not be needed anymore as we now compile for versions of NT > 500
  2. #include "shellprv.h"
  3. #include <appmgmt.h>
  4. #include <userenv.h>
  5. #include <devguid.h>
  6. #include <dbt.h>
  7. LPTSTR GetEnvBlock(HANDLE hUserToken)
  8. {
  9. LPTSTR pszRet = NULL;
  10. if (hUserToken)
  11. CreateEnvironmentBlock(&pszRet, hUserToken, TRUE);
  12. else
  13. pszRet = (LPTSTR) GetEnvironmentStrings();
  14. return pszRet;
  15. }
  16. void FreeEnvBlock(HANDLE hUserToken, LPTSTR pszEnv)
  17. {
  18. if (pszEnv)
  19. {
  20. if (hUserToken)
  21. DestroyEnvironmentBlock(pszEnv);
  22. else
  23. FreeEnvironmentStrings(pszEnv);
  24. }
  25. }
  26. STDAPI_(BOOL) GetAllUsersDirectory(LPTSTR pszPath)
  27. {
  28. DWORD cbData = MAX_PATH;
  29. BOOL fRet = FALSE;
  30. // This is delay loaded. It can fail.
  31. __try
  32. {
  33. fRet = GetAllUsersProfileDirectoryW(pszPath, &cbData);
  34. }
  35. __except(EXCEPTION_EXECUTE_HANDLER)
  36. {
  37. pszPath[0] = 0;
  38. }
  39. return fRet;
  40. }
  41. BOOL IsColorKey(RGBQUAD rgbPixel, COLORREF crKey)
  42. {
  43. // COLORREF is backwards to RGBQUAD
  44. return InRange( rgbPixel.rgbBlue, ((crKey & 0xFF0000) >> 16) - 5, ((crKey & 0xFF0000) >> 16) + 5) &&
  45. InRange( rgbPixel.rgbGreen, ((crKey & 0x00FF00) >> 8) - 5, ((crKey & 0x00FF00) >> 8) + 5) &&
  46. InRange( rgbPixel.rgbRed, ((crKey & 0x0000FF) >> 0) - 5, ((crKey & 0x0000FF) >> 0) + 5);
  47. }
  48. typedef BOOL (* PFNUPDATELAYEREDWINDOW)
  49. (HWND hwnd,
  50. HDC hdcDest,
  51. POINT *pptDst,
  52. SIZE *psize,
  53. HDC hdcSrc,
  54. POINT *pptSrc,
  55. COLORREF crKey,
  56. BLENDFUNCTION *pblend,
  57. DWORD dwFlags);
  58. BOOL NT5_UpdateLayeredWindow(HWND hwnd, HDC hdcDest, POINT* pptDest, SIZE* psize,
  59. HDC hdcSrc, POINT* pptSrc, COLORREF crKey, BLENDFUNCTION* pblend, DWORD dwFlags)
  60. {
  61. BOOL bRet = FALSE;
  62. static PFNUPDATELAYEREDWINDOW pfn = NULL;
  63. if (NULL == pfn)
  64. {
  65. HMODULE hmod = GetModuleHandle(TEXT("USER32"));
  66. if (hmod)
  67. pfn = (PFNUPDATELAYEREDWINDOW)GetProcAddress(hmod, "UpdateLayeredWindow");
  68. }
  69. if (pfn)
  70. {
  71. // The user implementation is poor and does not implement this functionality
  72. BITMAPINFO bmi;
  73. HDC hdcRGBA;
  74. HBITMAP hbmRGBA;
  75. VOID* pBits;
  76. LONG i;
  77. BLENDFUNCTION blend;
  78. ULONG* pul;
  79. POINT ptSrc;
  80. hdcRGBA = NULL;
  81. if ((dwFlags & (ULW_ALPHA | ULW_COLORKEY)) == (ULW_ALPHA | ULW_COLORKEY))
  82. {
  83. if (hdcSrc)
  84. {
  85. RtlZeroMemory(&bmi, sizeof(bmi));
  86. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  87. bmi.bmiHeader.biWidth = psize->cx;
  88. bmi.bmiHeader.biHeight = psize->cy;
  89. bmi.bmiHeader.biPlanes = 1;
  90. bmi.bmiHeader.biBitCount = 32;
  91. bmi.bmiHeader.biCompression = BI_RGB;
  92. hbmRGBA = CreateDIBSection(hdcDest,
  93. &bmi,
  94. DIB_RGB_COLORS,
  95. &pBits,
  96. NULL,
  97. 0);
  98. if (!hbmRGBA)
  99. return FALSE;
  100. hdcRGBA = CreateCompatibleDC(hdcDest);
  101. if (!hdcRGBA)
  102. {
  103. DeleteObject(hbmRGBA);
  104. return FALSE;
  105. }
  106. SelectObject(hdcRGBA, hbmRGBA);
  107. BitBlt(hdcRGBA, 0, 0, psize->cx, psize->cy,
  108. hdcSrc, pptSrc->x, pptSrc->y, SRCCOPY);
  109. pul = pBits;
  110. for (i = psize->cx * psize->cy; i != 0; i--)
  111. {
  112. if (IsColorKey(*(RGBQUAD*)pul, crKey))
  113. {
  114. // Write a pre-multiplied value of 0:
  115. *pul = 0;
  116. }
  117. else
  118. {
  119. // Where the bitmap is not the transparent color, change the
  120. // alpha value to opaque:
  121. ((RGBQUAD*) pul)->rgbReserved = 0xff;
  122. }
  123. pul++;
  124. }
  125. // Change the parameters to account for the fact that we're now
  126. // providing only a 32-bit per-pixel alpha source:
  127. ptSrc.x = 0;
  128. ptSrc.y = 0;
  129. pptSrc = &ptSrc;
  130. hdcSrc = hdcRGBA;
  131. }
  132. blend = *pblend;
  133. blend.AlphaFormat = AC_SRC_ALPHA;
  134. pblend = &blend;
  135. dwFlags = ULW_ALPHA;
  136. }
  137. bRet = pfn(hwnd, hdcDest, pptDest, psize, hdcSrc, pptSrc, crKey, pblend, dwFlags);
  138. if (hdcRGBA)
  139. {
  140. DeleteObject(hdcRGBA);
  141. DeleteObject(hbmRGBA);
  142. }
  143. }
  144. return bRet;
  145. }