ToolBar 工具栏

toolbar.hpp
#ifndef toolbarH
#define toolbarH

#include <commctrl.h>
#include <windows.h>
#include <vector>

using std::vector;

namespace NSTS {

struct ToolBarButton {
UINT uCmdId;
int iIconSize;
int iColor;
UINT uDefaultIconId;
UINT uHotIconId;
UINT uDisableIconId;
TCHAR* pszToolTips;
TCHAR* pszText;
};

class CToolBar {
public:
CToolBar (void);
~CToolBar (void);

public:
bool Init (HWND hParent, HINSTANCE hInst, UINT uId = NULL, DWORD dwStyle = WS_CHILD | WS_VISIBLE |
TBSTYLE_TOOLTIPS | TBSTYLE_WRAPABLE | TBSTYLE_FLAT |
WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_TOP | BTNS_AUTOSIZE | CCS_NODIVIDER
);
bool Init (HWND hParent, HINSTANCE hInst, ToolBarButton btns[], int iBtnSize, UINT uId = NULL, DWORD dwStyle = WS_CHILD | WS_VISIBLE |
TBSTYLE_TOOLTIPS | TBSTYLE_WRAPABLE | TBSTYLE_FLAT |
WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_TOP | BTNS_AUTOSIZE | CCS_NODIVIDER
);
void Destroy (void);

bool AddButtons (const ToolBarButton btns[], int iSize);
bool InsertButton (int iPos, const ToolBarButton* pBtn);

bool AddButtons (TBBUTTON btns[], int iSize);
bool InsertButton (int iPos, const LPTBBUTTON lpBtn);
bool DeleteButton (UINT uBtnId);
bool EnableButton (UINT uBtnId, BOOL fEnable);
bool IsButtonEnabled (UINT uBtnId);
bool HideButton (UINT uBtnid, BOOL fHide = TRUE);
bool IsButtonVisible (UINT uBtnId);
bool MoveButton (UINT uOldPos, UINT uNewPos);

bool SetButtonBitmap (UINT uBtnId, int iBitmapIndex);
bool SetButtonInfo (UINT uBtnId, const TBBUTTONINFO* lptbbi);
bool SetButtonSize (WORD wX, WORD wY);
bool SetBitmapSize (WORD wX, WORD wY);
bool SetDefaultImageList (HIMAGELIST himlNew);
bool SetHotImageList (HIMAGELIST himlHotNew);
bool SetDisabledImageList (HIMAGELIST himlDisableNew);
bool SetButtonText (UINT uBtnId, TCHAR* szText);
HIMAGELIST GetDefaultImageList (void);
HIMAGELIST GetHotImageList (void);
HIMAGELIST GetDisabledImageList (void);
bool SetButtonToBeDropdown (UINT uBtn); /** the parent must handle the WM_NOTIFY message */
bool SetButtonToolTips (UINT uId, LPTSTR lpszText);

int GetButtonCount (void);
bool GetButton (UINT uId, TBBUTTON* pBtn);
int GetButtonIndex (UINT uBtnId);
bool GetButtonInfo (UINT uBtnId, TBBUTTONINFO* pBtnInfo);
bool GetButtonText (UINT uBtnId, LPTSTR szText);
BYTE GetButtonState (UINT uBtnId);
int GetHotIndex (void);

bool SetExtendedStyle (DWORD dwExtendedStyle);
DWORD GetExtendedStyle (void);
bool SetStyle (DWORD dwStyle);
DWORD GetStyle (void);
bool SetUnicodeFormat (BOOL fUnicode = TRUE);
bool IsUnicodeFormat (void);

void DoToolTipNotify (LPARAM lParam);
void DoDropDownNotify (LPARAM lParam, UINT uId, HMENU hMenu);

bool SetParent (HWND hParent);
HWND GetParent (void);
HWND GetSelf (void);

protected:
bool IsWindowValid (HWND hwnd) { return (hwnd != NULL && IsWindow (hwnd)); };

protected:
HWND m_hParent;
HWND m_hSelf;
HINSTANCE m_hInst;
vector <ToolBarButton> m_vctBtns;
};
}


#endif
toolbar.cpp
#include "toolbar.hpp"

#include <assert.h>

