Listing 2 Sample code to print a string in the center of the window
case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); RECT rect; GetClientRect(hwnd, &rect); Graphics graphics(hdc); // Use a gray brush SolidBrush brush(Color(255, 128, 128, 128)); LPCWSTR str = L"Windows Developer Magazine"; int len = wcslen(str); // Calculate the font size to fill the window width, // assume average width is less than height of font int pixelsPerChar = (rect.right-rect.left)/len; FontFamily fontFamily(L"Arial"); Font font(&fontFamily, pixelsPerChar, FontStyleRegular, UnitPixel); RectF client(rect.left, rect.top, rect.right, rect.bottom); // Indicate that we want the string in the // center of the window StringFormat format; format.SetAlignment(StringAlignmentCenter); format.SetLineAlignment(StringAlignmentCenter); // Draw the string graphics.DrawString(str, -1, &font, client, &format, &brush); EndPaint(hwnd, &ps); }