-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlphaToolBar.cpp
executable file
·101 lines (82 loc) · 2.43 KB
/
AlphaToolBar.cpp
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
/*********************************************************
* Simple IE-like Menu And Toolbar
* Version: 1.3
* Date: Semptember 1, 2003
* Autor: Michal Mecinski
* E-mail: mimec@mimec.w.pl
* WWW: http://www.mimec.w.pl
*
* Copyright (C) 2002-03 by Michal Mecinski
*********************************************************/
#include "stdafx.h"
#include "AlphaToolBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CAlphaToolBar::CAlphaToolBar()
{
}
CAlphaToolBar::~CAlphaToolBar()
{
}
BEGIN_MESSAGE_MAP(CAlphaToolBar, CToolBar)
END_MESSAGE_MAP()
BOOL CAlphaToolBar::Create(CWnd* pParentWnd, UINT nID)
{
// create flat transparent toolbar for use in a rebar control
return CToolBar::CreateEx(pParentWnd, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT,
WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY,
CRect(0,0,0,0), nID);
}
BOOL CAlphaToolBar::LoadToolBar(UINT nID, int nStyle)
{
HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(nID), RT_TOOLBAR);
HRSRC hRsrc = ::FindResource(hInst, MAKEINTRESOURCE(nID), RT_TOOLBAR);
if (hRsrc == NULL)
return FALSE;
HGLOBAL hGlobal = LoadResource(hInst, hRsrc);
if (hGlobal == NULL)
return FALSE;
struct TBDATA
{
WORD wVersion;
WORD wWidth;
WORD wHeight;
WORD wItemCount;
WORD aItems[1];
};
// get the toolbar data
TBDATA* pData = (TBDATA*)LockResource(hGlobal);
if (pData == NULL)
return FALSE;
ASSERT(pData->wVersion == 1);
// create toolbar buttons
UINT* pItems = new UINT[pData->wItemCount];
for (int i = 0; i < pData->wItemCount; i++)
pItems[i] = pData->aItems[i];
BOOL bResult = SetButtons(pItems, pData->wItemCount);
delete[] pItems;
if (bResult)
{
CSize sizeImage(pData->wWidth, pData->wHeight);
CSize sizeButton(pData->wWidth + 8, pData->wHeight + 7);
SetSizes(sizeButton, sizeImage);
// load images from bitmap resource
if (m_ImgList.Create(pData->wWidth, pData->wHeight, nStyle,
pData->wItemCount))
{
bResult = m_ImgList.AddBitmap(nID);
}
else
bResult = FALSE;
}
UnlockResource(hGlobal);
FreeResource(hGlobal);
if (bResult) // let the toolbar use our image lists
{
SendMessage(TB_SETIMAGELIST, 0, (LPARAM)m_ImgList.GetImageList(AIL_NORMAL));
SendMessage(TB_SETHOTIMAGELIST, 0, (LPARAM)m_ImgList.GetImageList(AIL_HOT));
SendMessage(TB_SETDISABLEDIMAGELIST, 0, (LPARAM)m_ImgList.GetImageList(AIL_DISABLED));
}
return bResult;
}