Usage resolution of the CHTGDIManager GDI resource management class for the VC programming control class HTControl

  • 2020-04-02 02:32:53
  • OfStack

This paper mainly introduces the usage of CHTGDIManager GDI resource management class of VC programming control class HTControl. The LoadBitmap interface of CBitmap class provided by MFC can only obtain bitmap from EXE, but in many cases it is necessary to obtain bitmap from EXE. The CHTGDIManager class provides the interface to obtain bitmap from EXE.


m_hBmpBtnCloseNormal = m_HTGDIManager.GetBitmap(_T(".\pic\btn_close_normal.png"));


#if !defined(__CHTGDIMANAGER_H__)
#define __CHTGDIMANAGER_H__
class AFX_CLASS_EXPORT CHTGDIManager
{
public:
 CHTGDIManager(void);
 ~CHTGDIManager(void);

HBITMAP GetBitmap(TCHAR* szPicPath, RECT* pRect = NULL);

HBITMAP GetBitmap(int iPicId, RECT* pRect = NULL);

HFONT GetFont(long lHeight, long lWeight, TCHAR* szFaceName, BOOL bUnderline = FALSE, BOOL bItalic = FALSE);
 void DeleteBitmap(HBITMAP hBitmap);
 void DeleteAllBitmap(HBITMAP hBitmap);
 void DeleteFont(HFONT hFont);
 void DeleteAllFont(HFONT hFont);
private:
 HBITMAP* m_hBitmap;
 HFONT* m_hFont;
 int m_iBitmapIndex;
 int m_iFontIndex;
 int m_iBitmapCount;
 int m_iFontCount;
};
#endif //!__CHTGDIMANAGER_H__

MFC provides a variety of GDI object encapsulation class, many used to WIN32 API development (SDK development) may not like to use these classes (anyway, I do not like to use, I think these classes encapsulation is not very good), but used to use API directly to create, and many cases need to directly use the handle of these GDI objects. The revocation of the GDI object, which is to be retracted when the GDI object is used, in case of resource leakage. The CHTGDIManager undoes all the GDI objects it creates during class destructions, and the consumer does not need to.


Related articles: