This paper mainly introduces the VC programmable control parts Class Htcontrol Chtgdimanager GDI resource Management Class Usage, MFC provides the CBitmap class LoadBitmap interface can only obtain the bitmap from the exe inside, but in many cases need to obtain from the EXE outside, The Chtgdimanager class provides an interface for obtaining bitmaps from outside the EXE, using the following methods:
M_hbmpbtnclosenormal = M_htgdimanager.getbitmap (_t (". \\pic\\btn_close_normal.png"));
#if!defined (__chtgdimanager_h__) #define __CHTGDIMANAGER_H__ class Afx_class_export Chtgdimanager {Public:chtgdimana
Ger (void);
~chtgdimanager (void); /****************************************************************************
| function function: Get bitmap from File | | Input Parameters: | | Szpicpath: Picture file path | | Prect: Take a part of the picture null means to take the whole picture | | Output parameters: none | | Return value: Successfully returned bitmap handle failed return Null | |
Description: This type of destructor deletes this bitmap, and the user does not have to delete | /Hbitmap Getbitmap (tchar* Szpicpath,
rect* prect = NULL); /****************************************************************************
| function function: Get bitmap from resources | | Input Parameters: | | IPICID: Resource ID | | Prect: Take a part of the picture null means to take the whole picture | | Output parameters: none | | Return value: Successfully returned bitmap handle failed return null |
|
Description: This type of destructor deletes this bitmap, and the user does not have to delete | /hbitmap getbitmap (int ipicid, rect*
Prect = NULL); /****************************************************************************
| function function: Get the specified font | | Input Parameters: | | Lheight: Font Size | | Lweight: Coarse Degree | | Szfacename: Font name | | Bunderline: Whether with bottom horizontal line | | Bitalic: Italic | | Output parameters: none | | Return value: Successful return of font handle failed return Null | |
Description: This type of destructor deletes this font, the user does not have to delete | /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 encapsulation classes for a variety of GDI objects, and many custom WIN32 APIs developed (SDK development) may not like to use these classes (anyway, I don't like to use them, personally think these classes are not very good encapsulation), but rather used to use the API directly to create, In many cases, you will need to use the handles of these GDI objects directly. The revocation of the GDI object, which is undone when the GDI object is used to prevent resource leaks. Chtgdimanager revokes all GDI objects created by the class destructor, and the user does not need to undo it.