蛋疼的SetROP2函数,该怎么解决

蛋疼的SetROP2函数
C/C++ code

void DrawBoxOutline(HWND hwnd,POINT ptBeg,POINT ptEnd)
{
    HDC hdc;
    hdc=GetDC(hwnd);

    SetROP2(hdc,R2_NOT);
    SelectObject(hdc,GetStockObject(NULL_BRUSH));
    Rectangle(hdc,ptBeg.x,ptBeg.y,ptEnd.x,ptEnd.y);
    
    ReleaseDC(hwnd,hdc);
}

//窗口过程
case WM_LBUTTONDOWN:
    fBlocking=TRUE;
    ptBeg.x=ptEnd.x=LOWORD(lParam);
    ptBeg.y=ptEnd.y=HIWORD(lParam);
    DrawBoxOutline(hwnd,ptBeg,ptEnd);
    return 0;

case WM_MOUSEMOVE:
    if (fBlocking)
    {    
        DrawBoxOutline(hwnd,ptBeg,ptEnd);
        ptEnd.x=LOWORD(lParam);
        ptEnd.y=HIWORD(lParam);
        DrawBoxOutline(hwnd,ptBeg,ptEnd);
    }
    return 0;

case WM_LBUTTONUP:
    if (fBlocking)
    {
        fBlocking=FALSE;
        DrawBoxOutline(hwnd,ptBeg,ptEnd);
        InvalidateRect(hwnd,NULL,TRUE);
    }

    return 0;

case WM_PAINT:
    hdc=BeginPaint(hwnd,&ps);
    DrawBoxOutline(hwnd,ptBeg,ptEnd);
    EndPaint(hwnd,&ps);
    return 0;



有两个问题想问问大家:
1、SetROP2函数是将画笔颜色设置为背景色的反色,WM_MOUSEMOVE中第一个DrawBoxOutline好像是用白色将刚刚画的黑色矩形重画一遍,以达到擦去效果。我想问大家,DrawBoxOutline中的SetROP2是静态的?为什么上次反转后为黑色,第二次反转就为白色?
2、这个程序很奇怪,如果画矩形后快速松开鼠标,屏幕上显示一个矩形。但是当我画完鼠标不松停留一段时间再松开鼠标,屏幕上无显示了!!
3、调试时我在WM_MOUSEMOVE那设了一个断点,当然其他地方也有断点,但是调试时总是在WM_MOUSEMOVE那循环,而且窗口一闪就不见了,不知为何??


各位大哥,小弟刚学windows程序设计,请大家指点一下!!!
不胜感激!!!

------解决方案--------------------
试试:
C/C++ code

void DrawBoxOutline(HWND hwnd,POINT ptBeg,POINT ptEnd)
{
    HDC hdc;
    RECT rc;
    hdc=GetDC(hwnd);

    SetROP2(hdc,R2_NOTXORPEN);//R2_NOT);
    SelectObject(hdc,GetStockObject(NULL_BRUSH));
    SetRect(&rc,ptBeg.x,ptBeg.y,ptEnd.x,ptEnd.y);
    Rectangle(hdc,ptBeg.x,ptBeg.y,ptEnd.x,ptEnd.y);
    ReleaseDC(hwnd,hdc);
}
//
WNDPROC BToldProc;
BOOL fBlocking=FALSE;
POINT ptBeg={0},ptEnd={0};
LRESULT CALLBACK BTProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
//    HDC hdc;
    switch(Msg)
    {//
    case WM_LBUTTONDOWN:
        fBlocking=TRUE;
        ptBeg.x=ptEnd.x=LOWORD(lParam);
        ptBeg.y=ptEnd.y=HIWORD(lParam);
        DrawBoxOutline(hWnd,ptBeg,ptEnd);
        return 0;

    case WM_MOUSEMOVE:
        if (fBlocking)
        {    
            DrawBoxOutline(hWnd,ptBeg,ptEnd);
            ptEnd.x=LOWORD(lParam);
            ptEnd.y=HIWORD(lParam);
            DrawBoxOutline(hWnd,ptBeg,ptEnd);
        }
        return 0;
    case WM_LBUTTONUP:
        if (fBlocking)
        {
            fBlocking=FALSE;
            DrawBoxOutline(hWnd,ptBeg,ptEnd);
            //InvalidateRect(hWnd,NULL,TRUE);
        }
        return 0;
//    case WM_PAINT:
//        hdc=BeginPaint(hWnd,&ps);
//        DrawBoxOutline(hWnd,ptBeg,ptEnd);
//        EndPaint(hwnd,&ps);
//        return 0;
    }
//
    return CallWindowProc(BToldProc, hWnd, Msg, wParam, lParam);
}