Set JPG The image is shown in Dialog Box Background:
Display JPG Image Functions
Void cmydlg: showpicture (CDC * PDC, cstring m_strbroute, int X, int y, int width, int height)
{
Handle hfile = createfile (m_strbroute, generic_read, 0, null, open_existing, 0, null );
_ Asserte (invalid_handle_value! = Hfile );
// Obtain the file size
DWORD dwfilesize = getfilesize (hfile, null );
_ Asserte (-1! = Dwfilesize );
Lpvoid pvdata = NULL;
// Allocate memory based on the file size
Hglobal = globalalloc (gmem_moveable, dwfilesize );
_ Asserte (null! = Hglobal );
Pvdata = globallock (hglobal );
_ Asserte (null! = Pvdata );
DWORD dwbytesread = 0;
// Read the file and save it to the global memory
Bool bread = readfile (hfile, pvdata, dwfilesize, & dwbytesread, null );
_ Asserte (false! = Bread );
Globalunlock (hglobal );
Closehandle (hfile );
Lpstream PSTM = NULL;
// Create an istream * pointer through global memory
Hresult hR = createstreamonhglobal (hglobal, true, & PSTM );
_ Asserte (succeeded (HR) & PSTM );
// Create an ipicture object through a Graphic File
If (gppicture)
Gppicture-> release ();
HR = oleloadpicture (PSTM, dwfilesize, false, iid_ipicture, (lpvoid *) & gppicture );
_ Asserte (succeeded (HR) & gppicture );
PSTM-> release ();
HDC;
HDC = PDC-> getsafehdc ();
If (gppicture)
{
// Obtain the image width and height
Long hmwidth;
Long hmheight;
Gppicture-> get_width (& hmwidth );
Gppicture-> get_height (& hmheight );
// Convert from width to height to pixel
Int nwidth = muldiv (hmwidth, getdevicecaps (HDC, logpixelsx), himetric_inch );
Int nheight = muldiv (hmheight, getdevicecaps (HDC, logpixelsy), himetric_inch );
Rect RC;
Getclientrect (& rc);/* obtain the customer zone */
Gppicture-> render (HDC, X, Y, (INT) height * hmwidth/hmheight, height, 0, hmheight, hmwidth,-hmheight, & rc );
/* Display image */
}
Globalfree (hglobal );
}
// In onerasebkgnd
Crect RC;
Getclientrect (& rc );
Showpicture (PDC, strjpgpath, RC. Left, RC. Top, RC. Width (), RC. Height ());