CBitmap bmNew = NULL;
..
bmNew.CreateCompatibleBitmap( ..
覺得很奇怪。所以看一下 CBitmap 的 implement (在 atlgdi.h),, 有這一段:
    CBitmapT<t_bManaged>& operator =(HBITMAP hBitmap)
    {
        Attach(hBitmap);
        return *this;
    }
    void Attach(HBITMAP hBitmap)
    {
        if(t_bManaged && m_hBitmap != NULL&& m_hBitmap != hBitmap)
            ::DeleteObject(m_hBitmap);
        m_hBitmap = hBitmap;
    }
    HBITMAP Detach()
    {
        HBITMAP hBitmap = m_hBitmap;
        m_hBitmap = NULL;
        return hBitmap;
    }
所以是 CBitmap overwrite 了 operator "="
配合 attach, detach 來看,這有點像 smart_ptr 的作法。... 雖然他是handle wrapper,不是 pointer wrapper..
typedef CBitmapTCBitmap; 
true 代表 memory management 由 class 自己 handle。
所以那個 CBitmap bmNew = NULL 代表將 bmNew 的 member m_hBitmap 設為 NULL。
這應該只是為了好看吧..否則寫兩行也可以呀:
CBitmap bmNew;
bmNew.m_hBitmap = NULL;
沒有留言:
張貼留言