首页 > 代码库 > picture control添加图片

picture control添加图片

void CMFCApplication1Dlg::OnBnClickedOk()
{
	// TODO:  在此添加控件通知处理程序代码
	CString filter;
	filter = "所有文件(*.bmp,*.png,*.gif,*.tiiff)|*.bmp;*.png;*.jpg;*.gif;*.tiff| BMP(*.bmp)|*.bmp| JPG(*.jpg)|*.jpg|PNG(*.png)|*.png|GIF(*.gif)|*.gif| TIFF(*.tiff)|*.tiff||";
	CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, filter, NULL);
	if (dlg.DoModal() == IDOK)
	{
		//打开对话框获取图像信息
		CString BmpName = dlg.GetPathName();     //获取文件路径名   如D:\pic\abc.bmp
		CImage myImage;
		myImage.Load(BmpName);
		CRect rect;
		CWnd *pWnd = GetDlgItem(IDC_STATIC);  //(这是在此资源创建的类的内部, 若是在外部, 可先通过获得CMainFrame的指针, 再通过pMianFrame->GetDlgItem(IDCk_MY_PIC)来获取)
			CDC *pDC = pWnd->GetDC();
		pWnd->GetClientRect(&rect);
		pDC->SetStretchBltMode(STRETCH_HALFTONE);
		myImage.Draw(pDC->m_hDC, rect);
		ReleaseDC(pDC);
		myImage.Destroy();
		
	}
}

  

picture control添加图片