TrueColorToolBar.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /***=========================================================================
  2. ==== ====
  3. ==== D C U t i l i t y ====
  4. ==== ====
  5. =============================================================================
  6. ==== ====
  7. ==== File name : TrueColorToolBar.cpp ====
  8. ==== Project name : Tester ====
  9. ==== Project number : --- ====
  10. ==== Creation date : 13/1/2003 ====
  11. ==== Author(s) : Dany Cantin ====
  12. ==== ====
  13. ==== Copyright ?DCUtility 2003 ====
  14. ==== ====
  15. =============================================================================
  16. ===========================================================================*/
  17. #include "stdafx.h"
  18. #include "TrueColorToolBar.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CTrueColorToolBar
  26. CTrueColorToolBar::CTrueColorToolBar()
  27. {
  28. m_bDropDown = FALSE;
  29. }
  30. CTrueColorToolBar::~CTrueColorToolBar()
  31. {
  32. }
  33. BEGIN_MESSAGE_MAP(CTrueColorToolBar, CToolBar)
  34. //{{AFX_MSG_MAP(CTrueColorToolBar)
  35. ON_NOTIFY_REFLECT(TBN_DROPDOWN, OnToolbarDropDown)
  36. ON_WM_ERASEBKGND()
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CTrueColorToolBar message handlers
  41. BOOL CTrueColorToolBar::OnEraseBkgnd(CDC* pDC)
  42. {
  43. // TODO: Add your message handler code here and/or call default
  44. CRect rect;
  45. // GetWindowRect(&rect);
  46. CBrush *pnewBrush=new CBrush(RGB(225,225,225));//(RGB(198,186,156));
  47. GetClientRect(&rect);
  48. pDC->FillRect (&rect,pnewBrush);
  49. delete pnewBrush;
  50. // return CToolBar::OnEraseBkgnd(pDC);
  51. return 0;
  52. }
  53. BOOL CTrueColorToolBar::LoadTrueColorToolBar(int nBtnWidth,
  54. UINT uToolBar,
  55. UINT uToolBarHot,
  56. UINT uToolBarDisabled)
  57. {
  58. if (!SetTrueColorToolBar(TB_SETIMAGELIST, uToolBar, nBtnWidth))
  59. return FALSE;
  60. if (uToolBarHot)
  61. {
  62. if (!SetTrueColorToolBar(TB_SETHOTIMAGELIST, uToolBarHot, nBtnWidth))
  63. return FALSE;
  64. }
  65. if (uToolBarDisabled) {
  66. if (!SetTrueColorToolBar(TB_SETDISABLEDIMAGELIST, uToolBarDisabled, nBtnWidth))
  67. return FALSE;
  68. }
  69. return TRUE;
  70. }
  71. BOOL CTrueColorToolBar::SetTrueColorToolBar(UINT uToolBarType,
  72. UINT uToolBar,
  73. int nBtnWidth)
  74. {
  75. CImageList cImageList;
  76. CBitmap cBitmap;
  77. BITMAP bmBitmap;
  78. if (!cBitmap.Attach(LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(uToolBar),
  79. IMAGE_BITMAP, 0, 0,
  80. LR_DEFAULTSIZE|LR_CREATEDIBSECTION)) ||
  81. !cBitmap.GetBitmap(&bmBitmap))
  82. return FALSE;
  83. CSize cSize(bmBitmap.bmWidth, bmBitmap.bmHeight);
  84. int nNbBtn = cSize.cx/nBtnWidth;
  85. RGBTRIPLE* rgb = (RGBTRIPLE*)(bmBitmap.bmBits);
  86. COLORREF rgbMask = RGB(rgb[0].rgbtRed, rgb[0].rgbtGreen, rgb[0].rgbtBlue);
  87. if (!cImageList.Create(nBtnWidth, cSize.cy, ILC_COLOR24|ILC_MASK, nNbBtn, 0))
  88. return FALSE;
  89. if (cImageList.Add(&cBitmap, RGB(200,200,200)) == -1)
  90. // if (cImageList.Add(&cBitmap, RGB(0,0,0)) == -1)
  91. return FALSE;
  92. SendMessage(uToolBarType, 0, (LPARAM)cImageList.m_hImageList);
  93. cImageList.Detach();
  94. cBitmap.Detach();
  95. return TRUE;
  96. }
  97. void CTrueColorToolBar::AddDropDownButton(CWnd* pParent, UINT uButtonID, UINT uMenuID)
  98. {
  99. if (!m_bDropDown) {
  100. GetToolBarCtrl().SendMessage(TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_DRAWDDARROWS);
  101. m_bDropDown = TRUE;
  102. }
  103. SetButtonStyle(CommandToIndex(uButtonID), TBSTYLE_DROPDOWN);
  104. stDropDownInfo DropDownInfo;
  105. DropDownInfo.pParent = pParent;
  106. DropDownInfo.uButtonID = uButtonID;
  107. DropDownInfo.uMenuID = uMenuID;
  108. m_lstDropDownButton.Add(DropDownInfo);
  109. }
  110. #ifdef VC60
  111. void CTrueColorToolBar::OnToolbarDropDown(NMTOOLBAR* pnmtb, LRESULT *plr)
  112. {
  113. for (int i = 0; i < m_lstDropDownButton.GetSize(); i++) {
  114. stDropDownInfo DropDownInfo = m_lstDropDownButton.GetAt(i);
  115. if (DropDownInfo.uButtonID == UINT(pnmtb->iItem)) {
  116. CMenu menu;
  117. menu.LoadMenu(DropDownInfo.uMenuID);
  118. CMenu* pPopup = menu.GetSubMenu(0);
  119. CRect rc;
  120. SendMessage(TB_GETRECT, (WPARAM)pnmtb->iItem, (LPARAM)&rc);
  121. ClientToScreen(&rc);
  122. pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
  123. rc.left, rc.bottom, DropDownInfo.pParent, &rc);
  124. break;
  125. }
  126. }
  127. }
  128. #else
  129. void CTrueColorToolBar::OnToolbarDropDown(NMHDR * pNMHDR, LRESULT *plr)
  130. {
  131. LPNMTOOLBAR pNMTB = reinterpret_cast<LPNMTOOLBAR>(pNMHDR);
  132. for (int i = 0; i < m_lstDropDownButton.GetSize(); i++) {
  133. stDropDownInfo DropDownInfo = m_lstDropDownButton.GetAt(i);
  134. if (DropDownInfo.uButtonID == UINT(pNMTB->iItem)) {
  135. CMenu menu;
  136. menu.LoadMenu(DropDownInfo.uMenuID);
  137. CMenu* pPopup = menu.GetSubMenu(0);
  138. CRect rc;
  139. SendMessage(TB_GETRECT, (WPARAM)pNMTB->iItem, (LPARAM)&rc);
  140. ClientToScreen(&rc);
  141. pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
  142. rc.left, rc.bottom, DropDownInfo.pParent, &rc);
  143. break;
  144. }
  145. }
  146. }
  147. #endif