MFC生成的exe文件中,如果该exe文件中需要调用图片。直接运行exe文件,会出现图片无法载入的问题。
解决方法是:
step1: 将图片载入资源,如ID为ID_pic1;
step2: 图片载入代码
CImage image;
if (pic1 != 0)
{
image.LoadFromResource(theApp.m_hInstance,ID_pic1);
}
step3:将图片显示在picture控件中:(OnPaint函数)
CDC *pDC;
CStatic *m_picture = (CStatic *)GetDlgItem(IDC_STATIC1);
m_picture->GetClientRect(&rect);
pDC = m_picture->GetDC();
SetStretchBltMode(pDC->m_hDC,STRETCH_HALFTONE);
rect1 = CRect(rect.TopLeft(), CSize((int)rect.Width(),(int)rect.Height()));
image.StretchBlt(pDC->m_hDC,rect1,SRCCOPY);