123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- /***=========================================================================
- ==== ====
- ==== D C U t i l i t y ====
- ==== ====
- =============================================================================
- ==== ====
- ==== File name : TrueColorToolBar.cpp ====
- ==== Project name : Tester ====
- ==== Project number : --- ====
- ==== Creation date : 13/1/2003 ====
- ==== Author(s) : Dany Cantin ====
- ==== ====
- ==== Copyright ?DCUtility 2003 ====
- ==== ====
- =============================================================================
- ===========================================================================*/
- #include "stdafx.h"
- #include "TrueColorToolBar.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CTrueColorToolBar
- CTrueColorToolBar::CTrueColorToolBar()
- {
- m_bDropDown = FALSE;
- }
- CTrueColorToolBar::~CTrueColorToolBar()
- {
- }
- BEGIN_MESSAGE_MAP(CTrueColorToolBar, CToolBar)
- //{{AFX_MSG_MAP(CTrueColorToolBar)
- ON_NOTIFY_REFLECT(TBN_DROPDOWN, OnToolbarDropDown)
- ON_WM_ERASEBKGND()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CTrueColorToolBar message handlers
- BOOL CTrueColorToolBar::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: Add your message handler code here and/or call default
- CRect rect;
- // GetWindowRect(&rect);
- CBrush *pnewBrush=new CBrush(RGB(225,225,225));//(RGB(198,186,156));
- GetClientRect(&rect);
- pDC->FillRect (&rect,pnewBrush);
- delete pnewBrush;
- // return CToolBar::OnEraseBkgnd(pDC);
- return 0;
- }
- BOOL CTrueColorToolBar::LoadTrueColorToolBar(int nBtnWidth,
- UINT uToolBar,
- UINT uToolBarHot,
- UINT uToolBarDisabled)
- {
- if (!SetTrueColorToolBar(TB_SETIMAGELIST, uToolBar, nBtnWidth))
- return FALSE;
- if (uToolBarHot)
- {
- if (!SetTrueColorToolBar(TB_SETHOTIMAGELIST, uToolBarHot, nBtnWidth))
- return FALSE;
- }
- if (uToolBarDisabled) {
- if (!SetTrueColorToolBar(TB_SETDISABLEDIMAGELIST, uToolBarDisabled, nBtnWidth))
- return FALSE;
- }
- return TRUE;
- }
- BOOL CTrueColorToolBar::SetTrueColorToolBar(UINT uToolBarType,
- UINT uToolBar,
- int nBtnWidth)
- {
- CImageList cImageList;
- CBitmap cBitmap;
- BITMAP bmBitmap;
- if (!cBitmap.Attach(LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(uToolBar),
- IMAGE_BITMAP, 0, 0,
- LR_DEFAULTSIZE|LR_CREATEDIBSECTION)) ||
- !cBitmap.GetBitmap(&bmBitmap))
- return FALSE;
- CSize cSize(bmBitmap.bmWidth, bmBitmap.bmHeight);
- int nNbBtn = cSize.cx/nBtnWidth;
- RGBTRIPLE* rgb = (RGBTRIPLE*)(bmBitmap.bmBits);
- COLORREF rgbMask = RGB(rgb[0].rgbtRed, rgb[0].rgbtGreen, rgb[0].rgbtBlue);
- if (!cImageList.Create(nBtnWidth, cSize.cy, ILC_COLOR24|ILC_MASK, nNbBtn, 0))
- return FALSE;
- if (cImageList.Add(&cBitmap, RGB(200,200,200)) == -1)
- // if (cImageList.Add(&cBitmap, RGB(0,0,0)) == -1)
- return FALSE;
- SendMessage(uToolBarType, 0, (LPARAM)cImageList.m_hImageList);
- cImageList.Detach();
- cBitmap.Detach();
- return TRUE;
- }
- void CTrueColorToolBar::AddDropDownButton(CWnd* pParent, UINT uButtonID, UINT uMenuID)
- {
- if (!m_bDropDown) {
- GetToolBarCtrl().SendMessage(TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_DRAWDDARROWS);
- m_bDropDown = TRUE;
- }
- SetButtonStyle(CommandToIndex(uButtonID), TBSTYLE_DROPDOWN);
- stDropDownInfo DropDownInfo;
- DropDownInfo.pParent = pParent;
- DropDownInfo.uButtonID = uButtonID;
- DropDownInfo.uMenuID = uMenuID;
- m_lstDropDownButton.Add(DropDownInfo);
- }
- #ifdef VC60
- void CTrueColorToolBar::OnToolbarDropDown(NMTOOLBAR* pnmtb, LRESULT *plr)
- {
- for (int i = 0; i < m_lstDropDownButton.GetSize(); i++) {
-
- stDropDownInfo DropDownInfo = m_lstDropDownButton.GetAt(i);
- if (DropDownInfo.uButtonID == UINT(pnmtb->iItem)) {
- CMenu menu;
- menu.LoadMenu(DropDownInfo.uMenuID);
- CMenu* pPopup = menu.GetSubMenu(0);
-
- CRect rc;
- SendMessage(TB_GETRECT, (WPARAM)pnmtb->iItem, (LPARAM)&rc);
- ClientToScreen(&rc);
-
- pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
- rc.left, rc.bottom, DropDownInfo.pParent, &rc);
- break;
- }
- }
- }
- #else
- void CTrueColorToolBar::OnToolbarDropDown(NMHDR * pNMHDR, LRESULT *plr)
- {
- LPNMTOOLBAR pNMTB = reinterpret_cast<LPNMTOOLBAR>(pNMHDR);
- for (int i = 0; i < m_lstDropDownButton.GetSize(); i++) {
- stDropDownInfo DropDownInfo = m_lstDropDownButton.GetAt(i);
- if (DropDownInfo.uButtonID == UINT(pNMTB->iItem)) {
- CMenu menu;
- menu.LoadMenu(DropDownInfo.uMenuID);
- CMenu* pPopup = menu.GetSubMenu(0);
- CRect rc;
- SendMessage(TB_GETRECT, (WPARAM)pNMTB->iItem, (LPARAM)&rc);
- ClientToScreen(&rc);
- pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
- rc.left, rc.bottom, DropDownInfo.pParent, &rc);
- break;
- }
- }
- }
- #endif
|