namespace NSTS {


CToolBar::
CToolBar (void)
{
m_hParent = m_hSelf = NULL;
m_hInst = NULL;
}


CToolBar::
~CToolBar (void)
{
Destroy ();
}


bool
CToolBar::
Init (HWND hParent, HINSTANCE hInst, UINT uId, DWORD dwStyle)
{
Destroy ();
if (IsWindowValid (hParent)) {
INITCOMMONCONTROLSEX icex;

icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_WIN95_CLASSES|ICC_COOL_CLASSES|ICC_BAR_CLASSES|ICC_USEREX_CLASSES;

InitCommonControlsEx(&icex);

m_hSelf = CreateWindowEx (
WS_EX_PALETTEWINDOW,
TOOLBARCLASSNAME,
NULL,
dwStyle,
0,
0,
0,
0,
hParent,
(HMENU) uId,
hInst,
NULL);
if (!IsWindowValid (m_hSelf)) {
return false;
}

SendMessage (m_hSelf, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof (TBBUTTON), (LPARAM)0);
m_hParent = hParent;
m_hInst = hInst;

ShowWindow (m_hSelf, SW_SHOW);
return true;
}

return false;
}


bool
CToolBar::
Init (HWND hParent, HINSTANCE hInst, ToolBarButton btns[], int iBtnSize, UINT uId, DWORD dwStyle)
{
if (btns != NULL && iBtnSize > 0 && Init (hParent, hInst, uId, dwStyle)) {
/** add buttons */
if (!AddButtons (btns, iBtnSize)) {
Destroy ();
return false;
}

return true;
}

return false;
}


void
CToolBar::
Destroy (void)
{
HIMAGELIST hDefault = GetDefaultImageList ();
if (hDefault != NULL) {
ImageList_Destroy (hDefault);
}

HIMAGELIST hHot = GetHotImageList ();
if (hHot != NULL) {
ImageList_Destroy (hHot);
}

HIMAGELIST hDisabled = GetDisabledImageList ();
if (hDisabled != NULL) {
ImageList_Destroy (hHot);
}


if (m_hSelf != NULL) {
DestroyWindow (m_hSelf);
m_hSelf = NULL;
}

m_hParent = NULL;
m_hInst = NULL;

m_vctBtns.clear ();
}


bool
CToolBar::
AddButtons (TBBUTTON btns[], int iSize)
{
if (IsWindowValid (m_hSelf) && btns != NULL && iSize > 0) {
return SendMessage (m_hSelf, TB_ADDBUTTONS, (WPARAM)(UINT)iSize, (LPARAM)btns);
}

return false;
}


bool
CToolBar::
AddButtons (const ToolBarButton btns[], int iSize)
{
HIMAGELIST hDefault,
hHot,
hDisabled;
int iIconSize = btns[0].iIconSize;
UINT uFlag = ILC_MASK;
TBBUTTON* pBtns;
bool fOk;

if (!IsWindowValid (m_hSelf) || btns == NULL || iSize <= 0) {
return false;
}

switch (btns[0].iColor) {
case 4:
uFlag |= ILC_COLOR4;
break;
case 8:
uFlag |= ILC_COLOR8;
break;
case 16:
uFlag |= ILC_COLOR16;
break;

case 32:
uFlag |= ILC_COLOR32;
break;
default:
uFlag |= ILC_COLOR;
break;
}

hDefault = GetDefaultImageList ();
hHot = GetHotImageList ();
hDisabled = GetDisabledImageList ();


if (hDefault == NULL) {
hDefault = ImageList_Create (iIconSize, iIconSize, uFlag, iSize, 1);
if (!SetDefaultImageList (hDefault)) {
return false;
}
}

if (hHot == NULL) {
hHot = ImageList_Create (iIconSize, iIconSize, uFlag, iSize, 1);
if (!SetHotImageList (hHot)) {
return false;
}
}

if (hDisabled == NULL) {
hDisabled = ImageList_Create (iIconSize, iIconSize, uFlag, iSize, 1);
if (!SetDisabledImageList (hDisabled)) {
return false;
}
}

pBtns = new TBBUTTON [iSize];
for (int i = 0; i < iSize; ++i) {
HICON hDefaultIcon, hHotIcon, hDisabledIcon;

// default
hDefaultIcon = (HICON)::LoadImage (
m_hInst,
MAKEINTRESOURCE (btns [i].uDefaultIconId),
IMAGE_ICON,
iIconSize,
iIconSize,
LR_DEFAULTCOLOR | LR_LOADTRANSPARENT);

assert (hDefaultIcon);
ImageList_AddIcon (hDefault, hDefaultIcon);

// hot
hHotIcon = (HICON)::LoadImage (
m_hInst,
MAKEINTRESOURCE (btns [i].uHotIconId),
IMAGE_ICON,
iIconSize,
iIconSize,
LR_DEFAULTCOLOR | LR_LOADTRANSPARENT);
assert (hHotIcon);
ImageList_AddIcon (hHot, hHotIcon);

// disabled
hDisabledIcon = (HICON)::LoadImage (
m_hInst,
MAKEINTRESOURCE (btns [i].uDisableIconId),
IMAGE_ICON,
iIconSize,
iIconSize,
LR_DEFAULTCOLOR | LR_LOADTRANSPARENT);
assert (hDisabledIcon);
ImageList_AddIcon (hDisabled, hDisabledIcon);

pBtns [i].iBitmap = i;
pBtns [i].idCommand = btns[i].uCmdId;
pBtns [i].dwData = 0;
pBtns [i].fsStyle = BTNS_BUTTON;
pBtns [i].fsState = TBSTATE_ENABLED;
pBtns [i].iString = SendMessage (m_hSelf, TB_ADDSTRING, (WPARAM)0, (LPARAM)btns[i].pszText);;

DestroyIcon (hDefaultIcon);
DestroyIcon (hHotIcon);
DestroyIcon (hDisabledIcon);

m_vctBtns.push_back (btns [i]);
}

fOk = AddButtons (pBtns, iSize);
if (pBtns) {
delete [] pBtns;
}
return fOk;
}


bool
CToolBar::
InsertButton (int iPos, const LPTBBUTTON lpBtn)
{
HIMAGELIST himl = GetDefaultImageList ();
if (himl) {
ImageList_Destroy (himl);
}

if (IsWindowValid (m_hSelf) && iPos > 0 && lpBtn != NULL) {
return SendMessage (m_hSelf, TB_INSERTBUTTON, (WPARAM)iPos, (LPARAM)lpBtn);
}

return false;
}


bool
CToolBar::
DeleteButton (UINT uBtnId)
{
if (IsWindowValid (m_hSelf)) {
return SendMessage (m_hSelf, TB_DELETEBUTTON, (WPARAM)GetButtonIndex (uBtnId), 0);
}

return false;
}


bool
CToolBar::
EnableButton (UINT uBtnId, BOOL fEnable)
{
if (IsWindowValid (m_hSelf)) {
return SendMessage (m_hSelf, TB_ENABLEBUTTON, (WPARAM)uBtnId, (LPARAM)MAKELONG (fEnable, 0));
}

return false;
}


bool
CToolBar::
IsButtonEnabled (UINT uBtnId)
{
if (IsWindowValid (m_hSelf)) {
return (GetButtonState (uBtnId) & TBSTATE_ENABLED);
}

return false;
}

bool
CToolBar::
HideButton (UINT uBtnid, BOOL fHide)
{
if (IsWindowValid (m_hSelf)) {
return SendMessage (m_hSelf, TB_HIDEBUTTON, (WPARAM)uBtnid, (LPARAM)MAKELONG (fHide, 0));
}

return false;
}

bool
CToolBar::
IsButtonVisible (UINT uBtnId)
{
if (IsWindowValid (m_hSelf)) {
return !(GetButtonState (uBtnId) & TBSTATE_HIDDEN);
}

return false;
}


bool
CToolBar::
MoveButton (UINT uOldPos, UINT uNewPos)
{
if (IsWindowValid (m_hSelf)) {
return SendMessage (m_hSelf, TB_MOVEBUTTON, (WPARAM)uOldPos, (LPARAM)uNewPos);
}

return false;
}

bool
CToolBar::
SetButtonBitmap (UINT uBtnId, int iBitmapIndex)
{
if (IsWindowValid (m_hSelf) && iBitmapIndex >= 0) {
TBBUTTONINFO bi = { 0 };
bi.cbSize = sizeof (TBBUTTONINFO);
bi.dwMask = TBIF_IMAGE;
return SetButtonInfo (uBtnId, &bi);
}

return false;
}

bool
CToolBar::
SetButtonInfo (UINT uBtnId, const TBBUTTONINFO* lptbbi)
{
if (IsWindowValid (m_hSelf) && lptbbi != NULL) {
return SendMessage (m_hSelf, TB_SETBUTTONINFO, (WPARAM)uBtnId, (LPARAM)lptbbi);
}

return false;
}


bool
CToolBar::
SetButtonSize (WORD wX, WORD wY)
{
if (IsWindowValid (m_hSelf)) {
return SendMessage (m_hSelf, TB_SETBUTTONSIZE, (WPARAM)0, (LPARAM)MAKELONG (wX, wY));
}

return false;
}


bool
CToolBar::
SetDefaultImageList (HIMAGELIST himlNew)
{
if (IsWindowValid (m_hSelf) && himlNew != NULL) {
HIMAGELIST imlOld = (HIMAGELIST)SendMessage (m_hSelf, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)himlNew);
if (imlOld != NULL) {
ImageList_Destroy (imlOld);
}

return true;
}

return false;
}


