gusucode.com > ADO智能开发包C++源码程序 > ADO智能开发包/sfxdb_src_1.0.510.1/sfx/Source/db/src/TrueColorToolBar.cpp
/***========================================================================= ==== ==== ==== 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" #include "..\inc\truecolortoolbar.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTrueColorToolBar IMPLEMENT_DYNAMIC(CTrueColorToolBar, CToolBar) CTrueColorToolBar::CTrueColorToolBar() :m_mfcUI(false) ,m_bDropDown(FALSE) ,m_bParentCMD(true) ,m_hWndCmd(NULL) { } CTrueColorToolBar::~CTrueColorToolBar() { } BEGIN_MESSAGE_MAP(CTrueColorToolBar, CToolBar) //{{AFX_MSG_MAP(CTrueColorToolBar) //ON_NOTIFY_REFLECT(TBN_DROPDOWN, OnToolbarDropDown) //ON_NOTIFY_REFLECT(TBN_DROPDOWN, OnToolbarDropDown) //}}AFX_MSG_MAP ON_WM_LBUTTONUP() END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTrueColorToolBar message handlers // ytf add. //BOOL CTrueColorToolBar::LoadImage(LPCTSTR lpszFileName, // int nBtnWidth, UINT uToolBar, UINT uToolBarHot, UINT uToolBarDisabled) //{ // if (!SetImageToolBar(lpszFileName, TB_SETIMAGELIST, nBtnWidth)) // { // return FALSE; // } // // if (uToolBarHot) // { // if (!SetImageToolBar(lpszFileName, TB_SETHOTIMAGELIST, nBtnWidth)) // return FALSE; // } // // if (uToolBarDisabled) // { // if (!SetImageToolBar(lpszFileName, TB_SETDISABLEDIMAGELIST, nBtnWidth)) // return FALSE; // } // return TRUE; //} BOOL CTrueColorToolBar::InitButtons() { return TRUE; } BOOL CTrueColorToolBar::LoadImage(LPCTSTR lpszFileName, UINT nToolbarType, INT nBtnWidth) { CImageList cImageList; CBitmap cBitmap; BITMAP bmBitmap; HANDLE _hObject; _hObject = ::LoadImage(NULL, lpszFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE|LR_DEFAULTSIZE); if (NULL==_hObject) { ASSERT(_hObject); return FALSE; } if (!cBitmap.Attach(_hObject) || !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, rgbMask) == -1) return FALSE; SendMessage(nToolbarType, 0, (LPARAM)cImageList.m_hImageList); cImageList.Detach(); cBitmap.Detach(); return TRUE; } 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(), (LPCTSTR)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, rgbMask) == -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); } 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; } } } void CTrueColorToolBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler) { if (m_mfcUI) { CToolBar::OnUpdateCmdUI(pTarget, bDisableIfNoHndler); } } void CTrueColorToolBar::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default TRACE(_T("----CTrueColorToolBar::OnLButtonUp(UINT nFlags, CPoint point)\n")); int nCmd = 0; CToolBarCtrl *pBar = &GetToolBarCtrl(); TBBUTTON tbButton; if (NULL != m_hWndCmd) { int nIndex = pBar->HitTest(&point); if (0<=nIndex) { VERIFY(pBar->GetButton(nIndex, &tbButton)); if (!(tbButton.fsStyle&TBSTYLE_SEP)) { if (tbButton.fsState&TBSTATE_ENABLED) { WPARAM dwParam = MAKEWPARAM(tbButton.idCommand, ::GetWindowLong(m_hWnd, GWL_ID)); TRACE(_T("----工具条发送的控件WM_COMMAND 值:%X\n"), dwParam); // CToolBar::OnLButtonUp(nFlags, point); ::SendMessage(m_hWndCmd, WM_COMMAND, (WPARAM)dwParam, (LPARAM)m_hWnd); } } } // return ; } //CToolBar::OnLButtonUp(nFlags, point); } BOOL CTrueColorToolBar::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if (pMsg->message==WM_LBUTTONUP) { CPoint poing(pMsg->lParam); //DefWindowProc(pMsg->message, pMsg->wParam, pMsg->lParam); OnLButtonUp((UINT)pMsg->wParam, poing); //return TRUE; } return CToolBar::PreTranslateMessage(pMsg); }