To create a pager control specify WC_PAGESCROLLER as the window class and register the class by specifying the ICC_PAGESCROLLER_CLASS bit flag in the accompanying INITCOMMONCONTROLSEX structure.
#include <windows.h> #include <commctrl.h> #pragma warning(disable:4996) #pragma comment(lib, "comctl32.lib") //adds link to control control DLL #define TB_TEST1 1001 #define TB_TEST2 1002 #define TB_TEST3 1003 #define TB_TEST4 1004 #define TB_TEST5 1005 #define TB_TEST6 1006 #define TB_TEST7 1007 #define TB_TEST8 1008 #define TB_TEST9 1009 HWND hWndToolBar, hWndPager; 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("Page scroller Demo"), WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 340, 150, 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: { // load common control class ICC_PAGESCROLLER_CLASS from the dynamic-link library (DLL) INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(INITCOMMONCONTROLSEX); icex.dwICC = ICC_PAGESCROLLER_CLASS; InitCommonControlsEx(&icex); //create toolar and pager windows HBITMAP toolbarBitMap=NULL; TBBUTTON tbb[9]; HIMAGELIST imageList = NULL; hWndPager = CreateWindow(WC_PAGESCROLLER, NULL, WS_CHILD | WS_VISIBLE | PGS_HORZ, 100, 40, 120, 40, hwnd, NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); hWndToolBar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, TBSTYLE_TRANSPARENT | WS_CHILD | WS_VISIBLE | CCS_NORESIZE, 0, 0, 0, 0, hWndPager, NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); SendMessage(hWndToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); // Creates image list for toolbar imageList = ImageList_Create(24, 24, ILC_COLOR8 | ILC_MASK, 5, 0); //add bitmap to image list ImageList_Add(imageList, toolbarBitMap, NULL); //add imagelist to toolbar SendMessage(hWndToolBar, TB_SETIMAGELIST, 0, (LPARAM)imageList); //add system-defined button image to image list SendMessage(hWndToolBar, TB_LOADIMAGES, (WPARAM)IDB_STD_LARGE_COLOR, (LPARAM)HINST_COMMCTRL); ZeroMemory(tbb, sizeof(tbb)); //Define 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].iBitmap = 1; tbb[1].idCommand = TB_TEST2; tbb[1].fsState = TBSTATE_ENABLED; tbb[1].fsStyle = TBSTYLE_BUTTON; tbb[2].iBitmap = 2; tbb[2].idCommand = TB_TEST3; tbb[2].fsState = TBSTATE_ENABLED; tbb[2].fsStyle = TBSTYLE_BUTTON; tbb[3].iBitmap = 3; tbb[3].idCommand = TB_TEST4; tbb[3].fsState = TBSTATE_ENABLED; tbb[3].fsStyle = TBSTYLE_BUTTON; tbb[4].iBitmap = 4; tbb[4].idCommand = TB_TEST5; tbb[4].fsState = TBSTATE_ENABLED; tbb[4].fsStyle = TBSTYLE_BUTTON; tbb[5].iBitmap = 5; tbb[5].idCommand = TB_TEST6; tbb[5].fsState = TBSTATE_ENABLED; tbb[5].fsStyle = TBSTYLE_BUTTON; tbb[6].iBitmap = 6; tbb[6].idCommand = TB_TEST7; tbb[6].fsState = TBSTATE_ENABLED; tbb[6].fsStyle = TBSTYLE_BUTTON; tbb[7].iBitmap = 7; tbb[7].idCommand = TB_TEST8; tbb[7].fsState = TBSTATE_ENABLED; tbb[7].fsStyle = TBSTYLE_BUTTON; tbb[8].iBitmap = 8; tbb[8].idCommand = TB_TEST9; tbb[8].fsState = TBSTATE_ENABLED; tbb[8].fsStyle = TBSTYLE_BUTTON; //message TB_ADDBUTTONS add three buttons as defined in TBBUTTON structure tbb SendMessage(hWndToolBar, TB_ADDBUTTONS, 9, (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); SendMessage(hWndPager, PGM_SETCHILD, 0, (LPARAM)hWndToolBar); break; } case WM_NOTIFY: { NMHDR *hdr = (NMHDR *)lParam; if (hdr->code == PGN_CALCSIZE) { LPNMPGCALCSIZE pCalcSize = (LPNMPGCALCSIZE)lParam; if (pCalcSize->dwFlag == PGF_CALCWIDTH) { SIZE size; SendMessage(hWndToolBar, TB_GETMAXSIZE, 0, (LPARAM)&size); pCalcSize->iWidth = size.cx; } } } break; case WM_COMMAND: { switch (LOWORD(wParam)) { //respond to button clicks } } break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }