| 1 | /********************************************************************* |
|---|
| 2 | * IE-like Menu and Toolbar, version 1.5 (August 3, 2004) |
|---|
| 3 | * Copyright (C) 2002-2003 Michal Mecinski. |
|---|
| 4 | * |
|---|
| 5 | * You may freely use and modify this code, but don't remove |
|---|
| 6 | * this copyright note. |
|---|
| 7 | * |
|---|
| 8 | * THERE IS NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, FOR |
|---|
| 9 | * THIS CODE. THE AUTHOR DOES NOT TAKE THE RESPONSIBILITY |
|---|
| 10 | * FOR ANY DAMAGE RESULTING FROM THE USE OF IT. |
|---|
| 11 | * |
|---|
| 12 | * E-mail: mimec@mimec.org |
|---|
| 13 | * WWW: http://www.mimec.org |
|---|
| 14 | ********************************************************************/ |
|---|
| 15 | |
|---|
| 16 | #include "stdafx.h" |
|---|
| 17 | #include "AlphaToolBar.h" |
|---|
| 18 | |
|---|
| 19 | #ifdef _DEBUG |
|---|
| 20 | #define new DEBUG_NEW |
|---|
| 21 | #endif |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | CAlphaToolBar::CAlphaToolBar() |
|---|
| 25 | { |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | CAlphaToolBar::~CAlphaToolBar() |
|---|
| 29 | { |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | BEGIN_MESSAGE_MAP(CAlphaToolBar, CToolBar) |
|---|
| 33 | END_MESSAGE_MAP() |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | BOOL CAlphaToolBar::Create(CWnd* pParentWnd, UINT nID) |
|---|
| 37 | { |
|---|
| 38 | // create flat transparent toolbar for use in a rebar control |
|---|
| 39 | return CToolBar::CreateEx(pParentWnd, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT, |
|---|
| 40 | WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY, |
|---|
| 41 | CRect(0,0,0,0), nID); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | BOOL CAlphaToolBar::LoadToolBar(UINT nID, int nStyle) |
|---|
| 46 | { |
|---|
| 47 | HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(nID), RT_TOOLBAR); |
|---|
| 48 | HRSRC hRsrc = ::FindResource(hInst, MAKEINTRESOURCE(nID), RT_TOOLBAR); |
|---|
| 49 | if (hRsrc == NULL) |
|---|
| 50 | return FALSE; |
|---|
| 51 | |
|---|
| 52 | HGLOBAL hGlobal = LoadResource(hInst, hRsrc); |
|---|
| 53 | if (hGlobal == NULL) |
|---|
| 54 | return FALSE; |
|---|
| 55 | |
|---|
| 56 | struct TBDATA |
|---|
| 57 | { |
|---|
| 58 | WORD wVersion; |
|---|
| 59 | WORD wWidth; |
|---|
| 60 | WORD wHeight; |
|---|
| 61 | WORD wItemCount; |
|---|
| 62 | WORD aItems[1]; |
|---|
| 63 | }; |
|---|
| 64 | |
|---|
| 65 | // get the toolbar data |
|---|
| 66 | TBDATA* pData = (TBDATA*)LockResource(hGlobal); |
|---|
| 67 | if (pData == NULL) |
|---|
| 68 | return FALSE; |
|---|
| 69 | ASSERT(pData->wVersion == 1); |
|---|
| 70 | |
|---|
| 71 | // create toolbar buttons |
|---|
| 72 | UINT* pItems = new UINT[pData->wItemCount]; |
|---|
| 73 | for (int i = 0; i < pData->wItemCount; i++) |
|---|
| 74 | pItems[i] = pData->aItems[i]; |
|---|
| 75 | BOOL bResult = SetButtons(pItems, pData->wItemCount); |
|---|
| 76 | delete[] pItems; |
|---|
| 77 | |
|---|
| 78 | if (bResult) |
|---|
| 79 | { |
|---|
| 80 | CSize sizeImage(pData->wWidth, pData->wHeight); |
|---|
| 81 | CSize sizeButton(pData->wWidth + 8, pData->wHeight + 7); |
|---|
| 82 | SetSizes(sizeButton, sizeImage); |
|---|
| 83 | |
|---|
| 84 | // load images from bitmap resource |
|---|
| 85 | if (m_ImgList.Create(pData->wWidth, pData->wHeight, nStyle, |
|---|
| 86 | pData->wItemCount)) |
|---|
| 87 | { |
|---|
| 88 | bResult = m_ImgList.AddBitmap(nID); |
|---|
| 89 | } |
|---|
| 90 | else |
|---|
| 91 | bResult = FALSE; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | UnlockResource(hGlobal); |
|---|
| 95 | FreeResource(hGlobal); |
|---|
| 96 | |
|---|
| 97 | if (bResult) // let the toolbar use our image lists |
|---|
| 98 | { |
|---|
| 99 | SendMessage(TB_SETIMAGELIST, 0, (LPARAM)m_ImgList.GetImageList(AIL_NORMAL)); |
|---|
| 100 | SendMessage(TB_SETHOTIMAGELIST, 0, (LPARAM)m_ImgList.GetImageList(AIL_HOT)); |
|---|
| 101 | SendMessage(TB_SETDISABLEDIMAGELIST, 0, (LPARAM)m_ImgList.GetImageList(AIL_DISABLED)); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | return bResult; |
|---|
| 105 | } |
|---|