Code:
HWND CreateAToolBar(void)
{
HWND hwndTB;
INT index, stdidx;
//Buttons
TBBUTTON tbb [ ] =
{
{STD_FILENEW, M_FILE_NEW, TBSTATE_ENABLED, BTNS_BUTTON, 0,0L, 0},
{STD_FILEOPEN, M_FILE_OPEN, TBSTATE_ENABLED, BTNS_BUTTON, 0,0L, 0},
{STD_FILESAVE, M_FILE_SAVE, TBSTATE_ENABLED, BTNS_BUTTON, 0,0L, 0},
{5, 0, TBSTATE_ENABLED, BTNS_SEP, 0,0L, 0},
{TBIMG_REFRESH, M_FILE_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, 0,0L, 0},
{5, 0, TBSTATE_ENABLED, BTNS_SEP, 0,0L, 0},
{STD_CUT, M_EDIT_CUT, TBSTATE_ENABLED, BTNS_BUTTON, 0,0L, 0},
{STD_COPY,M_EDIT_COPY, TBSTATE_ENABLED, BTNS_BUTTON, 0,0L, 0},
{STD_PASTE, M_EDIT_PASTE, TBSTATE_ENABLED, BTNS_BUTTON, 0,0L, 0},
{STD_UNDO, M_EDIT_UNDO, TBSTATE_ENABLED, BTNS_BUTTON, 0,0L, 0},
{5, 0, TBSTATE_ENABLED, BTNS_SEP, 0,0L, 0},
{TBIMG_FIND, M_SRCH_FND, TBSTATE_ENABLED, BTNS_BUTTON, 0,0L, 0},
{5, 0, TBSTATE_ENABLED, BTNS_SEP, 0,0L, 0},
{TBIMG_CALC,M_CALC, TBSTATE_ENABLED, BTNS_BUTTON, 0,0L, 0},
};
//Button Strings
LPSTR toolStrings[ ] = {
"New", "Open", "Save","", "Refresh", "", "Cut", "Copy", "Paste","Undo","","Find","","Calculator",
};
//Create a toolbar that has ToolTips associated with it.
hwndTB = CreateWindowEx(0, TOOLBARCLASSNAME, (LPSTR) NULL,
WS_CHILD | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT,0, 0, 0, 0,
hDlg,(HMENU) M_MAIN, hInst, NULL);
// Send the TB_BUTTONSTRUCTSIZE message, which is required for
// backward compatibility.
SendMessage(hwndTB, TB_BUTTONSTRUCTSIZE,(WPARAM) sizeof(TBBUTTON), 0);
//Prevents text from displaying
SendMessage(hwndTB, TB_SETMAXTEXTROWS,0,0);
// Associate strings with buttons
for (index = 0;index < 14;index++) {
if (*toolStrings[index] != *"")
tbb[index].iString = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) toolStrings[index]);
else tbb[index].iString = 0;
}
//Add standard images
TBADDBITMAP tb;
tb.hInst = HINST_COMMCTRL;
tb.nID = IDB_STD_SMALL_COLOR;
SendMessage (hwndTB, TB_ADDBITMAP, 0, (LPARAM)&tb);
//Add custom images
tb.hInst = hInst;
tb.nID = BITMAP_ICONS;
stdidx = SendMessage (hwndTB, TB_ADDBITMAP, 2, (LPARAM)&tb);
//update bitmap indexes for custom images
tbb[4].iBitmap += stdidx; //refresh
tbb[13].iBitmap +=stdidx; //calculator
tbb[11].iBitmap +=stdidx; //Find - Windows does provide a find image
//but it is a magnifying glass and not the standard binoculars.
//Add buttons
//Don't add calculator button or last separator if we
//couldn't find the calculator.
SendMessage(hwndTB, TB_ADDBUTTONS, (WPARAM) (calcFound ? 14 : 12), (LPARAM) (LPTBBUTTON) &tbb);
//Size and show window
SendMessage(hwndTB, TB_AUTOSIZE, 0, 0);
ShowWindow(hwndTB, SW_SHOWNORMAL);
//Get bottom of toolbar so we can size edit box
RECT toolRect;
SendMessage(hwndTB,TB_GETRECT,0,(WPARAM) &toolRect);
toolBottom = toolRect.bottom;
return hwndTB;
}