bool
CToolBar::
SetHotImageList (HIMAGELIST himlHotNew)
{
if (IsWindowValid (m_hSelf) && himlHotNew != NULL) {
HIMAGELIST imlOld = (HIMAGELIST)SendMessage (m_hSelf, TB_SETHOTIMAGELIST, (WPARAM)0, (LPARAM)himlHotNew);
if (imlOld != NULL) {
ImageList_Destroy (imlOld);
}
return true;
}

return false;
}


bool
CToolBar::
SetDisabledImageList (HIMAGELIST himlDisableNew)
{
if (IsWindowValid (m_hSelf) && himlDisableNew != NULL) {
HIMAGELIST imlOld = (HIMAGELIST)SendMessage (m_hSelf, TB_SETDISABLEDIMAGELIST, (WPARAM)0, (LPARAM)himlDisableNew);
if (imlOld != NULL) {
ImageList_Destroy (imlOld);
}
return true;
}

return false;
}


HIMAGELIST
CToolBar::
GetDefaultImageList (void)
{
if (IsWindowValid (m_hSelf)) {
return (HIMAGELIST)SendMessage (m_hSelf, TB_GETIMAGELIST, (WPARAM)0, (LPARAM)0);
}

return NULL;
}

HIMAGELIST
CToolBar::
GetHotImageList (void)
{
if (IsWindowValid (m_hSelf)) {
return (HIMAGELIST)SendMessage (m_hSelf, TB_GETHOTIMAGELIST, (WPARAM)0, (LPARAM)0);
}

return NULL;
}


