Status Bar Demo

To create a Status Bar control, specify STATUSCLASSNAME as the window class and register the Status Bar common control class by specifying the ICC_BAR_CLASSES flag in the accompanying INITCOMMONCONTROLSEX structure before calling InitCommonControlsEx().

#define _WIN32_WINNT 0x0501 #include <windows.h> #include <commctrl.h> #include <stdio.h> #pragma comment(lib, "comctl32.lib") #define IDC_STATUSBAR 100 HWND hWndStatusBar; //Window procedure declaration LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { switch(Msg) { case WM_CREATE: { //Create status bar control hWndStatusBar = CreateWindowEx( 0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0, hWnd, (HMENU)IDC_STATUSBAR, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); //Check status bar was created if(!hWndStatusBar) { MessageBox( NULL, TEXT("Failed To Create Status Bar"), TEXT("Error"), MB_OK | MB_ICONERROR); return 0; } //Array containing the right edge position of each pane //The last value -1 fills the remaining window width int iStatusWidths[] = { 150, 310, -1 }; //Set number of panes and their widths SendMessage( hWndStatusBar, SB_SETPARTS, 3, (LPARAM)iStatusWidths); //Put text into first pane SendMessage( hWndStatusBar, SB_SETTEXT, 0, (LPARAM)TEXT("Ready")); //Put text into second pane SendMessage( hWndStatusBar, SB_SETTEXT, 1, (LPARAM)TEXT("Status Bar Demo")); //Put text into third pane SendMessage( hWndStatusBar, SB_SETTEXT, 2, (LPARAM)TEXT("Visual C++ 6.0")); break; } case WM_SIZE: { //Resize status bar when window changes size SendMessage( hWndStatusBar, WM_SIZE, 0, 0); break; } case WM_CLOSE: { DestroyWindow(hWnd); break; } case WM_DESTROY: { PostQuitMessage(0); break; } default: return DefWindowProc( hWnd, Msg, wParam, lParam); } return 0; } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //Load common controls InitCommonControls(); WNDCLASSEX wc; MSG Msg; //Define window class 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.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszMenuName = NULL; wc.lpszClassName = TEXT("MainWindowClass"); //Register window class if(!RegisterClassEx(&wc)) { MessageBox( NULL, TEXT("Window Registration Failed"), TEXT("Error"), MB_OK | MB_ICONERROR); return 0; } //Create main application window HWND hWnd = CreateWindowEx( WS_EX_CLIENTEDGE, TEXT("MainWindowClass"), TEXT("Status Bar Demo"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 550, 150, NULL, NULL, hInstance, NULL); if(hWnd == NULL) { return 0; } //Display window ShowWindow( hWnd, nCmdShow); UpdateWindow(hWnd); //Main message loop while(GetMessage(&Msg,NULL,0,0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; }