Display BMP dynamically on the Dlog interface

Source: Internet
Author: User
Tags bmp image

1. Select BMP image file by clicking the interface browse button.

Click the Browse button to open the File dialog box to select the BMP image file and get the path directory where the file is located. The key code is as follows:

 
   
  
  1. void Showbmpdlg::onbuttonselectiamge ()
  2. Char
  3. Strpathname = dlg. GetPathName ();
  4. Loadshowbmpfile (Strpathname);
  5. M_hbitmap = Buffertohbitmap ();

2. Loading BMP files into memory
By getting the BMP image file path directory, the BMP image file is loaded into memory. The key code is as follows:

 
   
  
  1. DWORD

3. Convert the contents of BMP files in memory to Hbitmap
Converts the contents of a BMP file in memory into a bitmap handle. The key code is as follows:

  
 
  1. Hbitmap Showbmpdlg::buffertohbitmap ()
  2. {
  3. Hbitmap hshowbmp;
  4. LPSTR hdib,lpbuffer = M_pbmpbuffer;
  5. LPVOID lpdibbits;
  6. Bitmapfileheader Bmfheader;
  7. DWORD Bmfheaderlen;
  8. Bmfheaderlen = sizeof (Bmfheader);
  9. strncpy ((LPSTR) &bmfheader, (LPSTR) lpbuffer,bmfheaderlen);
  10. if (Bmfheader.bftype! = (* (word*) "BM")) return NULL;
  11. Hdib = lpbuffer + Bmfheaderlen;
  12. Bitmapinfoheader &bmiheader = * (Lpbitmapinfoheader) Hdib;
  13. Bitmapinfo &bminfo = * (lpbitmapinfo) Hdib;
  14. M_BMW = Bmiheader.biwidth;
  15. M_BMH = Bmiheader.biheight;
  16. Lpdibbits= (lpbuffer) + ((Bitmapfileheader *) lpbuffer)->bfoffbits;
  17. CCLIENTDC DC (this);
  18. Hshowbmp = CreateDIBitmap (Dc.m_hdc,&bmiheader,cbm_init,lpdibbits,
  19. &bminfo,dib_rgb_colors);
  20. return hshowbmp;
  21. }

4. Displaying BMP images on the screen
Double buffering enables BMP bitmaps to be displayed on the screen. The key code is as follows:

 
   
  
  1. GetClientRect (&rect);

This method is a method that we often use to draw on the interface.

Display BMP dynamically on the Dlog interface

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.