getting problems in double buffering code :(
i'm trying avoiding the flickers on forms. for that i did:
Code:
case WM_ERASEBKGND:
return (LRESULT)1;
return true is the same for windows that the background was cleaned backcolor reapinted and call the WM_PAINT message.
in WM_PAINT i cread a memory DC(do a double buffer) and
add the backcolor(using the FillRect() API function(maybe i need change the Pen color too for the Brush and Pen been the same) and an image from the Paint() function and then i use BitBlt() for draw it(all in 1) on form.
Code:
case WM_PAINT:
{
if (inst->Paint==NULL) break;
PAINTSTRUCT ps;
HDC hdcimage = CreateCompatibleDC(NULL);
int width=ps.rcPaint.right-ps.rcPaint.left;
int height =ps.rcPaint.bottom-ps.rcPaint.top;
HBITMAP hbitmap=CreateCompatibleBitmap(hdcimage,width,height);
int f=width;// GetLastError();
SelectObject(hdcimage, hbitmap);
//int f= GetLastError();
FillRect(hdcimage,&ps.rcPaint,CreateSolidBrush(inst->clrBackColor));
inst->Paint(inst->hwnd,hdcimage);
HDC hdc = BeginPaint(inst->hwnd, &ps);
BitBlt(ps.hdc,0,0,ps.rcPaint.right-ps.rcPaint.left,ps.rcPaint.bottom-ps.rcPaint.top,hdcimage,0,0,SRCCOPY);
MessageBox(NULL,to_string(f).c_str(),"erro",MB_OK);
EndPaint(inst->hwnd, &ps);
DeleteObject(hbitmap);
DeleteDC(hdcimage);
}
break;
i have seen the error, but i odn't understand why :(
see the width and height arent correctly calculated or something :(
the GetLastError() give me 87: Invalid parameter :(
(the image isn't drawed)
what i'm doing wrong?