MFC displays images in the picture control (JPG)

Source: Internet
Author: User

First select the Picture:

voidChbgk_picdlg::onbnclickedbutton1 () {CFileDialog cfd (true, _t (". jpg"), null,ofn_filemustexist| ofn_hidereadonly,_t ("executable Files (*.jpg) |*.jpg| All Files (*. *) |*.*| |"), This);//conventions for option picturesif(CFD. DoModal ()!=idok)//decide whether to get a picture{    return;} M_path= CfD. GetPathName ();//get the picture pathUpdateData (false);//update path Public variablesshow_picture (); //call the show Picture function}//Show Picture functionvoidchbgk_picdlg::show_picture () {if(m_path=="")//determine if the picture path exists{   return;}//AfxMessageBox (_t ("read to Picture Path"));CRect rect;m_picture. GetClientRect (&rect);//M_picture is a picture control control variable that obtains the control's area objectCImage image;//working with picture classesImage. Load (M_path);//Loading the path slice information to the picture classcdc* PDC = m_picture. GETWINDOWDC ();//get the DC for the display controlImage. Draw (PDC-M_hdc,rect);//Picture Draw Draw function for picture classReleaseDC (PDC);}

The above two steps can display the JPG image information in the picture control control, but when the window is minimized or overwritten by another application, this time the picture can not be displayed, then you need to redraw the picture in control, by getting wm_ The paint message is processed and the response OnPaint () function is processed:

voidif  (Isiconic ()) {   ...} ...} Else {      cdialog::onpaint ();      // Redraw dialog Box   // Update Windows window, if there is no such pace, the picture shows that there will be problems   Show_picture ();     // Redraw a picture function }}

Note that you first draw the dialog box, update the window information when you are finished, and then draw the picture area in the control.

Here basically a picture selection shows the application has come out, details of the problem to be dealt with again.

Reprinted from: Http://hi.baidu.com/1235453434/item/7c6d1d9afec5c9dc1f4271ab

MFC displays images in the picture control (JPG)

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.