我需要完成一个程序,在SDI界面中初始化了一个图标,要实现的功能是当鼠标在该图标上单击并拖动时实现图标被拖动的效果。
听说SetROP2(R2_NOT)的设置可以帮助实现鼠标拖动的效果,于是我在mousemove事件中加入了如下的代码。(声明全局变量CPoint myPointNow,myPointOld 分别代表鼠标move时的当前点坐标和上一个点的坐标) char* pszIcon;
pszIcon=IDI_QUESTION;
CPoint linept1,linept2,linept3; CDC *pDC=GetDC();
pDC->SetBkMode(TRANSPARENT);
pDC->SetROP2(R2_NOT); myPointNow=point; pDC->DrawIcon(myPointOld,AfxGetApp()->LoadStandardIcon(pszIcon));//由于设置了SetROP2(R2_NOT)故此步重画上一个点的图标即可实现删除上一个点的图标。
pDC->DrawIcon(myPointNow,AfxGetApp()->LoadStandardIcon(pszIcon)); myPointOld=myPointNow;//下次调用move事件时坐标应更改 ReleaseDC(pDC);
现在遇到的问题是‘pDC->DrawIcon(myPointOld,AfxGetApp()->LoadStandardIcon(pszIcon));’不起作用,因此鼠标拖动时会显示许多的图标。请高手看看该怎么解决?另外,通过设置SetROP2(R2_NOT)我实现了线的拖动效果,那么图标是不是不能通过SetROP2(R2_NOT)来实现此效果呢?

解决方案 »

  1.   

    你应该先保存原图,重画原图就可以了,R2_NOT只能用在brush和pen
      

  2.   


      Platform SDK: Windows GDI 
    SetROP2
    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. The foreground mix mode defines how colors from the brush or pen and the colors in the existing image are to be combined. int SetROP2(
      HDC hdc,         // handle to DC
      int fnDrawMode   // drawing mode
    );
    Parameters
    hdc 
    [in] Handle to the device context. 
    fnDrawMode 
    [in] Specifies the mix mode. This parameter can be one of the following values. Mix mode Description 
    R2_BLACK Pixel is always 0. 
    R2_COPYPEN Pixel is the pen color. 
    R2_MASKNOTPEN Pixel is a combination of the colors common to both the screen and the inverse of the pen. 
    R2_MASKPEN Pixel is a combination of the colors common to both the pen and the screen. 
    R2_MASKPENNOT Pixel is a combination of the colors common to both the pen and the inverse of the screen. 
    R2_MERGENOTPEN Pixel is a combination of the screen color and the inverse of the pen color. 
    R2_MERGEPEN Pixel is a combination of the pen color and the screen color. 
    R2_MERGEPENNOT Pixel is a combination of the pen color and the inverse of the screen color. 
    R2_NOP Pixel remains unchanged. 
    R2_NOT Pixel is the inverse of the screen color. 
    R2_NOTCOPYPEN Pixel is the inverse of the pen color. 
    R2_NOTMASKPEN Pixel is the inverse of the R2_MASKPEN color. 
    R2_NOTMERGEPEN Pixel is the inverse of the R2_MERGEPEN color. 
    R2_NOTXORPEN Pixel is the inverse of the R2_XORPEN color. 
    R2_WHITE Pixel is always 1. 
    R2_XORPEN Pixel is a combination of the colors in the pen and in the screen, but not in both. 
    Return Values
    If the function succeeds, the return value specifies the previous mix mode.If the function fails, the return value is zero. Windows NT/2000/XP: To get extended error information, call GetLastError.Res
    Mix modes define how GDI combines source and destination colors when drawing with the current pen. The mix modes are binary raster operation codes, representing all possible Boolean functions of two variables, using the binary operations AND, OR, and XOR (exclusive OR), and the unary operation NOT. The mix mode is for raster devices only; it is not available for vector devices. Example Code
    For an example, see Using Rectangles. Requirements 
      Windows NT/2000/XP: Included in Windows NT 3.1 and later.
      Windows 95/98/Me: Included in Windows 95 and later.
      Header: Declared in Wingdi.h; include Windows.h.
      Library: Use Gdi32.lib.See Also
    Painting and Drawing Overview, Painting and Drawing Functions, GetROP2 Platform SDK Release: November 2001  What did you think of this topic?
    Let us know.  Order a Platform SDK CD Online
    (U.S/Canada)   (International)  Requirements 
      Windows NT/2000/XP: Included in Windows NT 3.1 and later.
      Windows 95/98/Me: Included in Windows 95 and later.
      Header: Declared in Wingdi.h; include Windows.h.
      Library: Use Gdi32.lib.
    See Also
    Painting and Drawing Overview, Painting and Drawing Functions, GetROP2 
      

  3.   

    看MSDN吧,对了不必都老是调用AfxGetApp()->LoadStandardIcon(pszIcon),
    可以用全局变量将ICOn资源保存,当然在此不知问题的关键