1
>   case WM_PAINT:          
                      {
>               hdc = BeginPaint(hWnd, &ps);
>               // TODO: Add any drawing code here...
>               RECT rt;
>               GetClientRect(hWnd, &rt);
>               HDC myHdc = CreateCompatibleDC(hdc);
>               
>               DrawText(myHdc, szHello, strlen(szHello), &rt, DT_CENTER);
>               BitBlt(hdc,0,0,rt.right-rt.left,rt.bottom-rt.top,myHdc,0,0,SRCCOPY);
>               
>               EndPaint(hWnd, &ps);            
                        }
> 
>           break;

Why the text cannot be showed at the window?

Eugene
  • 3,335
  • 3
  • 36
  • 44
Jianzhong
  • 409
  • 1
  • 7
  • 15

1 Answers1

6

You need to create BITMAP and select it in your DC:

RECT rt;
GetClientRect(hWnd, &rt);
HDC myHdc = CreateCompatibleDC(hdc);

CBitmap bitmap = CreateCompatibleBitmap(hdc, width, height);
HBITMAP oldBitmap = ::SelectObject(myHdc, bitmap);

DrawText(myHdc, szHello, strlen(szHello), &rt, DT_CENTER);
BitBlt(hdc,0,0,rt.right-rt.left,rt.bottom-rt.top,myHdc,0,0,SRCCOPY);

::SelectObject(myHdc, oldBitmap);

EndPaint(hWnd, &ps);  
Eugene
  • 3,335
  • 3
  • 36
  • 44
  • 2
    Right. When you use CreateCompatibleDC, I believe the bitmap selected into the DC is a 1x1 1-bit bitmap which isn't very useful. – Mark Ransom Apr 01 '11 at 04:34