Leaked source code of windows server 2003
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.

102 lines
2.9 KiB

  1. /*
  2. * Conversion
  3. */
  4. #ifndef DUI_UTIL_CONVERT_H_INCLUDED
  5. #define DUI_UTIL_CONVERT_H_INCLUDED
  6. #pragma once
  7. namespace DirectUI
  8. {
  9. #define DUIARRAYSIZE(a) (sizeof(a) / sizeof(a[0]))
  10. /////////////////////////////////////////////////////////////////////////////
  11. // String conversion
  12. #define DUI_CODEPAGE CP_ACP // String conversion codepage
  13. LPSTR UnicodeToMultiByte(LPCWSTR pszUnicode, int cChars = -1, int* pMultiBytes = NULL);
  14. LPWSTR MultiByteToUnicode(LPCSTR pszMulti, int dBytes = -1, int* pUniChars = NULL);
  15. /////////////////////////////////////////////////////////////////////////////
  16. // Atom conversion
  17. ATOM StrToID(LPCWSTR psz);
  18. /////////////////////////////////////////////////////////////////////////////
  19. // Bitmap conversion
  20. HBITMAP LoadDDBitmap(LPCWSTR pszBitmap, HINSTANCE hResLoad, int cx, int cy);
  21. #ifdef GADGET_ENABLE_GDIPLUS
  22. HRESULT LoadDDBitmap(LPCWSTR pszBitmap, HINSTANCE hResLoad, int cx, int cy, UINT nFormat, OUT Gdiplus::Bitmap** ppgpbmp);
  23. #endif
  24. HBITMAP ProcessAlphaBitmapI(HBITMAP hbmSource);
  25. #ifdef GADGET_ENABLE_GDIPLUS
  26. Gdiplus::Bitmap * ProcessAlphaBitmapF(HBITMAP hbmSource, UINT nFormat);
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // Color conversion
  30. inline COLORREF RemoveAlpha(COLORREF cr) { return ~(255 << 24) & cr; }
  31. inline COLORREF NearestPalColor(COLORREF cr) { return (0x02000000) | cr; }
  32. const int SysColorEnumOffset = 10000; // Used to identify a system color enum
  33. inline bool IsSysColorEnum(int c) { return c >= SysColorEnumOffset; }
  34. inline int MakeSysColorEnum(int c) { return c + SysColorEnumOffset; }
  35. inline int ConvertSysColorEnum(int c) { return c - SysColorEnumOffset; }
  36. HBRUSH BrushFromEnumI(int c);
  37. COLORREF ColorFromEnumI(int c);
  38. #ifdef GADGET_ENABLE_GDIPLUS
  39. Gdiplus::Color ColorFromEnumF(int c);
  40. #endif
  41. #ifdef GADGET_ENABLE_GDIPLUS
  42. inline Gdiplus::Color RemoveAlpha(Gdiplus::Color cr)
  43. {
  44. return Gdiplus::Color(cr.GetR(), cr.GetG(), cr.GetB());
  45. }
  46. inline Gdiplus::Color Convert(COLORREF cr)
  47. {
  48. return Gdiplus::Color(GetAValue(cr), GetRValue(cr), GetGValue(cr), GetBValue(cr));
  49. }
  50. #endif
  51. inline IsOpaque(BYTE bAlphaLevel)
  52. {
  53. return bAlphaLevel >= 250;
  54. }
  55. inline IsTransparent(BYTE bAlphaLevel)
  56. {
  57. return bAlphaLevel <= 5;
  58. }
  59. int PointToPixel(int nPoint);
  60. int RelPixToPixel(int nRelPix);
  61. inline int PointToPixel(int nPoint, int nDPI)
  62. {
  63. return -MulDiv(nPoint, nDPI, 72);
  64. }
  65. inline int RelPixToPixel(int nRelPix, int nDPI)
  66. {
  67. return MulDiv(nRelPix, nDPI, 96);
  68. }
  69. /////////////////////////////////////////////////////////////////////////////
  70. // Bitmap conversion
  71. bool IsPalette(HWND hWnd = NULL);
  72. //HPALETTE PALToHPALETTE(LPWSTR pPALFile, bool bMemFile = false, DWORD dMemFileSize = 0, LPRGBQUAD pRGBQuad = NULL, LPWSTR pError = NULL);
  73. } // namespace DirectUI
  74. #endif // DUI_UTIL_CONVERT_H_INCLUDED