TOOLBAR

int CclassTestDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDHtmlDialog::OnCreate(lpCreateStruct) == -1)
return -1;




//设置控件边框的宽度
m_ToolBarDrawBottom.SetBorders(1, 1, 1, 1);


//CBRS_BOTTOM 控制条位于框架窗口的底部。  
//CBRS_TOOLTIPS 控制条显示工具提示。  
//CBRS_SIZE_DYNAMIC 控制条是动态的。  
//CBRS_FLYBY 状态条显示按钮的信息。  


if ( !m_ToolBarDrawBottom.Create(this, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_BOTTOM
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) )
{
TRACE0("Failed to create toolbar\n");
//return -1;      // fail to create
}


m_ToolBarDrawBottom.LoadToolBar( IDR_TOOLBAR2 );
DWORD dwError = ::GetLastError( );
m_ToolBarDrawBottom.ModifyStyle(0, TBSTYLE_FLAT);


m_ToolBarDrawBottom.LoadTrueColorToolBar(24,
IDB_BITMAP3,
IDB_BITMAP3);


//m_ToolBarDrawBottom.AddDropDownButton(this, ID_PORTRAIT, IDR_MENU9);


RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);




CRect rtToolBar( 5, 5, 221, 29);
m_ToolBarDrawBottom.MoveWindow( rtToolBar );
// TODO:  在此添加您专用的创建代码


return 0;

}



=================================================XXXXXX.h====================================

/***=========================================================================
====                                                                     ====
====                          D C U t i l i t y                          ====
====                                                                     ====
=============================================================================
====                                                                     ====
====    File name           :  TrueColorToolBar.h                        ====
====    Project name        :  Tester                                    ====
====    Project number      :  ---                                       ====
====    Creation date       :  13/1/2003                                 ====
====    Author(s)           :  Dany Cantin                               ====
====                                                                     ====
====                  Copyright ?DCUtility  2003                        ====
====                                                                     ====
=============================================================================
===========================================================================*/




#ifndef TRUECOLORTOOLBAR_H_
#define TRUECOLORTOOLBAR_H_


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000




#include <afxtempl.h>


/
// CTrueColorToolBar


class CTrueColorToolBar : public CToolBar
{
// Construction
public:
CTrueColorToolBar();


// Attributes
private:
BOOL m_bDropDown;


struct stDropDownInfo {
public:
UINT  uButtonID;
UINT  uMenuID;
CWnd* pParent;
};

CArray <stDropDownInfo, stDropDownInfo&> m_lstDropDownButton;

// Operations
public:
BOOL LoadTrueColorToolBar(int  nBtnWidth,
 UINT uToolBar,
 UINT uToolBarHot = 0,
 UINT uToolBarDisabled = 0);


void AddDropDownButton(CWnd* pParent, UINT uButtonID, UINT uMenuID);


private:
BOOL SetTrueColorToolBar(UINT uToolBarType,
                    UINT uToolBar,
    int  nBtnWidth);


// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTrueColorToolBar)
//}}AFX_VIRTUAL


// Implementation
public:
virtual ~CTrueColorToolBar();


// Generated message map functions
protected:
//{{AFX_MSG(CTrueColorToolBar)
afx_msg void OnToolbarDropDown(NMHDR* pnmhdr, LRESULT *plr);
//}}AFX_MSG


DECLARE_MESSAGE_MAP()
};


/


//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.


#endif // TRUECOLORTOOLBAR_H_





=========================================================XXXXX.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"


#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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/
// CTrueColorToolBar message handlers
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, 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(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;
}
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值