zoukankan      html  css  js  c++  java
  • MFC乱七八糟笔记

    1.CBitmap-------------------------------------------------------------------------------------

    1、类层次
    CObject
        CGdiObject
            CBitmap
    BOOL CGdiObject::~CGdiObject()
    {
        if (m_hObject == NULL)
      return FALSE;
     return ::DeleteObject(Detach());
    }
    从CGdiObject的析构函数中,可以看出有先Detach再Delete

    2、BOOL CBitmap::LoadBitmap(LPCTSTR lpszResourceName);
       BOOL CBitmap::LoadBitmap(UINT nIDResource);
    对应Win32 SDK中的LoadBitmap
    HBITMAP LoadBitmap(
      HINSTANCE hInstance,  // handle to application instance
      LPCTSTR lpBitmapName  // name of bitmap resource
    );
    注意:由LoadBitmap

    2.CDC-----------------------------------------------------------------------------------------------

    class CDC : public CObject
    {
    public:
     static CDC* PASCAL FromHandle(HDC hDC);
     
     // Attach与Detach函数
     BOOL Attach(HDC hDC);
     HDC Detach();
     
     // 构造与析构函数
     CDC();
     virtual ~CDC();
    }

    1、CDC的构造函数和析构函数
    CDC::CDC()
    {
     m_hDC = NULL;
    }
    CDC::~CDC()
    {
     if (m_hDC != NULL)
      ::DeleteDC(Detach());
    }
    从析构函数中可以看出,释放了关联的HDC
    并且在Delete之前还Detach了

    2、Attach用于将CDC的对象和HDC的句柄关联在一起
       Detach则相反
    BOOL CDC::Attach(HDC hDC)
    {
     if (hDC == NULL)
     {
      return FALSE;
     }

     m_hDC = hDC;
     CHandleMap* pMap = afxMapHDC(TRUE); // create map if not exist
     pMap->SetPermanent(m_hDC, this);

     return TRUE;
    }
    HDC CDC::Detach()
    {
     HDC hDC = m_hDC;
     if (hDC != NULL)
     {
      CHandleMap* pMap = afxMapHDC(); // don't create if not exist
      if (pMap != NULL)
       pMap->RemoveHandle(m_hDC);
     }
     m_hDC = NULL;
     
     return hDC;
    }

    3、FromHandle从映射表中查找有无hDC对应的CDC
       有则返回其指针;没有则先new一个临时的CDC的对象,将其和hDC关联再返回其指针
       注意:这个临时的CDC对象不用由用户delete,系统的空闲线程会处理
    CDC* PASCAL CDC::FromHandle(HDC hDC)
    {
     CHandleMap* pMap = afxMapHDC(TRUE);       //create map if not exist
     CDC* pDC = (CDC*)pMap->FromHandle(hDC);   // 如果pMap中不存在hDC关联的CDC对象,则new一CDC对象并和hDC关联
     return pDC;
    }

    3.CDialog----------------------------------------------------------------------------------

    1、CDialog析构时销毁了与之关联的窗口
    CDialog::~CDialog()
    {
     if (m_hWnd != NULL)
     {
      DestroyWindow();
     }
    }

    4.CWnd---------------------------------------------------------------------------------------

    1、CWnd析构时销毁了与之关联的窗口
    CWnd::~CWnd()
    {
     if (m_hWnd != NULL)
     {
      DestroyWindow();
     }
    }

    2、获取桌面窗口句柄
    static CWnd* PASCAL CWnd::GetDesktopWindow();
    对应Win32 SDK中的为
    HWND GetDesktopWindow(VOID);

  • 相关阅读:
    Educational Codeforces Round 83 --- F. AND Segments
    Educational Codeforces Round 83 --- G. Autocompletion
    SEERC 2019 A.Max or Min
    2019-2020 ICPC Southwestern European Regional Programming Contest(Gym 102501)
    Educational Codeforces Round 78 --- F. Cards
    今天我学习了一门全新的语言
    codeforces 1323D 题解(数学)
    Educational Codeforces Round 80 (Div. 2) 题解 1288A 1288B 1288C 1288D 1288E
    Educational Codeforces Round 81 (Div. 2) 题解 1295A 1295B 1295C 1295D 1295E 1295F
    Codeforces Round #617 (Div. 3) 题解 1296C 1296D 1296E 1296F
  • 原文地址:https://www.cnblogs.com/Hisin/p/3152944.html
Copyright © 2011-2022 走看看