In the following example, a simple three-button toolbar is created with two standard buttons separated by a separator. A separator provides a small gap between groups of buttons and does not receive user input. The toolbar images are loaded into an image list, which is created by calling the ImageList_Create() function. Images can be loaded from a bitmap using LoadImage() or by using one of the standard system image sets with the TB_LOADIMAGES message. The image list is then attached to the toolbar using the TB_SETIMAGELIST message. Each button’s associated image is specified by the iBitmap member of the TBBUTTON structure. Clicking either button generates a message box indicating which button was selected. In order for the toolbutton image to be displayed correctly the image icons will need to be downloaded and placed into the project directory alongside the cpp file.
For in depth reading on the creation of toolbars https://docs.microsoft.com/en-us/windows/win32/controls/toolbar-control-reference#include <windows.h> #include <commctrl.h> #pragma comment(lib, "comctl32.lib") //adds link to control control DLL HINSTANCE ghInstance; #define TB_TEST1 1003 #define TB_TEST2 1004 static HWND hWndToolBar; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; MSG msg; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszMenuName = NULL; wc.lpszClassName = TEXT("myWindowClass"); wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); RegisterClassEx(&wc); InitCommonControls(); CreateWindowEx(WS_EX_CLIENTEDGE,TEXT("myWindowClass"),TEXT("Simple Toolbar Window"), WS_VISIBLE | WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, hInstance, NULL); while(GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: TBBUTTON tbb[3]; HBITMAP toolbarBitMap; //add toolbar images to toolbar bitmap toolbarBitMap = (HBITMAP)LoadImage(NULL, TEXT("tbbitmap.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); //create toolbar hWndToolBar = CreateWindowEx(0,TOOLBARCLASSNAME, NULL,TBSTYLE_TRANSPARENT | WS_CHILD| WS_VISIBLE,0,0,0,0,hwnd,NULL , (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); HIMAGELIST imageList; // Creates image list imageList = ImageList_Create(30, 30, ILC_COLOR8 | ILC_MASK, 4, 0); //add bitmap to image list ImageList_Add(imageList, toolbarBitMap, NULL); //add imagelist to toolbar SendMessage(hWndToolBar, TB_SETIMAGELIST, 0, (LPARAM)imageList); ZeroMemory(tbb, sizeof(tbb)); //TBBUTON variable defines characteristics of each toolbar button. tbb[0].iBitmap = 0; tbb[0].idCommand = TB_TEST1; tbb[0].fsState = TBSTATE_ENABLED; tbb[0].fsStyle = TBSTYLE_BUTTON; tbb[1].fsState = TBSTATE_ENABLED; tbb[1].fsStyle = TBSTYLE_SEP; tbb[2].iBitmap = 1; tbb[2].idCommand = TB_TEST2; tbb[2].fsState = TBSTATE_ENABLED; tbb[2].fsStyle = TBSTYLE_BUTTON; //message TB_ADDBUTTONS add three buttons as defined in TBBUTTON structure tbb SendMessage(hWndToolBar, TB_ADDBUTTONS, 3, (LPARAM)&tbb); //message TB_AUTOSIZE causes a toolbar to be resized so that icons and buttons are aligined in toolbar SendMessage(hWndToolBar, TB_AUTOSIZE , 0, 0); break; case WM_COMMAND: { switch(LOWORD(wParam)) { //responds to button 1 click case TB_TEST1: { MessageBox(NULL, TEXT("Toolbar Button One"),TEXT("Success"), MB_OK | MB_ICONINFORMATION); } break; //responds to button 2 click case TB_TEST2: { MessageBox(NULL, TEXT("Toolbar Button Two"), TEXT("Success"), MB_OK | MB_ICONINFORMATION); } break; } } break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }