?? colortoolbar.cpp
字號:
#include "stdafx.h"
#include "ColorToolBar.h"
/************************************************************************/
BEGIN_MESSAGE_MAP(CColorToolBar, CToolBar)
//{{AFX_MSG_MAP(CColorToolBar)
ON_NOTIFY_REFLECT(TBN_DROPDOWN, OnToolbarDropDown)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/************************************************************************/
CColorToolBar::CColorToolBar()
{
m_bIsDropBtn = false;
}
/*================================================================
* 函數名: Set
* 功能描述: 給工具條設置圖象列表 (私有函數)
================================================================*/
BOOL CColorToolBar::SetImage(UINT ImageType, UINT uToolBar, int nBtnWidth)
{
CImageList ImageList;
CBitmap bmp;
BITMAP bm;
if (!bmp.Attach(::LoadImage(AfxGetResourceHandle(), //加載位圖
MAKEINTRESOURCE(uToolBar),
IMAGE_BITMAP, 0, 0,
LR_DEFAULTSIZE|LR_CREATEDIBSECTION)) ||
!bmp.GetBitmap(&bm))
{
return false;
}
CSize cSize(bm.bmWidth, bm.bmHeight); //獲得位圖的尺寸
int nNbBtn = cSize.cx/nBtnWidth;
RGBTRIPLE* rgb = (RGBTRIPLE*)(bm.bmBits);
COLORREF rgbMask = RGB(rgb[0].rgbtRed, rgb[0].rgbtGreen, rgb[0].rgbtBlue);
if (!ImageList.Create(nBtnWidth, cSize.cy, ILC_COLOR24|ILC_MASK, nNbBtn, 0)) //創建圖象列表
return false;
if (ImageList.Add(&bmp, rgbMask) == -1)
return false;
SendMessage(ImageType, 0, (LPARAM)ImageList.m_hImageList); //發送設置圖象列表的消息
ImageList.Detach();
bmp.Detach();
return TRUE;
}
/*================================================================
* 函數名: SetColorToolBar
* 參數: int nBtnWidth, UINT uBmpNormal, UINT uBmpHot, UINT uBmpDisable)
* 功能描述: 設置真彩位圖(正常時,鼠標在上面時,不可時)
* 返回值: BOOL
================================================================*/
BOOL CColorToolBar::SetColorToolBar(int nBtnWidth, UINT uBmpNormal, UINT uBmpHot, UINT uBmpDisable)
{
if (! this->SetImage(TB_SETIMAGELIST, uBmpNormal, nBtnWidth)) //正常時
return false;
if (uBmpHot) //鼠標移動到按扭上時
{
if (! this->SetImage(TB_SETHOTIMAGELIST, uBmpHot, nBtnWidth))
return false;
}
if (uBmpDisable) //不可用時
{
if (! this->SetImage(TB_SETDISABLEDIMAGELIST, uBmpDisable, nBtnWidth))
return false;
}
return TRUE;
}
/*================================================================
* 函數名: SetDropButton
* 功能描述: 設置下拉按扭
================================================================*/
void CColorToolBar::SetDropButton(CWnd* pParent, UINT uButtonID, UINT uMenuID)
{
if (!m_bIsDropBtn)
{
GetToolBarCtrl().SendMessage(TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_DRAWDDARROWS);
m_bIsDropBtn = TRUE;
}
SetButtonStyle(CommandToIndex(uButtonID), TBSTYLE_DROPDOWN);
DROP_INFO info;
info.pParent = pParent;
info.uButtonID = uButtonID;
info.uMenuID = uMenuID;
m_DropInfoArray.Add(info);
}
/*================================================================
* 函數名: OnToolbarDropDown
* 功能描述: 消息處理函數
================================================================*/
void CColorToolBar::OnToolbarDropDown(NMTOOLBAR* pnmtb, LRESULT *plr)
{
for (int i = 0; i < m_DropInfoArray.GetSize(); i++)
{
DROP_INFO info = m_DropInfoArray.GetAt(i);
{
CMenu menu;
menu.LoadMenu(info.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, info.pParent, &rc);
break;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -