-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathTrueColorToolBar.cpp
More file actions
148 lines (116 loc) · 4.45 KB
/
Copy pathTrueColorToolBar.cpp
File metadata and controls
148 lines (116 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/***=========================================================================
==== ====
==== 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 "pub.h"//"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, HMENU 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)
void CTrueColorToolBar::OnToolbarDropDown(NMHDR* pnmtb, LRESULT *plr)
{
NMTOOLBARA* pnmtb1 = (NMTOOLBARA*)pnmtb;
for (int i = 0; i < m_lstDropDownButton.GetSize(); i++) {
stDropDownInfo DropDownInfo = m_lstDropDownButton.GetAt(i);
if (DropDownInfo.uButtonID == pnmtb1->iItem) {
CMenu menu;
menu.Attach(DropDownInfo.uMenuID);
CMenu* pPopup = menu.GetSubMenu(0);
if (!pPopup)
break;
CRect rc;
SendMessage(TB_GETRECT, (WPARAM)pnmtb1->iItem, (LPARAM)&rc);
ClientToScreen(&rc);
pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
rc.left, rc.bottom, DropDownInfo.pParent, &rc);
menu.Detach();
break;
}
}
}