Draw the jpg image on the background of the dialog box: (this code can be executed)

Source: Internet
Author: User

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 ());

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.