xuejinlong:
怎么会呢,代码是一样的,就按我说的意思,大家可以做一下,几分钟的事,马上就可见到效果
画一条线就行了。

解决方案 »

  1.   

    to emmai(WaTaXiWaWaTaXi):
      应该不是,都是类成员
      

  2.   

    CDC* dc也是成员变量?
    你是取得dc之后就记下来,
    在另一个event中再用?
    是不是?
    mfc中gdi对象有些为临时对象,
    会在OnIdle时释放,所以不能吧mfc c++对象的指针记下来,
    而是要把gdi对象的句柄记下来。
    TN003: Mapping of Windows Handles to Objects
    This note describes the MFC routines that support mapping Windows object handles to C++ objects.The ProblemWindows objects are normally represented by HANDLEs. The MFC classes wrap Windows object handles with C++ objects. The handle wrapping functions of the MFC class library provide a way to find the C++ object that is wrapping the Windows object with a particular handle. There are times when a Windows object does not have a C++ wrapper object, however, and at these times a temporary object is created to act as the C++ wrapper.The Windows objects that use handle maps are: HWND (CWnd and CWnd-derived classes)
    HDC (CDC and CDC-derived classes)
    HMENU (CMenu)
    HPEN (CGdiObject)
    HBRUSH (CGdiObject)
    HFONT (CGdiObject)
    HBITMAP (CGdiObject)
    HPALETTE (CGdiObject)
    HRGN (CGdiObject)
    HIMAGELIST (CImageList)
    SOCKET (CSocket) 
    Given a handle to any of these objects, you can find the MFC object that wraps the handle by calling the static member function FromHandle. For example, given an HWND called hWnd:CWnd::FromHandle(hWnd)will return a pointer to the CWnd that wraps the hWnd. If that hWnd does not have a specific wrapper object, then a temporary CWnd is created to wrap the hWnd. This makes it possible to get a valid C++ object from any handle.Once you have a wrapper object, you can get to its handle through a public member variable. In the case of an CWnd, m_hWnd contains the HWND for that object.Attaching Handles to MFC ObjectsGiven a newly created handle-wrapper object and a handle to a Windows object, you can associate the two by calling Attach. For example:CWnd myWnd;
    myWnd.Attach(hWnd);This makes an entry in the permanent map associating myWnd and hWnd. Calling CWnd::FromHandle(hWnd) will now return a pointer to myWnd. When myWnd is deleted, the destructor will automatically destroy the hWnd by calling the Windows DestroyWindow function. If this is not desired, the hWnd must be detached from myWnd before the myWnd object is destroyed (normally when leaving the scope at which myWnd was defined). The Detach member function does this.myWnd.Detach();More About Temporary ObjectsTemporary objects are created whenever FromHandle is given a handle that does not already have a wrapper object. These temporary objects are detached from their handle and deleted by the DeleteTempMap functions. The default OnIdle processing in CWinThread automatically calls DeleteTempMap for each class that supports temporary handle maps. This means that you cannot assume a pointer to a temporary object will be valid past the point of exit from the function where the pointer was obtained, as the temporary object will be deleted during the Windows message-loop idle time.Wrapper Objects and Multiple ThreadsBoth temporary and permanent objects are maintained on a per-thread basis. That is, one thread cannot access another threads C++ wrapper objects, regardless of whether it is temporary or permanent. As stated above, temporary objects are deleted when the thread which that temporary object belongs enters OnIdle.To pass these objects from one thread to another, always send them as their native HANDLE type. Passing a C++ wrapper object from one thread to another will often result in unexpected results.Technical Notes by Number |  Technical Notes by Category
    --------------------------------------------------------------------------------
      

  3.   

    内存DC并不保持持续的。 在你的HBITMAP 句柄或者是CBITMAP 对象没有删除或者改变是,写到内存DC上也就是画在位图上的图象是不会丢掉的。你可以先释放原来的内存DC,在构造一个,只要不改变HBITMAP句柄或者CBITMAP 对象。
      

  4.   

    参见上面的
    More About Temporary Objects
      

  5.   

    你在document-view的工程中,画完后,Invalidate(), UpdateWindow()一下试试.
      

  6.   

    敬请关注 
    专家门诊/扩充话题/软件市场/
    “中国人只能做MIS软件吗?有兴趣合作“通用软件“吗?开发模式可以学习Linux”(ShipDrink)内核已经写好,非常干净,原码公开

    70000行,其中50000行为手写,核心代码30000行
    (无注释)目前版本是1.5,经历了1.0,1.1,1.2,1.4等
    版本,其中1.1和1.5版本都曾作了极大改进,变化
    较大结构更加紧凑,编码更加合理,使用了部分
    COM原理但又不是COM,编译完,1.4版本为1.9M,
    1.5为900K,这从一个侧面反映了布局和编码的合理性。注:请对比一下
      Acrobat (正版2000元,我用得是正版)安装完为140M,
                但其核心代码为4.9M,
        Delphi6 (正版)安装完为600M,但其核心代码也仅为几兆,
      且编译程序中还包括大量资源(如位图,图标,对话框等)。),
    如果你你有开发热情,可以索要帮助文档,
    你可以为它升级。但你不会赚钱。
    因为赚钱的不是内核部分,