// basic.cpp : 定义应用程序的入口点。 // #include "stdafx.h" #include "main.h" #include "cef_form.h" enum ThreadId { kThreadUI }; #pragma comment(lib, "dbghelp.lib") int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // 将 bin\\cef 目录添加到环境变量,这样可以将所有 CEF 相关文件放到该目录下,方便管理 // 在项目属性->连接器->输入,延迟加载 nim_libcef.dll nim_comp::CefManager::GetInstance()->AddCefDllToPath(); HRESULT hr = ::OleInitialize(NULL); if (FAILED(hr)) return 0; // 初始化 CEF CefSettings settings; if (!nim_comp::CefManager::GetInstance()->Initialize(nbase::win32::GetCurrentModuleDirectory() + L"cef_temp\\", settings, kEnableOffsetRender)) { return 0; } // 创建主线程 MainThread thread; // 执行主线程循环 thread.RunOnCurrentThreadWithLoop(nbase::MessageLoop::kUIMessageLoop); // 清理 CEF nim_comp::CefManager::GetInstance()->UnInitialize(); ::OleUninitialize(); return 0; } void MainThread::Init() { nbase::ThreadManager::RegisterThread(kThreadUI); // 获取资源路径,初始化全局参数 // 默认皮肤使用 resources\\themes\\default // 默认语言使用 resources\\lang\\zh_CN // 如需修改请指定 Startup 最后两个参数 std::wstring theme_dir = nbase::win32::GetCurrentModuleDirectory(); ui::GlobalManager::Startup(theme_dir + L"resources\\", ui::CreateControlCallback(), false); // 创建一个默认带有阴影的居中窗口 CefForm* window = new CefForm(); window->Create(NULL, CefForm::kClassName.c_str(), WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX, 0, nim_comp::CefManager::GetInstance()->IsEnableOffsetRender()); window->CenterWindow(); window->ShowWindow(); } void MainThread::Cleanup() { ui::GlobalManager::Shutdown(); SetThreadWasQuitProperly(true); nbase::ThreadManager::UnregisterThread(); }