How to add a text file as resource in VC++ 2005?

2019-03-27 13:31发布

I want to add a text file as resource in VC++ 2005. I am not able to find text as option in resource template.

Also once added how can I refer to that file while programming?

1条回答
家丑人穷心不美
2楼-- · 2019-03-27 14:26

That's pretty simple: In your solution, switch to resource view, right click on your RC file, select "Add Resource", click on "Import", select "All files" then open the file you want. You're prompted to type in a custom resource type. Enter "TEXT" for example.

You can now load your custom resource like this:

HRSRC hRes = FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_TEXT1), _T("TEXT"));
DWORD dwSize = SizeofResource(GetModuleHandle(NULL), hRes);
HGLOBAL hGlob = LoadResource(GetModuleHandle(NULL), hRes);
const BYTE* pData = reinterpret_cast<const BYTE*>(::LockResource(hGlob));

You don't need to unlock or free the resource, so this code can be used exactly as written without any additional calls. The resource will be freed when your program exits.

查看更多
登录 后发表回答