HIMAGELIST
CToolBar::
GetDisabledImageList (void)
{
if (IsWindowValid (m_hSelf)) {
return (HIMAGELIST)SendMessage (m_hSelf, TB_GETDISABLEDIMAGELIST, (WPARAM)0, (LPARAM)0);
}

return NULL;
}




/****
** the parent MUST handle the WM_NOTIFY message
------------------------------------------------------------------
BOOL DoNotify(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
#define lpnm ((LPNMHDR)lParam)
#define lpnmTB ((LPNMTOOLBAR)lParam)

RECT rc;
TPMPARAMS tpm;
HMENU hPopupMenu = NULL;
HMENU hMenuLoaded;
BOOL bRet = FALSE;

switch(lpnm->code){
case TBN_DROPDOWN:
SendMessage(lpnmTB->hdr.hwndFrom, TB_GETRECT,
(WPARAM)lpnmTB->iItem, (LPARAM)&rc);

MapWindowPoints(lpnmTB->hdr.hwndFrom,
HWND_DESKTOP, (LPPOINT)&rc, 2);

tpm.cbSize = sizeof(TPMPARAMS);
tpm.rcExclude = rc;
hMenuLoaded = LoadMenu(g_hinst, MAKEINTRESOURCE(IDR_POPUP));
hPopupMenu = GetSubMenu(hMenuLoaded,0);
TrackPopupMenuEx(hPopupMenu,
TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
rc.left, rc.bottom, g_hwndMain, &tpm);
DestroyMenu(hMenuLoaded);
return (FALSE);
}

return FALSE;
}
*
*/
bool
CToolBar::
SetButtonToBeDropdown (UINT uBtn)
{
TBBUTTONINFO bi = {0};
bi.cbSize = sizeof (TBBUTTONINFO);

if (GetButtonInfo (uBtn, &bi)) {
bi.dwMask = TBIF_STYLE;
bi.fsStyle |= BTNS_DROPDOWN;
if (SetButtonInfo (uBtn, &bi)) {
return SetExtendedStyle (GetExtendedStyle () | TBSTYLE_EX_DRAWDDARROWS);
}
}

return false;
}


