#define IDC_MAIN_TOOLBAR 1001
#include <commctrl.h>
InitCommonControls();
case WM_CREATE:
hWndToolBar = CreateToolBar(hWnd);
break;case WM_SIZE:
hWndToolBar = GetDlgItem(hWnd,IDC_MAIN_TOOLBAR);
SendMessage(hWndToolBar,WM_SIZE,0,0);
break;HWND CreateToolBar(HWND hWndParent)
{
HWND hWndTB;
TBBUTTON tbb[4];
//TBADDBITMAP tbab;
hWndTB = CreateWindowEx(0,TOOLBARCLASSNAME,TEXT(""),WS_CHILD|WS_VISIBLE|CCS_NODIVIDER|TBSTYLE_LIST,
0,0,0,0,hWndParent,(HMENU)IDC_MAIN_TOOLBAR,
hInst,NULL);
if(!hWndTB)
return 0;
SendMessage(hWndTB, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);HIMAGELIST hImageList = ImageList_Create(32,28,ILC_COLOR24,3,1);
HBITMAP hBitmap = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_MAIN_TOOLBAR));
ImageList_Add(hImageList,hBitmap,NULL);
DeleteObject (hBitmap);SendMessage(hWndTB,TB_SETIMAGELIST,0,(LPARAM)hImageList);
//tbab.hInst = NULL;
//tbab.nID =IDB_TOOLBAR;
//SendMessage(hWndTB, TB_ADDBITMAP, (WPARAM)(int)2, (LPARAM)&tbab);ZeroMemory(tbb, sizeof(tbb));
tbb[0].iBitmap =MAKELONG(0,0) ;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_BUTTON|BTNS_AUTOSIZE;
tbb[0].idCommand = IDM_FIND;
tbb[0].iString = (INT_PTR)TEXT("查找");tbb[1].iBitmap =MAKELONG(1,0);
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON|BTNS_AUTOSIZE;
tbb[1].idCommand = IDM_BACK;
tbb[1].iString = (INT_PTR)TEXT("后退");tbb[2].iBitmap =MAKELONG(2,0);
tbb[2].fsState = TBSTATE_ENABLED;
tbb[2].fsStyle = TBSTYLE_BUTTON|BTNS_AUTOSIZE;
tbb[2].idCommand = IDM_FORWARD;
tbb[2].iString = (INT_PTR)TEXT("向前");tbb[3].iBitmap =MAKELONG(3,0);
tbb[3].fsState = TBSTATE_ENABLED;
tbb[3].fsStyle = TBSTYLE_BUTTON|BTNS_AUTOSIZE;
tbb[3].idCommand = IDM_VIEW;
tbb[3].iString = (INT_PTR)TEXT("视图");SendMessage(hWndTB, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
SendMessage(hWndTB,WM_SIZE,0,0);return hWndTB;
}
程序运行如下:
本文引用通告地址: http://blog.csdn.net/ruchimy/services/trackbacks/360004.aspx