Salut,
Voici un exemple qui pourrait te servir:
Au début de ta WndProc tu déclares ceci:
static HDC memDC ;
static HBITMAP hBmp;
static RECT rect;
A la fin du traitement de WM_CREATE tu ajoutes:
HDC hdc;
hdc = GetDC(hwnd);
memDC = CreateCompatibleDC(hdc);
GetClientRect(hwnd,&rect);
hBmp = CreateCompatibleBitmap(hdc, rect.right, rect.bottom);
SelectObject(memDC, hBmp);
ReleaseDC(hwnd,hdc);
Pour le traitement de WM_PAINT tu fais:
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
BitBlt(hdc,0,0,rect.right,rect.bottom,memDC,0,0,SRCCOPY);
EndPaint(hwnd, &ps);
return 1;
}
Juste avant la fermeture du programme du fais:
DeleteObject(hBmp);
DeleteDC(memDC);
Dand cet exemple, on dessine dans un HBITMAP en mémoire. Il y reste tant qu'on ne l'a pas supprimé. La fonction BitBlt() l'affiche sur la fenêtre pendant WM_PAINT. Si tu veux l'afficher juste après avoir dessiné tu fais par exemple:
Rectangle(memDC,10,10,50,30);
InvalidateRect(hwnd,&rect);
J'espère que ça résoudra ton problème.