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)