void DrawBoxOutline (HWND hwnd, POINT ptBeg, POINT ptEnd)
{
     HDC hdc ;
     
     hdc = GetDC (hwnd) ;
     SelectObject(hdc,GetStockObject(BLACK_PEN));
     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 :
          ptBeg.x = ptEnd.x = LOWORD (lParam) ;
          ptBeg.y = ptEnd.y = HIWORD (lParam) ;
          
          DrawBoxOutline (hwnd, ptBeg, ptEnd) ;
          
          SetCursor (LoadCursor (NULL, IDC_CROSS)) ;
          
          fBlocking = TRUE ;
          return 0 ;
          
     case WM_MOUSEMOVE :
          if (fBlocking)
          {
               SetCursor (LoadCursor (NULL, IDC_CROSS)) ;
               
               DrawBoxOutline (hwnd, ptBeg, ptEnd) ;
               
               ptEnd.x = LOWORD (lParam) ;
               ptEnd.y = HIWORD (lParam) ;
               
               DrawBoxOutline (hwnd, ptBeg, ptEnd) ;
          }
          return 0 ;
          
     case WM_LBUTTONUP :
          if (fBlocking)
          {
               DrawBoxOutline (hwnd, ptBeg, ptEnd) ;
               
               ptBoxBeg   = ptBeg ;
               ptBoxEnd.x = LOWORD (lParam) ;
               ptBoxEnd.y = HIWORD (lParam) ;
               
               SetCursor (LoadCursor (NULL, IDC_ARROW)) ;
               
               fBlocking = FALSE ;
               fValidBox  = TRUE ;
               
               InvalidateRect (hwnd, NULL, TRUE) ;
          }
          return 0 ;
如果去掉case WM_MOUSEMOVE 里的第一个
            DrawBoxOutline (hwnd, ptBeg, ptEnd) ;
会产生什么效果???(我试过了)请问这句的作用是什么?为什么???

解决方案 »

  1.   

    这个函数应该是自定义的吧,msdn上找不到,
    可能是画边框
      

  2.   

    楼上的.这个不是已经写出来了么.呵呵.MSDN上当然没有了.void DrawBoxOutline (HWND hwnd, POINT ptBeg, POINT ptEnd)
    {
         HDC hdc ;
         
         hdc = GetDC (hwnd) ;
         SelectObject(hdc,GetStockObject(BLACK_PEN));
         SetROP2 (hdc, R2_NOT) ;
         SelectObject (hdc, GetStockObject (NULL_BRUSH)) ;
         Rectangle (hdc, ptBeg.x, ptBeg.y, ptEnd.x, ptEnd.y) ;
         
         ReleaseDC (hwnd, hdc) ;
    }
      

  3.   

    你这是windows程序设计中的那个橡皮筋效果画图程序,第一个DrawBoxOutline 是清除以前画的橡皮筋线,而第二个DrawBoxOutline 是画一条新的线
      

  4.   

    异或操作,a异或b在异或b还是a.DrawBoxOutline执行的图形异或操作,所以连画两次就相当于清除。
      

  5.   

    SetROP2 (hdc, R2_NOT) ;The SetROP2 function sets the current foreground mix mode. GDI uses the foreground mix mode to combine pens and interiors of filled objects with the colors already on the screen.R2_NOT:Pixel is the inverse of the screen color.
    我觉得这一点书上说得比较清楚,另外,要注意请教MSDN
      

  6.   

    SetROP2 (hdc, R2_NOT) 
    书上没有说啊。怎么用的?
      

  7.   

    主要是异或操作的概念A异或B就是当A和B相等时结果为0,一个为1一个为0时结果为1
      

  8.   

    MSDN上面有吗,干嘛不去看!!!!