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.

124 lines
3.5 KiB

  1. //
  2. // iconlib.cpp
  3. //
  4. #include "private.h"
  5. #include "cmydc.h"
  6. #include "iconlib.h"
  7. /* G E T I C O N S I Z E */
  8. /*------------------------------------------------------------------------------
  9. get icon size
  10. ------------------------------------------------------------------------------*/
  11. BOOL GetIconSize( HICON hIcon, SIZE *psize )
  12. {
  13. ICONINFO IconInfo;
  14. BITMAP bmp;
  15. Assert( hIcon != NULL );
  16. if (!GetIconInfo( hIcon, &IconInfo ))
  17. return FALSE;
  18. GetObject( IconInfo.hbmColor, sizeof(bmp), &bmp );
  19. DeleteObject( IconInfo.hbmColor );
  20. DeleteObject( IconInfo.hbmMask );
  21. psize->cx = bmp.bmWidth;
  22. psize->cy = bmp.bmHeight;
  23. return TRUE;
  24. }
  25. //+---------------------------------------------------------------------------
  26. //
  27. // GetIconBitmaps
  28. //
  29. //----------------------------------------------------------------------------
  30. BOOL GetIconBitmaps(HICON hIcon, HBITMAP *phbmp, HBITMAP *phbmpMask, SIZE *psize)
  31. {
  32. CBitmapDC hdcSrc(TRUE);
  33. CBitmapDC hdcMask(TRUE);
  34. SIZE size;
  35. if (psize)
  36. size = *psize;
  37. else if (!GetIconSize( hIcon, &size))
  38. return FALSE;
  39. hdcSrc.SetCompatibleBitmap(size.cx, size.cy);
  40. // hdcMask.SetCompatibleBitmap(size.cx, size.cy);
  41. hdcMask.SetBitmap(size.cx, size.cy, 1, 1);
  42. RECT rc = {0, 0, size.cx, size.cy};
  43. FillRect(hdcSrc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
  44. DrawIconEx(hdcSrc, 0, 0, hIcon, size.cx, size.cy, 0, NULL, DI_NORMAL);
  45. DrawIconEx(hdcMask, 0, 0, hIcon, size.cx, size.cy, 0, NULL, DI_MASK);
  46. *phbmp = hdcSrc.GetBitmapAndKeep();
  47. *phbmpMask = hdcMask.GetBitmapAndKeep();
  48. return TRUE;
  49. }
  50. //+---------------------------------------------------------------------------
  51. //
  52. // GetIconDIBitmaps
  53. //
  54. //----------------------------------------------------------------------------
  55. BOOL GetIconDIBitmaps(HICON hIcon, HBITMAP *phbmp, HBITMAP *phbmpMask, SIZE *psize)
  56. {
  57. CBitmapDC hdcSrc(TRUE);
  58. CBitmapDC hdcMask(TRUE);
  59. SIZE size;
  60. if (psize)
  61. size = *psize;
  62. else if (!GetIconSize( hIcon, &size))
  63. return FALSE;
  64. hdcSrc.SetDIB(size.cx, size.cy);
  65. // hdcMask.SetCompatibleBitmap(size.cx, size.cy);
  66. hdcMask.SetBitmap(size.cx, size.cy, 1, 1);
  67. RECT rc = {0, 0, size.cx, size.cy};
  68. FillRect(hdcSrc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
  69. DrawIconEx(hdcSrc, 0, 0, hIcon, size.cx, size.cy, 0, NULL, DI_NORMAL);
  70. DrawIconEx(hdcMask, 0, 0, hIcon, size.cx, size.cy, 0, NULL, DI_MASK);
  71. *phbmp = hdcSrc.GetBitmapAndKeep();
  72. *phbmpMask = hdcMask.GetBitmapAndKeep();
  73. return TRUE;
  74. }
  75. //+---------------------------------------------------------------------------
  76. //
  77. // GetMenuIconHeight
  78. //
  79. //----------------------------------------------------------------------------
  80. int GetMenuIconHeight(int *pnMenuFontHeghti)
  81. {
  82. int nMenuFontHeight;
  83. int cxSmIcon = GetSystemMetrics( SM_CXSMICON );
  84. NONCLIENTMETRICS ncm;
  85. int cyMenu = GetSystemMetrics(SM_CYMENU);
  86. ncm.cbSize = sizeof(ncm);
  87. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, FALSE);
  88. nMenuFontHeight = (ncm.lfMenuFont.lfHeight > 0) ?
  89. ncm.lfMenuFont.lfHeight :
  90. -ncm.lfMenuFont.lfHeight;
  91. if (pnMenuFontHeghti)
  92. *pnMenuFontHeghti = nMenuFontHeight;
  93. //
  94. // CUIMENU.CPP uses 8 as TextMargin of dropdown menu.
  95. //
  96. if ((nMenuFontHeight + 8 >= cxSmIcon) && (nMenuFontHeight <= cxSmIcon))
  97. return cxSmIcon;
  98. return nMenuFontHeight + 4;
  99. }