CImage myImage; CFileDialog fileDlg(TRUE,NULL,NULL,OFN_ALLOWMULTISELECT,_T("Picture Files (*.bmp *.jpg)|*bmp;;*jpg||"),AfxGetMainWnd()); CString pathName; if(fileDlg.DoModal () == IDOK) { POSITION mPos = fileDlg.GetStartPosition(); if(mPos!=NULL) { pathName = (LPCTSTR)fileDlg.GetPathName(); if(!myImage.IsNull())//判斷圖象是否為空,如果不為空則先釋放掉 myImage.Destroy(); myImage.Load(pathName); } } CRect rect; CWnd *pWnd = GetDlgItem(IDC_MY_PIC2); CDC *pDC = pWnd->GetDC(); //第1個控件 pWnd->GetClientRect(&rect); //取得客戶區尺寸 pDC->SetStretchBltMode(STRETCH_HALFTONE); //保持圖片不失真 myImage.Draw( pDC->m_hDC,rect); //已控件尺寸大小來繪圖 ReleaseDC( pDC ); myImage.Destroy();