error in message WM_PAINT

Oct 9, 2014 at 8:22am
i'm trying doing a double buffer in WM_PAINT message for avoid the flickers:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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;

the image isn't showed. the GetLastError() give me 87: invalid parameter.
what makes mes more strange is the width\height values :(
that math give me a negative values.. i don't know why.
can anyone explain to me what isn't right?
Oct 9, 2014 at 10:21am
BeginPaint fills in the PAINTSTRUCT, but you are using it beforehand. Use the DC from BeginPaint as the parameter for CreateCompatibleDC, else you'll have a monochrome bitmap.

The invalid parameter occurs on what line?
Oct 16, 2014 at 10:05pm
you have right.. thanks for correct me
Topic archived. No new replies allowed.