2011-04-01 10 views
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; 

Pourquoi le texte ne peut pas être affiché à la fenêtre?Pourquoi le bitblt ne peut pas fonctionner

Répondre

6

Vous devez créer et sélectionnez-BITMAP dans votre 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); 
+1

droit. Lorsque vous utilisez CreateCompatibleDC, je crois que le bitmap sélectionné dans le DC est un bitmap 1x1 1 bit qui n'est pas très utile. –

Questions connexes