bool
CToolBar::
SetBitmapSize (WORD wX, WORD wY)
{
if (IsWindowValid (m_hSelf)) {
return SendMessage (m_hSelf, TB_SETBITMAPSIZE, (WPARAM)0, (LPARAM)MAKELONG (wX, wY));
}

return false;
}


int
CToolBar::
GetButtonCount (void)
{
if (IsWindowValid (m_hSelf)) {
return SendMessage (m_hSelf, TB_BUTTONCOUNT, (WPARAM)0, (LPARAM)0);
}

return -1;
}


bool
CToolBar::
GetButton (UINT uId, TBBUTTON* pBtn)
{
if (IsWindowValid (m_hSelf) && pBtn != NULL) {
return SendMessage (m_hSelf, TB_GETBUTTON, (WPARAM)GetButtonIndex (uId), (LPARAM)pBtn);
}

return false;
}


int
CToolBar::
GetButtonIndex (UINT uBtnId)
{
if (IsWindowValid (m_hSelf)) {
return SendMessage (m_hSelf, TB_COMMANDTOINDEX, (WPARAM)uBtnId, (LPARAM)0);
}

return -1;
}

bool
CToolBar::
GetButtonInfo (UINT uBtnId, TBBUTTONINFO* pBtnInfo)
{
if (IsWindowValid (m_hSelf) && pBtnInfo != NULL) {
pBtnInfo->dwMask = TBIF_COMMAND | TBIF_IMAGE | TBIF_LPARAM |
TBIF_STATE | TBIF_STYLE | (pBtnInfo->pszText == NULL ? 0 : TBIF_TEXT);
return (SendMessage (m_hSelf, TB_GETBUTTONINFO, (WPARAM)uBtnId, (LPARAM)pBtnInfo) != -1);
}

return false;
}

bool
CToolBar::
GetButtonText (UINT uBtnId, LPTSTR szText)
{
if (IsWindowValid (m_hSelf) && szText != NULL) {
TBBUTTONINFO bi = {0};
bool fRet = false;
bi.cbSize = sizeof (TBBUTTONINFO);
bi.pszText = new TCHAR [128];
bi.cchText = 127;

if (GetButtonInfo (uBtnId, &bi)) {
lstrcpy (szText, bi.pszText);
fRet = true;
}

if (bi.pszText != NULL) {
delete [] bi.pszText;
}

return fRet;
}

return false;
}

BYTE
CToolBar::
GetButtonState (UINT uBtnId)
{
if (IsWindowValid (m_hSelf)) {
return (BYTE)SendMessage (m_hSelf, TB_GETSTATE, (WPARAM)uBtnId, (LPARAM)0);
}

return 0;
}


int
CToolBar::
GetHotIndex (void)
{
if (IsWindowValid (m_hSelf)) {
return (int)SendMessage (m_hSelf, TB_GETHOTITEM, 0, 0);
}
return -1;
}


bool
CToolBar::
SetButtonText (UINT uBtnId, TCHAR* szText)
{
if (IsWindowValid (m_hSelf) && szText != NULL) {
TBBUTTONINFO bi = {0};
bi.cbSize = sizeof (TBBUTTONINFO);
bi.dwMask = TBIF_TEXT;
bi.pszText = szText;
bi.cchText = lstrlen (szText) + 1;

return SetButtonInfo (uBtnId, &bi);
}

return false;
}


DWORD
CToolBar::
GetExtendedStyle (void)
{
if (IsWindowValid (m_hSelf)) {
return SendMessage (m_hSelf, TB_GETEXTENDEDSTYLE, (WPARAM)0, (LPARAM)0);
}

return 0;
}


bool
CToolBar::
SetExtendedStyle (DWORD dwExtendedStyle)
{
if (IsWindowValid (m_hSelf)) {
SendMessage (m_hSelf, TB_SETEXTENDEDSTYLE, (WPARAM)0, (LPARAM)dwExtendedStyle);
return true;
}

return false;
}


DWORD
CToolBar::
GetStyle (void)
{
if (IsWindowValid (m_hSelf)) {
return SendMessage (m_hSelf, TB_GETSTYLE, (WPARAM)0, (LPARAM)0);
}

return 0;
}


bool
CToolBar::
SetStyle (DWORD dwStyle)
{
if (IsWindowValid (m_hSelf)) {
return SendMessage (m_hSelf, TB_SETSTYLE, (WPARAM)0, (LPARAM)dwStyle);
}

return false;
}


