Réponse acceptée !
Salut
Voici un exemple qui marche:
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
static HDC memHdc; static HBITMAP hBitmap;
COLORREF color;
int n;
switch (message) /* handle the messages */
{
case WM_CREATE:
memHdc=CreateCompatibleDC(NULL);
HDC H;
H=GetDC(hwnd);
hBitmap = CreateCompatibleBitmap(H,480,272);
ReleaseDC(hwnd,H);
SelectObject(memHdc, hBitmap);
color=0x000000FF; //0x00bbggrr
for (n=10;n<100;n++)
for (int i=0;i<100;i++)
SetPixel(memHdc,n,i, color);
break ;
case WM_PAINT:
PAINTSTRUCT paintst;
hdc=BeginPaint(hwnd,&paintst);
BitBlt(hdc,0,0,480,272,memHdc,0,0,SRCCOPY);
EndPaint(hwnd,&paintst);
return 0;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break ;
default : /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
Il faut creer ton HBitmap et ton memDC dans le message WM_CREATE et non pas dans le WM_PAINT. Le messaeg paint est envoyer en rafale et il est inutile de le faire a chaque fois. J'ai changer aussi ta maniere de les creer:
memHdc=CreateCompatibleDC(NULL);
HDC H;
H=GetDC(hwnd);
hBitmap = CreateCompatibleBitmap(H,480,272);
A+
Mon site internet :
[ Lien ]