Code:
#pragma comment(lib,"comctl32.lib")
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commctrl.h>
HINSTANCE appInst;
HWND hwndTool;
#define WINWIDTH 300
#define WINHEIGHT 300
LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
switch (Message)
{
case WM_CREATE:
{
INITCOMMONCONTROLSEX iccx;
TBADDBITMAP tbAddBmp;
TBBUTTON tbb[5];
iccx.dwSize=sizeof(INITCOMMONCONTROLSEX);
iccx.dwICC=ICC_BAR_CLASSES;
InitCommonControlsEx(&iccx);
hwndTool = CreateWindowEx(0,
TOOLBARCLASSNAME,
NULL,
WS_CHILD|WS_VISIBLE|
TBSTYLE_FLAT|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_NORESIZE,
0,
0,
WINWIDTH,
40,
hwnd,
NULL,
appInst,
NULL);
SendMessage(hwndTool,TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON),0);
tbAddBmp.hInst=HINST_COMMCTRL;
tbAddBmp.nID=IDB_STD_SMALL_COLOR;
// SendMessage(hwndTool,TB_ADDBITMAP,0,(WPARAM)&tbAddBmp);
// tbb[0].iBitmap=STD_FILENEW;
tbb[0].idCommand=-1;
tbb[0].fsState=TBSTATE_ENABLED;
tbb[0].fsStyle=TBSTYLE_BUTTON;
tbb[0].dwData=0;
tbb[0].iString=SendMessage(hwndTool,TB_ADDSTRING,0,(LPARAM)TEXT("New"));
// tbb[1].iBitmap=STD_FILEOPEN;
tbb[1].idCommand=-1;
tbb[1].fsState=TBSTATE_ENABLED;
tbb[1].fsStyle=TBSTYLE_BUTTON;
tbb[1].dwData=0;
tbb[1].iString=SendMessage(hwndTool,TB_ADDSTRING,0,(LPARAM)TEXT("Open"));
// tbb[2].iBitmap=STD_FILESAVE;
tbb[2].idCommand=-1;
tbb[2].fsState=TBSTATE_ENABLED;
tbb[2].fsStyle=TBSTYLE_BUTTON;
tbb[2].dwData=0;
tbb[2].iString=SendMessage(hwndTool,TB_ADDSTRING,0,(LPARAM)TEXT("Save"));
//tbb[3].iBitmap=STD_PRINTPRE;
tbb[3].idCommand=-1;
tbb[3].fsState=TBSTATE_ENABLED;
tbb[3].fsStyle=TBSTYLE_BUTTON;
tbb[3].dwData=0;
tbb[3].iString=SendMessage(hwndTool,TB_ADDSTRING,0,(LPARAM)TEXT("PrintPre"));
//
// tbb[4].iBitmap=STD_PRINT;
tbb[4].idCommand=-1;
tbb[4].fsState=TBSTATE_ENABLED;
tbb[4].fsStyle=TBSTYLE_BUTTON;
tbb[4].dwData=0;
tbb[4].iString=SendMessage(hwndTool,TB_ADDSTRING,0,(LPARAM)TEXT("Print"));
SendMessage(hwndTool,TB_ADDBUTTONS,5,(LPARAM)(LPTBBUTTON)&tbb);
return 0;
}
case WM_SIZE:
{
MoveWindow(hwndTool,0,0,LOWORD(lParam),40,false);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
default:
return DefWindowProc(hwnd,Message,wParam,lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASSEX wcx;
appInst = hInstance;
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = CS_HREDRAW|CS_VREDRAW;
wcx.lpfnWndProc = (WNDPROC)WndProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hInstance;
wcx.hIcon = LoadIcon(0,IDI_APPLICATION);
wcx.hCursor = LoadCursor(0,IDC_ARROW);
wcx.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH));
wcx.lpszMenuName = NULL;
wcx.lpszClassName = "ToolBarExample";
wcx.hIconSm = NULL;
if (!RegisterClassEx(&wcx))
{
MessageBox( NULL,"Failed to register wnd class","ERROR",MB_OK|MB_ICONERROR);
return FALSE;
}
hwnd=CreateWindowEx(0,
"ToolBarExample",
"Toolbar Example",
WS_OVERLAPPEDWINDOW,
GetSystemMetrics(SM_CXSCREEN)/4,
GetSystemMetrics(SM_CYSCREEN)/4,
WINWIDTH,
WINHEIGHT,
NULL,
NULL,
hInstance,
NULL);
if (!hwnd)
{
MessageBox( NULL,
"Failed to create wnd",
"ERROR",
MB_OK|MB_ICONERROR);
return FALSE;
}
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&Msg,NULL,0,0)>0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
I have read many pages at msdn relating to toolbars and have not yet found a solution to my problem. Any help will be greatly appreciated.