StatusBar
Visual C++ 2005 Express Edition
Windows Server 2003 SP1 Platform SDK
Windowsアプリケーション / 空のプロジェクト
StatusBar.c
// マルチバイト文字セット // comctl32.lib #include
#include
#define APPNAME "StatusBar" #define IDC_WND_STATUS 1 // グローバル変数 static HINSTANCE g_hInstance; static HWND g_hWndStatus; // プロトタイプ宣言 LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); void OnPaint(HWND hWnd); void OnCreate(HWND hWnd); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char acAppName[] = APPNAME; WNDCLASSEX wcex; HWND hWnd; MSG msg; g_hInstance = hInstance; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = g_hInstance; wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wcex.lpszMenuName = NULL; wcex.lpszClassName = acAppName; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); RegisterClassEx(&wcex); hWnd = CreateWindow( acAppName, // ClassName acAppName, // WindowName WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, // x CW_USEDEFAULT, // y CW_USEDEFAULT, // Width CW_USEDEFAULT, // Height NULL, // WndParent NULL, // Menu g_hInstance, NULL); // Param if (hWnd == NULL) { return 0; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_PAINT: OnPaint(hWnd); break; case WM_SIZE: SendMessage(g_hWndStatus, WM_SIZE, wParam, lParam); break; case WM_CREATE: OnCreate(hWnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; } void OnPaint(HWND hWnd) { PAINTSTRUCT ps; HDC hdc; RECT rcClient; RECT rcStatus; int iWidth; int iHeight; hdc = BeginPaint(hWnd, &ps); GetClientRect(hWnd, &rcClient); GetWindowRect(g_hWndStatus, &rcStatus); iWidth = rcClient.right; iHeight = rcClient.bottom - (rcStatus.bottom - rcStatus.top); MoveToEx(hdc, 0, 0, NULL); LineTo(hdc, iWidth, iHeight); EndPaint(hWnd, &ps); } void OnCreate(HWND hWnd) { INITCOMMONCONTROLSEX icc; icc.dwSize = sizeof(INITCOMMONCONTROLSEX); icc.dwICC = ICC_BAR_CLASSES; InitCommonControlsEx(&icc); g_hWndStatus = CreateStatusWindow( WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP, NULL, hWnd, IDC_WND_STATUS); SendMessage(g_hWndStatus, SB_SIMPLE, TRUE, 0); SendMessage(g_hWndStatus, SB_SETTEXT, 255 | 0, (LPARAM)"hello, world"); }