bool
CToolBar::
SetUnicodeFormat (BOOL fUnicode)
{
if (IsWindowValid (m_hSelf)) {
return SendMessage (m_hSelf, TB_SETUNICODEFORMAT, (WPARAM)fUnicode, (LPARAM)0);
}

return false;
}

bool
CToolBar::
IsUnicodeFormat (void)
{
if (IsWindowValid (m_hSelf)) {
return SendMessage (m_hSelf, TB_GETUNICODEFORMAT, (WPARAM)0, (LPARAM)0);
}

return false;
}


bool
CToolBar::
SetParent (HWND hParent)
{
if (IsWindowValid (m_hSelf) && IsWindowValid (hParent)) {
SendMessage (m_hSelf, TB_SETPARENT, (WPARAM)hParent, (LPARAM)0);
return true;
}

return false;
}



bool
CToolBar::
SetButtonToolTips (UINT uId, LPTSTR lpszText)
{
if (IsWindowValid (m_hSelf)) {
for (vector <ToolBarButton>::iterator it = m_vctBtns.begin (); it != m_vctBtns.end (); ++it) {
if (it->uCmdId == uId) {
it->pszToolTips = lpszText;
return true;
}
}
}

return false;
}



void
CToolBar::
DoToolTipNotify (LPARAM lParam)
{
switch (((LPNMHDR) lParam)->code)
{
case TTN_GETDISPINFO:
{
LPTOOLTIPTEXT lpttt;
UINT idButton;

lpttt = (LPTOOLTIPTEXT) lParam;
lpttt->hinst = m_hInst;

// Specify the resource identifier of the descriptive
// text for the given button.
idButton = lpttt->hdr.idFrom;
for (vector <ToolBarButton>::iterator it = m_vctBtns.begin (); it != m_vctBtns.end (); ++it) {
if (it->uCmdId == idButton) {
lpttt->lpszText = it->pszToolTips;
break;
}
}

break;
}

default:
break;
}

}


void
CToolBar::
DoDropDownNotify (LPARAM lParam, UINT uId, HMENU hMenu)
{
#define lpnm ((LPNMHDR)lParam)
#define lpnmTB ((LPNMTOOLBAR)lParam)

RECT rc;
TPMPARAMS tpm;
BOOL bRet = FALSE;

switch(lpnm->code){
case TBN_DROPDOWN:
if (GetHotIndex () == GetButtonIndex (uId) ) {

SendMessage(lpnmTB->hdr.hwndFrom, TB_GETRECT,
(WPARAM)lpnmTB->iItem, (LPARAM)&rc);

MapWindowPoints(lpnmTB->hdr.hwndFrom,
HWND_DESKTOP, (LPPOINT)&rc, 2);

tpm.cbSize = sizeof(TPMPARAMS);
tpm.rcExclude = rc;
TrackPopupMenuEx(hMenu,
TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
rc.left, rc.bottom, m_hParent, &tpm);
break;
}
break;

default:
break;
}
}


}

 

usage:

NSTS::ToolBarButton g_toolbarButtons[2] = {
{IDM_ABOUT, 16, 24, IDI_ICON1, IDI_ICON1, IDI_ICON1, TEXT ("ABOUT"), NULL},
{IDM_EXIT, 16, 24, IDI_ICON2, IDI_ICON2, IDI_ICON3, TEXT ("EXIT"), NULL}
};

NSTS::CToolBar g_tb;


WM_CREATE:
g_tb.Init (hWnd, hInst, g_toolbarButtons, 2);
g_tb.SetButtonToBeDropDown (IDM_ABOUT);
g_toolbar.SetButtonToolTips (IDM_ABOUT, TEXT ("ABOUT_1"));


WM_NOTIFY:
{
HMENU hLoadMenu, hSubMenu, hExitMenu;
hLoadMenu = LoadMenu (hInst, MAKEINTRESOURCE (IDC_TOOLBAR_DEMO));
assert (hLoadMenu);
hSubMenu = GetSubMenu (hLoadMenu, 1);
hExitMenu = GetSubMenu (hLoadMenu, 0);
assert (hSubMenu);

g_toolbar.DoToolTipNotify (lParam);
g_toolbar.DoDropDownNotify (lParam, IDM_ABOUT, hSubMenu);
g_toolbar.DoDropDownNotify (lParam, IDM_EXIT, hExitMenu);

DestroyMenu (hLoadMenu);
}




posted @ 2012-01-18 14:58  夜雨無聲  阅读(435)  评论(0编辑  收藏  举报