'Chromium Embedded Framework (CEF) - Call_back is not called
Please tell me,
I have simplified the selfsimple example to a minimal amount of code: this code successfully creates a browser window and opens the specified page:
1.int main()
2.class my_SimpleApp
3.class my_work_handle
int main()
{
//-------------------------------------------------------------------------
HINSTANCE hInstance = GetModuleHandleA(NULL);
CefMainArgs args(hInstance);
int ec = CefExecuteProcess(args, nullptr, nullptr);
if (ec >= 0)
{
return ec;
}
CefSettings settings;
settings = { 0 };
//-------------------------------------------------------------------------
CefRefPtr<my_SimpleApp> my_app;
my_app = new my_SimpleApp[1];
CefInitialize(args, settings, my_app.get(), nullptr);
//-------------------------------------------------------------------------
CefRunMessageLoop();
CefShutdown();
//-------------------------------------------------------------------------
}
class my_SimpleApp : public CefApp, public CefBrowserProcessHandler
{
public:
CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() override
{
return this;
}
void OnContextInitialized()
{
std::cout << "OnContextInitialized" << std::endl;
CEF_REQUIRE_UI_THREAD();
CefBrowserSettings browser_settings;
std::string url = "http://www.google.com";
CefWindowInfo window_info;
window_info.SetAsPopup(nullptr, "cefsimple");
CefRefPtr<my_work_handler> my_work_handler_;
my_work_handler_ = new my_work_handler[1];
CefBrowserHost::CreateBrowser(window_info, my_work_handler_, url, browser_settings, nullptr, nullptr);
}
private:
IMPLEMENT_REFCOUNTING(my_SimpleApp);
};
class my_work_handler : public CefApp, public CefLifeSpanHandler, public CefClient
{
public:
void OnAfterCreated(CefRefPtr<CefBrowser>my_CefRefPtr) override
{
std::cout << "OnAfterCreated" << std::endl;
}
bool DoClose(CefRefPtr<CefBrowser>my_CefRefPtr) override
{
std::cout << "DoClose" << std::endl;
return false; //at the moment, it doesn't matter what returns
}
void OnBeforeClose(CefRefPtr<CefBrowser>my_CefRefPtr) override
{
std::cout << "OnBeforeClose" << std::endl;
CefQuitMessageLoop();
}
private:
IMPLEMENT_REFCOUNTING(my_work_handler);
};
This code is executed successfully, a browser window is created and opens google.com . But I can't understand why the console doesn't display the message ---> "OnAfterCreated"
If i run the cefsimple example, it is output there, but in my case, for some reason not. I can 't figure out what the reason is ?
PS: and when closing the browser window - also not output - "DoClose" and "OnBeforeClose"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
