CWnd* m_pWnd;
m_pWnd = this->GetDlgItem(IDC_PICTURE); // IDC_PICTURE此为Picture控件ID
//********* 加载图像 ********************
CString filter;
filter = "支持的图像(*.bmp;*.tif;*.jpg)|*.bmp;*.tif;*.jpg||";
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, filter);
//**默认加载图像时路径,此处可不做处理
CString strForlder=TEXT("d:// ");
dlg.m_ofn.lpstrInitialDir = strForlder;
//**
if (dlg.DoModal() == IDOK)
{
try{
// 此类方法即便实现体在OnPaint()外,Picture也可以显示图像,已经过验证
CRect rect;
CImage image;
image.Load(dlg.GetPathName().GetBuffer());
wndDraw->GetWindowRect(&rect); //将客户区选中到控件表示的矩形区域内
CWnd *pWnd = NULL;
pWnd = wndDraw;//获取控件句柄
pWnd->GetClientRect(&rect);//获取句柄指向控件区域的大小
CDC *pDc = NULL;
pDc = pWnd->GetDC();//获取picture的DC
pDc->SetStretchBltMode(STRETCH_HALFTONE);
image.Draw(pDc->m_hDC, rect);//将
ReleaseDC(pDc);
}
catch(CException *e)//&e
{
TCHAR szError[1024];
e->GetErrorMessage(szError,1024); // e.GetErrorMessage(szError,1024);
::AfxMessageBox(szError);
}
}