Cbitmap,hbitmap,bitmap difference and relation in C + +

Source: Internet
Author: User

This article mainly introduces the C + + cbitmap,hbitmap,bitmap differences and related information, the need for friends can refer to the

Load a bit diagram, you can use LoadImage:

HANDLE LoadImage (hinstance hinst,lpctstr lpszname,uint utype,int);

LoadImage can be used to load bitmaps, icons, and cursors

Loading can specify the mapping of the load graph to the size of memory:

Cxdesired: Specifies the width, in pixels, of an 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 width.

Cydesired: Specifies the height, in pixels, of an 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 the handle to the related resource. Because the bitmap is loaded, the returned handle is HBITMAP (requires casting).

Extended Understanding Hbitmap/cbitmap/bitmap:

Hbitmap is the bitmap pointer,

MSDN: Handle to a bitmap.typedef Handle hbitmap;

CBitmap is the class that encapsulates bitmap in MFC;

MSDN:

Encapsulates (includes) a Windows graphics Device interface (GDI) bitmap and provides member functions to manipulate (operations) the BITM Ap.

Bitmap is a structural body that encapsulates some of the information bitmap. Defines the height, width, color format, and bit value of a logical bitmap.

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

The transformation of the relationship between the three:

?

1 2 3 4 5 6 7 8 9 10 11-12 Hbitmap Hbitmap;   CBitmap Bitmap;   BITMAP BM; Here are the links between the three: bitmap. Attach (HBITMAP)//CBitmap bitmap associated with Hbitmap. Getbitmap (&BM); Bitmap hbitmap= (HBITMAP) bitmap, which is associated with CBitmap. Getsafehandle ()//by CBitmap to get related hbitmap

The bitmap structure has the following form:

?

1 2 3 4 5 6 7 8 9 10 typedef 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 the attach is not detach, then the Windows object will be ruined by the C + + object when it is destroyed.

After attach, the pointer to a C + + object and the HWND of the Windows object have a mapping relationship, which acts as if you were to create a Windows object directly with a C + + 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 return a pointer, and you can cast it. GetDlgItem will look for it in the mapping list.

There are 2 kinds of mapping tables, one is permanent and one is temporary.

A Windows object created directly with a C + + object, or a mapping relationship to an object that is attach, is placed in a permanent table, otherwise a mapping is created in a temporary table.

So GetDlgItem does not recommend that you save the returned pointer because it is difficult to ensure that your Windows object's association with C + + objects is placed in a permanent table.

If the map is placed in a temporary table, it is automatically deleted at idle time.

Using Attcah is entirely to facilitate the use of MFC class member functions to manipulate Windows objects.

The above mentioned is the entire content of this article, I hope you can enjoy.

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.