您的位置:首页 > 其它

MFC从资源加载文本

2017-05-15 00:22 176 查看
bool CWizardSheet::GetTextResource(UINT uID, CString& csContent)
{
HMODULE hModule=GetModuleHandle(NULL);
HRSRC hRes = FindResource(hModule,MAKEINTRESOURCE(uID),_T("txt"));
if(hRes == NULL)
{
FreeResource(hRes);
}
else
{
HGLOBAL hglobal = LoadResource(hModule,hRes);
if(hglobal == NULL)
{
FreeResource(hglobal);
return false;
}
else
{
//get text
csContent.Format(_T("%s"),(LPVOID)hglobal);
}
}
return true;
}


  

bool CWizardSheet::GetResource(UINT uID, CString csType, CString csOutputPath)
{
CFile file;
HMODULE hModule=GetModuleHandle(NULL);
HRSRC hRes = FindResource(hModule,MAKEINTRESOURCE(uID),csType);
if(hRes == NULL)
{
FreeResource(hRes);
}
else
{
HGLOBAL hglobal = LoadResource(hModule,hRes);
if(hglobal == NULL)
{
FreeResource(hglobal);
return false;
}
else
{
//释放文件
LPBYTE lpByte=(LPBYTE)LockResource(hglobal);
DWORD dwRcSize=SizeofResource(hModule,hRes);
file.Open(csOutputPath,CFile::modeCreate | CFile::modeWrite);
file.Write(lpByte,dwRcSize);
file.Close();
}
}
return true;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: