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:
- void Showbmpdlg::onbuttonselectiamge ()
- Char
-
-
-
- Strpathname = dlg. GetPathName ();
- Loadshowbmpfile (Strpathname);
- 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:
-
-
-
- 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:
- Hbitmap Showbmpdlg::buffertohbitmap ()
- {
- Hbitmap hshowbmp;
- LPSTR hdib,lpbuffer = M_pbmpbuffer;
- LPVOID lpdibbits;
- Bitmapfileheader Bmfheader;
- DWORD Bmfheaderlen;
-
- Bmfheaderlen = sizeof (Bmfheader);
- strncpy ((LPSTR) &bmfheader, (LPSTR) lpbuffer,bmfheaderlen);
- if (Bmfheader.bftype! = (* (word*) "BM")) return NULL;
- Hdib = lpbuffer + Bmfheaderlen;
- Bitmapinfoheader &bmiheader = * (Lpbitmapinfoheader) Hdib;
- Bitmapinfo &bminfo = * (lpbitmapinfo) Hdib;
- M_BMW = Bmiheader.biwidth;
- M_BMH = Bmiheader.biheight;
- Lpdibbits= (lpbuffer) + ((Bitmapfileheader *) lpbuffer)->bfoffbits;
- CCLIENTDC DC (this);
- Hshowbmp = CreateDIBitmap (Dc.m_hdc,&bmiheader,cbm_init,lpdibbits,
- &bminfo,dib_rgb_colors);
- return hshowbmp;
- }
4. Displaying BMP images on the screen
Double buffering enables BMP bitmaps to be displayed on the screen. The key code is as follows:
-
-
-
-
-
-
-
-
- GetClientRect (&rect);
-
-
This method is a method that we often use to draw on the interface.
Display BMP dynamically on the Dlog interface