windows - hvorfor Bitblt ikke kan fungere

Indlæg af Hanne Mølgaard Plasc

Problem



>   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;


Hvorfor kan teksten ikke vises ved vinduet?

Bedste reference


Du skal oprette BITMAP og vælge den i din 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);