that is not a question on VC++.. it's one for win32api.
there is a source code on MSDN:
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include "globals.h"
#include "toolbar.h"
#include "statbar.h"
#include "resource.h"
HWND hWndToolbar;
#define NUMIMAGES 20
#define IMAGEWIDTH 18
#define IMAGEHEIGHT 17
#define BUTTONWIDTH 0
#define BUTTONHEIGHT 0
TBBUTTON tbButton[ ] =
{
{0, IDM_FILENEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{1, IDM_FILEOPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{2, IDM_FILESAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{3, IDM_EDITCUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0},
{4, IDM_EDITCOPY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{5, IDM_EDITPASTE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{6, IDM_FILEPRINT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0},
{7, IDM_ABOUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
};
TBBUTTON tbButtonNew[ ] =
{
{ 8, IDM_ERASE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{ 9, IDM_PEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{10, IDM_SELECT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{11, IDM_BRUSH, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{12, IDM_AIRBRUSH, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{13, IDM_FILL, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{14, IDM_LINE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{15, IDM_EYEDROP, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{16, IDM_ZOOM, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{17, IDM_RECT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{18, IDM_FRAME, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{19, IDM_OVAL, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
};
char pszStrings[ ] = {'&','N','E','W','\0','\0'};
BOOL CreateTBar(HWND hwnd)
{
int iNew;
UINT ID;
hWndToolbar = CreateToolbarEx(hwnd,
WS_CHILD | WS_VISIBLE
| CCS_ADJUSTABLE | TBSTYLE_TOOLTIPS,
IDM_TOOLBAR,
NUMIMAGES,
hInst,
IDB_BMP,
tbButton,
sizeof(tbButton)/sizeof(TBBUTTON),
BUTTONWIDTH,
BUTTONHEIGHT,
IMAGEWIDTH,
IMAGEHEIGHT,
sizeof(TBBUTTON));
iNew = SendMessage(hWndToolbar, TB_ADDSTRING,(WPARAM) 0, (LPARAM) pszStrings);
iNew = SendMessage(hWndToolbar, TB_MAPACCELERATOR, (WPARAM) 'N', (LPARAM) &ID);
return (hWndToolbar != NULL);
}
LRESULT MsgNotify(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
LPTOOLTIPTEXT lpToolTipText;
static char szBuffer[64];
static UINT i=0;
LPNMHDR lpnmhdr;
lpToolTipText = (LPTOOLTIPTEXT)lparam;
lpnmhdr = (LPNMHDR)lparam;
if (lpnmhdr->code == TBN_QUERYINSERT)
return TRUE;
else if (lpnmhdr->code == TBN_QUERYDELETE)
{
return TRUE;
}
else if (lpnmhdr->code == TBN_DELETINGBUTTON)
{
return TRUE;
}
else if (lpnmhdr->code == TBN_BEGINDRAG)
return TRUE;
else if (lpnmhdr->code == TBN_ENDDRAG)
return TRUE;
else if (lpnmhdr->code == TBN_BEGINADJUST)
return TRUE;
else if (lpnmhdr->code == TBN_INITCUSTOMIZE)
return TRUE;
else
if (lpnmhdr->code == TBN_GETBUTTONINFO)
{
LPTBNOTIFY lpTbNotify = (LPTBNOTIFY)lparam;
char szBuffer [20];
if (lpTbNotify->iItem < 12)
{
lpTbNotify->tbButton = tbButtonNew[lpTbNotify->iItem];
LoadString(hInst,
4000+ lpTbNotify->iItem,
szBuffer,
sizeof(szBuffer));
lstrcpy (lpTbNotify->pszText, szBuffer);
lpTbNotify->cchText = sizeof (szBuffer);
return TRUE;
}
else
return 0;
}
else
if (lpToolTipText->hdr.code == TTN_NEEDTEXT)
{
LoadString(hInst,
lpToolTipText->hdr.idFrom,
szBuffer,
sizeof(szBuffer));
UpdateStatusBar(lpToolTipText->lpszText, 0, 0);
lpToolTipText->hinst = hInst;
lpToolTipText->lpszText = MAKEINTRESOURCE(lpToolTipText->hdr.idFrom);
}
return 0;
}
hope this helps.
Don't try it, just do it!
|