CDC* pDC=GetDC();
    CRect rect;
    GetClientRect(&rect);
    CDC  memDC;
    memDC.CreateCompatibleDC(NULL);
    CBitmap  memBitmap;
    memBitmap.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());
    memDC.SelectObject(&memBitmap);
          
    pDC->BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
   
    memBitmap.DeleteObject();
    memDC.DeleteDC();
    ReleaseDC(pDC);像上面這段代码,其中的
pDC能保存吗,比如保存为成员变量,供其他成员函数调用m_pDC=GetDC();
同理,
memBitmap  對象能保存嗎?
memDC  对象能保存吗?如果能保存,我每次重繪窗口不用重新创建memBitmap,memDC,直接貼圖就行了

解决方案 »

  1.   

    保存来做什么呢?函数结束就必须要ReleaseDC的。
      

  2.   

    看看MSDN,The GetDC function retrieves a common, class, or private DC depending on the class style of the specified window. For class and private DCs, GetDC leaves the previously assigned attributes unchanged. However, for common DCs, GetDC assigns default attributes to the DC each time it is retrieved. For example, the default font is System, which is a bitmap font. Because of this, the handle for a common DC returned by GetDC does not tell you what font, color, or brush was used when the window was drawn. Note that the handle to the DC can only be used by a single thread at any one time.After painting with a common DC, the ReleaseDC function must be called to release the DC. Class and private DCs do not have to be released. ReleaseDC must be called from the same thread that called GetDC. The number of DCs is limited only by available memory. Windows 95/98/Me: There are only 5 common DCs available per thread, thus failure to release a DC can prevent other applications from accessing one.
      

  3.   

    MSDN上有一句话:
    Identifies the device context for the CWnd client area if successful; otherwise, the return value is NULL. The pointer may be temporary and should not be stored for later use. 
      

  4.   

    那memDC和memBitmap呢,我重繪10000次(具體繪圖操作很少),發現創建memDC和memBitmap耗去了很多時間
      

  5.   

    高手的MSDN吃的很透啊,看来MSDN的重要性。
      

  6.   

    “响应鼠标移动实时画十字光标线”?应该不是改变鼠标指针的样式吧,我的思路是:首先你LButtonDown事件中记录好你的初始鼠标CPoint,接着在OnMouseMove事件中不断调用当前鼠标的位置记录在另一个CPoint之中,然后根据2个CPoint形成的矩形,截取他们的每条边的中点,来画2条线即可。由于OnMouseMove不断触发,因此所画十子不断变化。
      

  7.   

    写个结构记录 绘画的类型和节点, 重绘就可以了  1000次GDI还是能搞定的  我的是画到图上得优化一下
      

  8.   

    memDC和memBitmap是可以保存的
    但窗口大小如果有变化则要重新建立
      

  9.   

    十字线为什么要你绘制?鼠标的那个指针你交给系统即可
    你应该获得你的invalidate rectangle,然后只绘制那里面的,这样会极大地缩小你需要绘制的内容