C ++ CBitmap, HBitmap, Bitmap differences and connections, cbitmaphbitmap

Source: Internet
Author: User

C ++ CBitmap, HBitmap, Bitmap differences and connections, cbitmaphbitmap

To load a bitmap, you can use LoadImage:

HANDLE LoadImage(HINSTANCE hinst,LPCTSTR lpszName,UINT uType,int cxDesired,int CyDesired,UINT fuLoad);

LoadImage can be used to load bitmap, icon, and cursor

You can specify the size of the map to the memory when loading the graph:

CxDesired: Specify the width of the icon or cursor, in pixels. If this parameter is zero and LR_DEFAULTSIZE in the fuLoad value is not used, the function uses the current resource width.

CyDesired: Specify the height of the icon or cursor, in pixels. If this parameter is zero and LR_DEFAULTSIZE in the fuLoad value is not used, the function uses the current resource height.

The returned value of LoadImage is related to the resource.Handle. Because bitmap is loaded, the returned handle is HBITMAP (mandatory conversion is required ).

Extended understanding of HBITMAP/CBitmap/BITMAP:

HBITMAPIs a bitmap pointer,

In msdn, Handle to a bitmap. typedef handle hbitmap;

CBitmapIs the class that encapsulates bitmap in mfc;

In msdn:

Encapsulates (included) a Windows graphics device interface (GDI) bitmap and provides member functions to manipulate (operation) the bitmap.

BITMAPIs a struct that encapsulates bitmap information. Defines the height, width, color format, and bit value of the logical bitmap.

In MSDN, This structure defines the type, width, height, color format, and bit values of a bitmap.

Relationship conversion between the three:

HBITMAP hBitmap; CBitmap bitmap; BITMAP bm; // The following is the relationship between the three: bitmap. attach (hBitmap); // The CBitmapbitmap associated with HBITMAP. getBitmap (& bm); // obtain the associated BITMAP hBitmap = (HBITMAP) bitmap from CBitmap. getSafeHandle (); // get the relevant HBITMAP from CBitmap
The BITMAP structure has the following forms:
Typedef struct tagBITMAP {int bmType; int bmWidth; // wide int bmHeight; // high int bmWidthBytes; BYTE bmPlanes; BYTE bmBitsPixel; LPVOID bmBits;} BITMAP;

For more information, see Attach/Detach:

Attach associates a C ++ object with a WINDOWS Object until detach is used.
If there is no detach after attach, the WINDOWS object will be finished together when the C ++ object is destroyed.
After attach, the pointer of the C ++ object has a ing relationship with the HWND of the WINDOWS object, which is equivalent to directly using a C ++ object to Create a WINDOWS Object, for example, CEdit edit; edit. create (...)
And the ing is permanent, so it is known that the object is finished.
If you use a function similar to GetDlgItem, you can also return a pointer and perform forced conversion. GetDlgItem will be found in the ing table.
There are two types of ing tables. One is permanent and the other is temporary.
WINDOWS objects created directly using C ++ objects or the atting relationships of attach objects are stored in permanent tables. Otherwise, a ing is created in temporary tables.
Therefore, GetDlgItem does not recommend that you save the returned pointer, because it is difficult to ensure that the association between your WINDOWS object and the C ++ object is in a permanent table.
If the ing is in a temporary table, it is automatically deleted during idle time.
Attcah is used to facilitate the use of MFC class member functions to manipulate WINDOWS objects.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.