Doubstract
Doubstract

Reputation: 1

It is possible to use DrawText or TextOut text rendering in GDI

I am trying to render some text on screen. I am using GDI, C++ and trying to use DrawText and TextOut functions to render my text. My text only appears when program starts, and then text immediatily disappear. Am i able to use it with GDI and if i am, then how?

HDC         hDC;
PAINTSTRUCT Ps;
HFONT       font;
LOGFONT LogFont;

...

hDC = BeginPaint(hWnd, &Ps);

GDI render code

    LogFont.lfStrikeOut = 0;
    LogFont.lfUnderline = 0;
    LogFont.lfHeight = 42;
    LogFont.lfEscapement = 0;
    LogFont.lfItalic = TRUE;

    font = CreateFontIndirect(&LogFont);
    SelectObject(hDC, font);
    TextOut(hDC, 20, 18, "Some text", 14);

    DeleteObject(font);

EndPaint(hWnd, &Ps);

Using code from this lesson.

Upvotes: 0

Views: 1244

Answers (1)

Alex F
Alex F

Reputation: 43311

My text only appears when program starts, and then text immediately disappear This usually happens when drawing is done not in WM_PAINT message handler.

Upvotes: 0

Related Questions