cookie
cookie

Reputation: 73

The GDI text display problem (I just use GDI and not use Unity or DirectX)

I am writing a program game and want to show a text on the game's beginning.

I have checked the syntax of the program to guarantee there is no problem.

But the text can't display on the window.

I declare two global variables HDC:

   HDC g_hdc, g_mdc;

The first is used to display, the second is used to buffer.

The text display code:

   HFONT hFont = CreateFont(45, 0, 0, 0, 0, 0, 0, 0, GB2312_CHARSET, 0, 0, 0, 0, NULL);
   SelectObject(g_hdc, hFont);
   SetBkMode(g_hdc, TRANSPARENT);
   wchar_t text1[] = L"Begin!";
   SetTextColor(g_hdc, RGB(50, 255, 50));
   TextOut(g_hdc, 0, 0, text1, wcslen(text1));

This code is included in the function init() so the code will be used when the windows create and just use only once.

When I run this program I just got this : image

You can see the bitmap show correct but the text is not. Can anyone tell me why?

Upvotes: 0

Views: 119

Answers (1)

cookie
cookie

Reputation: 73

I find why it can't display. I change the way of get HDC form PaintBegin() to GetDC() then the text begin to display. The PaintBegin() looks like only using when WM_PAINT message be caught.

Upvotes: 1

Related Questions