To load a map, you can use LoadImage:
HANDLE LoadImage (hinstance hinst,lpctstr lpszname,uint utype,int cxdesired,int cydesired,uint Fuload);
LoadImage can be used to load bitmaps, icons and cursors
You can specify the size of the load map to memory when loading:
Cxdesired: Specifies the width of the icon or cursor, in pixels. If this parameter is zero and lr_defaultsize is not used in the parameter Fuload value, then the function uses the current resource width.
Cydesired: Specifies the height, in pixels, of the icon or cursor. If this parameter is zero and lr_defaultsize is not used in the parameter Fuload value, then the function uses the current resource height.
The return value of the LoadImage is a handle to the related resource . Because the bitmap is loaded, the returned handle is of type HBITMAP (cast required).
Extended Understanding Hbitmap/cbitmap/bitmap:
hbitmap is a pointer to bitmap,
MSDN in this case: Handle to a bitmap.typedef Handle hbitmap;
CBitmap is the class of encapsulated bitmap in MFC;
In MSDN:
Encapsulates (includes) a Windows graphics Device interface (GDI) bitmap and provides member functions to manipulate (operation) the BITM Ap.
BITMAP is a structure that encapsulates some of the information of the BITMAP. Defines the height, width, color format, and bit values of a logical bitmap.
MSDN as: This structure defines the type, width, height, color format, and bit values of a bitmap.
The relationship between the three transitions:
Hbitmap hbitmap; CBitmap bitmap; BITMAP BM; // here are the links between the three: bitmap. Attach (HBITMAP); // CBitmap that are associated by Hbitmap bitmap. Getbitmap (//hbitmap= (hbitmap) bitmap. Getsafehandle (); // get the relevant hbitmap by CBitmap
The bitmap structure has the following form:
struct tagbitmap{ int bmtype; int Bmwidth; // wide int Bmheight; // High int bmwidthbytes; BYTE Bmplanes; BYTE Bmbitspixel; LPVOID bmbits;} BITMAP;
Extended understanding under Attach/detach:
Attach is to associate a C + + object with a Windows object until the association is removed with detach.
If attach is not detach, the Windows object will be destroyed when the C + + object destroys.
Attach, the pointer to the C + + object and the HWND of the Windows object have a mapping relationship, which is equivalent to using a C + + object to create a Windows object, such as CEdit edit; Edit.create (...)
And this mapping is permanent, knowing that this object is finished.
If you use a similar GetDlgItem function, you can also return a pointer and cast it. GetDlgItem will look in the mapping table.
There are 2 kinds of mapping tables, one is permanent, one is temporary.
A Windows object created directly with a C + + object, or a mapping of objects through attach, is placed in a permanent table, otherwise a mapping is created in the staging table.
So GetDlgItem does not recommend that you save the returned pointer because it is difficult to ensure that your Windows object is associated with a C + + object in a permanent table.
If the mapping is placed in a temporary table, it is automatically deleted at idle time.
Using Attcah is purely for the convenience of using the MFC class's member functions to manipulate Windows objects.
C + + Cbitmap,hbitmap,bitmap differences and links