Stefan
Stefan

Reputation: 1

how to make the text appear in center of the window when re-sizing it, visual c++

so i've got this code:

{
    PAINTSTRUCT ps;
    HDC hdc;

switch (message)
{
case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    TextOut(hdc,
        100, 55, TEXT("some text here"), 50
        );

    EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
    PostQuitMessage(0);
    break;
default:
    return DefWindowProc(hWnd, message, wParam, lParam);
    break;
}

How can i make the text appear in the center when re-sizing the window?

Upvotes: 0

Views: 1068

Answers (1)

ScottMcP-MVP
ScottMcP-MVP

Reputation: 10425

Call GetClientRect to get the window dimensions. Do some math to get the center coordinate. It will be easier if you also call SetTextAlign with TA_CENTER to use the text center point as the coordianate you give to TextOut.

Upvotes: 2

Related Questions