#include HINSTANCE hInst; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { static HWND hLeftLabel, hCenterLabel, hRightLabel, hSimpleLabel; static HWND hLeftText, hCenterText, hRightText, hSimpleText;; static int cxChar, cyChar; int width; switch (msg) { case WM_CREATE: hLeftLabel = CreateWindowEx(0, "STATIC", "Left aligned", WS_CHILD | WS_VISIBLE | SS_LEFT, 0, 0, 0, 0, hwnd, (HMENU) -1, hInst, NULL); hCenterLabel = CreateWindowEx(0, "STATIC", "Center aligned", WS_CHILD | WS_VISIBLE | SS_LEFT, 0, 0, 0, 0, hwnd, (HMENU) -1, hInst, NULL); hRightLabel = CreateWindowEx(0, "STATIC", "Right aligned", WS_CHILD | WS_VISIBLE | SS_LEFT, 0, 0, 0, 0, hwnd, (HMENU) -1, hInst, NULL); hSimpleLabel = CreateWindowEx(0, "STATIC", "Simple aligned", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 0, 0, 0, 0, hwnd, (HMENU) -1, hInst, NULL); hLeftText = CreateWindowEx(0, "STATIC", "Left aligned", WS_CHILD | WS_VISIBLE | SS_LEFT, 0, 0, 0, 0, hwnd, (HMENU) -1, hInst, NULL); hCenterText = CreateWindowEx(0, "STATIC", "Center aligned", WS_CHILD | WS_VISIBLE | SS_CENTER, 0, 0, 0, 0, hwnd, (HMENU) -1, hInst, NULL); hRightText = CreateWindowEx(0, "STATIC", "Right aligned", WS_CHILD | WS_VISIBLE | SS_RIGHT, 0, 0, 0, 0, hwnd, (HMENU) -1, hInst, NULL); hSimpleText = CreateWindowEx(0, "STATIC", "Simple aligned", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 0, 0, 0, 0, hwnd, (HMENU) -1, hInst, NULL); cxChar = cyChar = -1; break; case WM_SIZE: width = LOWORD(lparam); if (cxChar == -1) { HDC hdc = GetDC(hwnd); TEXTMETRIC tm; GetTextMetrics(hdc, &tm); cxChar = tm.tmAveCharWidth; cyChar = tm.tmHeight + tm.tmExternalLeading; ReleaseDC(hwnd, hdc); } MoveWindow(hLeftLabel, cxChar, 0, cxChar*20, cyChar, TRUE); MoveWindow(hCenterLabel, cxChar, cyChar*4, cxChar*20, cyChar, TRUE); MoveWindow(hRightLabel, cxChar, cyChar*8, cxChar*20, cyChar, TRUE); MoveWindow(hSimpleLabel, cxChar, cyChar*12, cxChar*20, cyChar, TRUE); MoveWindow(hLeftText, width/2, 0, cxChar*8, cyChar, TRUE); MoveWindow(hCenterText, width/2, cyChar*4, cxChar*8, cyChar, TRUE); MoveWindow(hRightText, width/2, cyChar*8, cxChar*8, cyChar, TRUE); MoveWindow(hSimpleText, width/2, cyChar*12, cxChar*8, cyChar, TRUE); break; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, msg, wparam, lparam); } int WINAPI WinMain(HINSTANCE instance, HINSTANCE prev, LPSTR cmdLine, int cmdShow) { WNDCLASSEX class; MSG msg; HWND window; /* this stuff is just boilerplate */ memset(&class, 0, sizeof(WNDCLASSEX)); class.cbSize = sizeof(WNDCLASSEX); class.hInstance = instance; class.lpszClassName = "MainWnd"; class.lpfnWndProc = WndProc; class.hbrBackground = (HBRUSH) COLOR_WINDOW ; if (!RegisterClassEx(&class)) { MessageBox(NULL, "Could not register window class", "", MB_OK | MB_ICONERROR); return 1; } window = CreateWindowEx(0, "MainWnd", "Main Window", WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 400, 400, NULL, NULL, instance, NULL); ShowWindow(window, cmdShow); /* Every thread that creates a window must pump the message loop */ while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; }