如果想用鼠标拉出来一个矩形框 
并且该矩形框画好后
能够用鼠标随意改变其大小和移动它到任意位置
请问如何实现阿?
最好能给我原码 万分感谢
回答后立刻节帖给分

解决方案 »

  1.   

    void CPictureActiveCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: この位置にメッセージ ハンドラ用のコードを追加するかまたはデフォルトの処理を呼び出してください
    StartPoint=point;
    mousedown=TRUE;
    CClientDC ddc(this);
    // OnDraw(&ddc,&Clientrect,NULL);
    OnResetState();
    if(DectrionMove)
    {

    bPointmouse=TRUE;
    oldselRect=CRect(0,0,0,0);
    ddc.LPtoDP(oldselRect);
    DrawRect.NormalizeRect();
    oldselRect.NormalizeRect();
    ddc.DrawDragRect(DrawRect,sz,oldselRect,sz ,&Drawbrush,NULL);
    oldselRect=DrawRect;
    bDrawed=TRUE;


    }
    else
    {
    bDrawed=FALSE;
    bPointmouse=FALSE;
    DectrionMove=FALSE; }


    COleControl::OnLButtonDown(nFlags, point);
    }void CPictureActiveCtrl::OnLButtonUp(UINT nFlags, CPoint point) 
    {
    mousedown=FALSE;
    bPointmouse=FALSE;
    DectrionMove=FALSE;
    EndPoint=point;
    CClientDC ddc(this);
    /* CDC MemDC;
    MemDC.CreateCompatibleDC(&ddc);  
    MemDC.SelectObject(bitmap);
    long clr1=RGB(255,255,255);
    long color=MemDC.GetPixel(point.x ,point.y);
    xPil=point.x;
    ypil=point.y;
    MemDC.DeleteDC();*/
    // Scanpicture(color); SelRect.left=StartPoint.x;
    SelRect.top=StartPoint.y;
    SelRect.right=EndPoint.x;
    SelRect.bottom=EndPoint.y;

    if(!bDrawed)
    {
    oldselRect=CRect(0,0,0,0);
    ddc.LPtoDP(oldselRect);
    SelRect.NormalizeRect();
    oldselRect.NormalizeRect();

    ddc.DrawDragRect(SelRect,sz,oldselRect,sz ,&Drawbrush,NULL);
    oldselRect=SelRect;
    bDrawed=TRUE;
    DrawRect=SelRect;
    }
    DrawDragPoint(&ddc,DrawRect);
    COleControl::OnLButtonUp(nFlags, point);
    }void CPictureActiveCtrl::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: この位置にメッセージ ハンドラ用のコードを追加するかまたはデフォルトの処理を呼び出してください
    CPoint testPoint;
    testPoint.x=point.x;
    testPoint.y=point.y;
    if(!mousedown)
    {
    if(rect[1].PtInRect(testPoint))
    {
    dectrion=LEFTTOP;DectrionMove=1;
    ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENWSE   ));
    }
    else if(rect[2].PtInRect(testPoint))
    {
    dectrion=UP;DectrionMove=1;
    ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS   ));
    }
    else if(rect[3].PtInRect(testPoint))
    {
    dectrion=RIGHTTOP;DectrionMove=1;
    ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENESW      ));
    }
    else if(rect[4].PtInRect(testPoint))
    {
    dectrion=RIGHT;DectrionMove=1;
    ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE      ));
    }
    else if(rect[5].PtInRect(testPoint))
    {
    dectrion=RIGHTB0TTOM;DectrionMove=1;
    ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENWSE   ));
    }
    else if(rect[6].PtInRect(testPoint))
    {
    dectrion=DOWN;DectrionMove=1;
    ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS   ));
    }
    else if(rect[7].PtInRect(testPoint))
    {
    dectrion=LEFTBOTTOM;DectrionMove=1;
    ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENESW      ));
    }
    else if(rect[8].PtInRect(testPoint))
    {
    dectrion=LEFT;DectrionMove=1;
    ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE       ));
    }
    else
    DectrionMove=0;
    }
    if(bDrawed && bPointmouse)
    {

    if(DectrionMove)
    {
    switch(dectrion)
    {
    case 1:
    DrawRect.top=point.y; DrawRect.left=point.x;
    break;
    case 2:
    //DrawRect=rectTemp;
    DrawRect.top=point.y;  break;
    case 3:
    //DrawRect=rectTemp;
    DrawRect.right=point.x;DrawRect.top=point.y;  break;
    case 4:
    //DrawRect=rectTemp;
    DrawRect.right=point.x; break;
    case 5:
    //DrawRect=rectTemp;
    DrawRect.bottom=point.y;DrawRect.right=point.x; break;
    case 6:
    //DrawRect=rectTemp;
    DrawRect.bottom=point.y; break;
    case 7:
    //DrawRect=rectTemp;
    DrawRect.left=point.x; DrawRect.bottom=point.y;  break;
    case 8:
    //DrawRect=rectTemp;
    DrawRect.left=point.x; break;
    default:

    break;
    }
    }
    else
    {
    DectrionMove=0;
    holdCursor=::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
    DrawRect.bottom=point.y;
    DrawRect.right=point.x;
    }
    CClientDC ddc(this);
    ddc.LPtoDP(oldselRect);
    DrawRect.NormalizeRect();
    oldselRect.NormalizeRect();
    ddc.DrawDragRect(DrawRect,sz,oldselRect,sz ,&Drawbrush,NULL);
    oldselRect=DrawRect;
    }
    COleControl::OnMouseMove(nFlags, point);
    }BOOL CPictureActiveCtrl::DrawDragPoint(CDC *cdc, CRect rectBox)
    {
    CBrush brush;
    brush.CreateSolidBrush(RGB(255,0,0));
    rect[1]=GetRect(rectBox.left,rectBox.top);
    rect[2]=GetRect((rectBox.left+rectBox.right)/2,rectBox.top);
    rect[3]=GetRect(rectBox.right,rectBox.top); rect[4]=GetRect(rectBox.right,(rectBox.top+rectBox.bottom)/2);
    rect[5]=GetRect(rectBox.right,rectBox.bottom); rect[6]=GetRect((rectBox.left+rectBox.right)/2,rectBox.bottom);
    rect[7]=GetRect(rectBox.left,rectBox.bottom);
    rect[8]=GetRect(rectBox.left,(rectBox.top+rectBox.bottom)/2);

    for(int i=1;i<9;i++)
    {
    cdc->FillRect(rect[i],&brush);
    // MetaFileDC->FillRect(rect[i],&brush);
    cdc->UpdateColors();
    // MetaFileDC->UpdateColors();

    }
    return true;
    }CRect CPictureActiveCtrl::GetRect(long x, long y)
    {
    CRect rect1;
    rect1.bottom=y+2;  rect1.top=y-2;
    rect1.left=x-2;    rect1.right=x+2;
    return rect1;
    }