19,500
社区成员
发帖
与我相关
我的任务
分享
CString pathname;
if(aCFileDialog.DoModal()==IDOK)
{
pathname=aCFileDialog.GetPathName();
if(pathname.GetLength()>0)
{
m_cedit_path.SetWindowText(pathname);
CImage aCImage;
// if(aCImage.Load(pathname)==E_FAIL)
aCImage.LoadFromResource(AfxGetInstanceHandle(),pathname);
if (aCImage.IsNull())
// if(aCImage.LoadFromResource(AfxGetInstanceHandle(),pathname)==E_FAIL)
{
CString strErrMsg;
strErrMsg.LoadString(IDS_KVIMAGEOCX_ERROR_FILEFORMAT);
CString strTitle;
strTitle.LoadString(IDS_KVIMAGEOCX_MESSAGEBOXTITLE);
MessageBox(strErrMsg ,strTitle);
}
}
}
void LoadFromResource( HINSTANCE hInstance, LPCTSTR pszResourceName ) throw();
void LoadFromResource( HINSTANCE hInstance, UINT nIDResource ) throw();
CString pathname;
if(aCFileDialog.DoModal()==IDOK)
{
pathname=aCFileDialog.GetPathName();
if(pathname.GetLength()>0)
{
m_cedit_path.SetWindowText(pathname);
CImage aCImage;
// if(aCImage.Load(pathname)==E_FAIL)
aCImage.LoadFromResource(AfxGetInstanceHandle(),pathname);
if (aCImage.IsNull())
// if(aCImage.LoadFromResource(AfxGetInstanceHandle(),pathname)==E_FAIL)
{
CString strErrMsg;
strErrMsg.LoadString(IDS_KVIMAGEOCX_ERROR_FILEFORMAT);
CString strTitle;
strTitle.LoadString(IDS_KVIMAGEOCX_MESSAGEBOXTITLE);
MessageBox(strErrMsg ,strTitle);
}
}
}
在代码中标红的部分,你把它替换为所要添加的图片ID(图片须事先添加到工程里),例如IDB_XXX等形式…