代码如下:
     // 获得窗口的客户区设备上下文句柄       
       CClientDC dc(NULL);
    //定义字体属性
       LOGFONT lf;
       lf.lfHeight = 40;     
       lf.lfWidth = 0; 
       lf.lfEscapement = 0; 
       lf.lfOrientation = 0; 
       lf.lfWeight = FW_HEAVY; 
       lf.lfItalic = FALSE; 
       lf.lfUnderline = FALSE; 
       lf.lfStrikeOut = FALSE; 
       lf.lfCharSet = GB2312_CHARSET; 
       strcpy(lf.lfFaceName,"幼圆");
//创建字体
       CFont font;
       font.CreateFontIndirect(&lf);
//更改当前字体
       CFont *pOldFont  = dc.SelectObject(&font);
//绘制字体
       dc.SetBkMode(TRANSPARENT);
       //dc.SetTextColor(::GetSysColor(COLOR_3DDKSHADOW));
       //dc.TextOut(10,10,"文字");
       //dc.SetTextColor(::GetSysColor(COLOR_3DHILIGHT)); 
       //恢复设备上下文的原有设置
       dc.SelectObject(pOldFont);

解决方案 »

  1.   

    http://search.csdn.net/Expert/topic/2004/2004165.xml?temp=.7544519
      

  2.   

    用Invalidate,会导致重绘,这样,你写的文字就不在了。
      

  3.   

    但我是在DESKTOP上写的文字:CClientDC dc(NULL);
    Invalidate我试过不行的,发送WM_PAINT,也必须有个发送对象才行啊。
    ndy_w(carpe diem) 的方法:擦?用底色重写,应该怎么抓它的底色啊?
      

  4.   

    最标准的,设置DC的绘图方式为ROP2,然后用同样的语句重写一遍。诸位,学校里的东西都忘光了啊?
      

  5.   

    擦除,也可以覆盖.
    类似:
    dc.FillRect(&rctFill, CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH)));
      

  6.   

    TextOut 写的字是不能用 设置ROP2为 R2_NOT , 然后重写就可以擦除的正确的做法是用 InvlidateRect(CRect );楼主你说 Invlidate 不行难道你的代码是写在 OnDraw 或 OnPaint 事件中
    , 如果是的话, 这只要用底色重写了dc.GetBkColor();  就是得到它的底色
    然后用 dc.Rectangle 在相应的位置画一个矩形就将它擦除了当然以上方法只适用于纯色的背景, 如果背景是一个位图, 那就又麻烦了些只能用 BitBlt 将相应位置的位图再拷贝一份
      

  7.   

    用这个吧 RedrawWindow(m_hWnd,rect,NULL,RDW_INTERNALPAINT|RDW_ERASE|RDW_UPDATENOW|RDW_INVALIDATE);
      

  8.   

    如果想局部重绘画,最好的方法就是按原来的文字轨迹以xor方式绘画一次.但是轨迹的处理比较困难,建议直接把文字写到bitmap上,然后绘图,用bitblt函数
      

  9.   

    huwei001982(編程浪子) :
        我的代码是在一个自定义消息中实现的,背景就是显示的文字五面的屏幕上所见的东西(位图),可能得用你所说的BitBlt,能不能给个简单的实例
      

  10.   

    huwei001982(編程浪子) :
        我的代码是在一个自定义消息中实现的,背景就是输出的文字下面的屏幕上所见的东西(位图),可能得用你所说的BitBlt,这个就是所说的“截屏”吧。能不能给个简单的实例
      

  11.   

    BOOL BitBlt( int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop );Return ValueNonzero if the function is successful; otherwise 0.ParametersxSpecifies the logical x-coordinate of the upper-left corner of the destination rectangle.ySpecifies the logical y-coordinate of the upper-left corner of the destination rectangle.nWidthSpecifies the width (in logical units) of the destination rectangle and source bitmap.nHeightSpecifies the height (in logical units) of the destination rectangle and source bitmap.pSrcDCPointer to a CDC object that identifies the device context from which the bitmap will be copied. It must be NULL if dwRop specifies a raster operation that does not include a source.xSrcSpecifies the logical x-coordinate of the upper-left corner of the source bitmap.ySrcSpecifies the logical y-coordinate of the upper-left corner of the source bitmap.dwRopSpecifies the raster operation to be performed. Raster-operation codes define how the GDI combines colors in output operations that involve a current brush, a possible source bitmap, and a destination bitmap. The following lists raster-operation codes for dwRop and their descriptions: BLACKNESS   Turns all output black.
    DSTINVERT   Inverts the destination bitmap.
    MERGECOPY   Combines the pattern and the source bitmap using the Boolean AND operator.
    MERGEPAINT   Combines the inverted source bitmap with the destination bitmap using the Boolean OR operator.
    NOTSRCCOPY   Copies the inverted source bitmap to the destination.
    NOTSRCERASE   Inverts the result of combining the destination and source bitmaps using the Boolean OR operator.
    PATCOPY   Copies the pattern to the destination bitmap.
    PATINVERT   Combines the destination bitmap with the pattern using the Boolean XOR operator.
    PATPAINT   Combines the inverted source bitmap with the pattern using the Boolean OR operator. Combines the result of this operation with the destination bitmap using the Boolean OR operator.
    SRCAND   Combines pixels of the destination and source bitmaps using the Boolean AND operator.
    SRCCOPY   Copies the source bitmap to the destination bitmap.
    SRCERASE   Inverts the desination bitmap and combines the result with the source bitmap using the Boolean AND operator.
    SRCINVERT   Combines pixels of the destination and source bitmaps using the Boolean XOR operator.
    SRCPAINT   Combines pixels of the destination and source bitmaps using the Boolean OR operator.
    WHITENESS   Turns all output white.
      

  12.   

    如果是在屏幕上(DeskTop)画图直接用 
    ::InvalidateRect(0, Rect, TRUE); 就行rect 即是你要擦除的区域