Status Bar Control Example

//status bar demo
#include <windows.h>
#include <CommCtrl.h>
#include <stdio.h>
#pragma comment(lib, "comctl32.lib")
#define IDC_STATUSBAR 100
#define IDI_ICON 101
//const TEXT ClassName[] = "MainWindowClass";
HWND hWndStatusBar;
LRESULT CALLBACK WndProc( HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam )
{
switch (Msg)
{
case WM_CREATE:
{
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);
if (!hWndStatusBar)
{
MessageBox(NULL, TEXT("Failed To Create The Status Bar"), TEXT("Error"), MB_OK | MB_ICONERROR);
return 0;
}
int iStatusWidths[] = {150,310, -1};
char text[256];
//Sets the number of parts in a status window and the coordinate of the right edge of each part.
SendMessage(hWndStatusBar, SB_SETPARTS, 3, (LPARAM)iStatusWidths);
//The SB_SETTEXT message sets the text in a status window.
SendMessage(hWndStatusBar, SB_SETTEXT, 0,(LPARAM)TEXT("Status Bar Cell 1 width 120"));
SendMessage(hWndStatusBar, SB_SETTEXT, 1,(LPARAM)TEXT("Status Bar Cell 2 width 130"));
sprintf(text, "%d", 3);
SendMessage(hWndStatusBar, SB_SETTEXT, 2,(LPARAM)TEXT("Status Bar Cell 3 width remaining space"));
ShowWindow(hWndStatusBar, SW_SHOW);
}
break;
case WM_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 )
{
InitCommonControls();
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));
wc.hIconSm= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = TEXT("MainWindowClass");
if (!RegisterClassEx(&wc))
{
MessageBox(NULL, TEXT("Failed To Register The Window Class."), TEXT("Error"), MB_OK | MB_ICONERROR);
return 0;
}

HWND hWnd;
hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,TEXT("MainWindowClass"),TEXT("Status Bar"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,550,120,NULL,NULL,hInstance,NULL);

if (!hWnd)
{
MessageBox(NULL, TEXT("Window Creation Failed."),TEXT( "Error"), MB_OK | MB_ICONERROR);
return 0;
}
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
MSG Msg;
while (GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}