I want to load HTML from a resource embedded in my exe file. I am using C++ and CEF3 on Windows 8.1.
I've seen this article and it seems to be exactly what I'm looking for but it concerns CefSharp.
Is there a way to do that with C++?
Also, can I embed a folder containing HTML and CSS files and load it with CEF?
You can add any file to the resources. Open the project's *.rc file with notepad. Add the following line to *.rc file:
123 RCDATA "c:\\source-path\\source-file.htm"
You can use any predefined value, example #define ID_STRING 1234
Open the resource during run time, then copy to disk or open the data directly. This code will try to save the file to disk, then open file disk.
#include <Windows.h>
#include <fstream>
void foo()
{
HRSRC hrsrc = FindResource(NULL, MAKEINTRESOURCE(123), RT_RCDATA);
if(!hrsrc)
{
MessageBoxW(0, L"resource `123 RCDATA` not found", 0, 0);
return;
}
HMODULE hmodule = 0;
HGLOBAL hglobal = LoadResource(hmodule, hrsrc);
void *data = LockResource(hglobal);
DWORD size = SizeofResource(hmodule, hrsrc);
const wchar_t* filename = L"c:\\temp\\testout.htm";
std::ofstream fout(filename, std::ios::binary);
if(!fout)
{
MessageBoxW(0, L"Cannot make temp file", 0, 0);
return;
}
fout.write((char*)data, size);
fout.close();
ShellExecuteW(0, NULL, filename, NULL, NULL, SW_SHOW);
}
RCDATA
is constant 10
RT_RCDATA
is a macro for MAKEINTRESOURCE(10)