error in message WM_PAINT

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?
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?
you have right.. thanks for correct me
Registered users can post here. Sign in or register to post.