#include "def.h"
#include <Windows.h>
#include <list>
#include "include/base/cef_bind.h"
#include "include/cef_browser.h"
#include "include/cef_command_line.h"
#include "include/views/cef_window.h"
#include "include/cef_app.h"
#include "include/wrapper/cef_helpers.h"
#include "desktop.h"
#include "charswap.h"
#include <Windowsx.h>
//
//g_mainParams[0] type HWND 主要窗口类
//g_mainParams[1] type HOOK 键盘事件全局钩子
//g_mainParams[2] type HOOK 鼠标事件全局钩子
//g_mainParams[3] type CefBrowser* 浏览器对象,注意,可能为空
void* g_mainParams = NULL;
int g_mainParamsCount = 0;
class MyCefClient :
public CefClient,
public CefDisplayHandler,
public CefLifeSpanHandler,
public CefLoadHandler
{
private:
std::list<CefRefPtr<CefBrowser>> m_listBrowser;
bool m_bClosing;
public:
MyCefClient() {
m_bClosing = false;
printf("[%s] methods %s : %s\n", "debug", "MyCefClient::MyCefClient", "create!");
};
~MyCefClient() {
printf("[%s] methods %s : %s\n", "debug", "MyCefClient::MyCefClient", "delete!");
};
public:
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE { return this; }
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE { return this; }
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE { return this; }
public:
// 有关请求的弹出窗口的信息。为了允许创建
// 弹出浏览器可选择修改 |windowInfo|、|client|、|settings|和
// |no_javascript_access|并返回假。取消弹出窗口的创建
// 浏览器返回真。
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& target_url,
const CefString& target_frame_name,
WindowOpenDisposition target_disposition,
bool user_gesture,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings,
CefRefPtr<CefDictionaryValue>& extra_info,
bool* no_javascript_access) {
CEF_REQUIRE_UI_THREAD();
printf("[%s] methods %s : %s\n", "info", "MyCefClient::OnBeforePopup", "create...");
if (m_listBrowser.empty() && m_bClosing == false) {
printf("[%s] methods %s : %s\n", "info", "MyCefClient::OnBeforePopup", "create next!");
return false;
}
else {
printf("[%s] methods %s : %s\n", "info", "MyCefClient::OnBeforePopup", "create exit, Main_Browser exist!");
return true;
}
}
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title) OVERRIDE {
//当有新的浏览器标题可用时的回调
CEF_REQUIRE_UI_THREAD();
std::string strUtf8WindowTitle = title.ToString();
std::string strAsciiWindowTitle = UTF_82ASCII(strUtf8WindowTitle);
printf("[info] OnTitleChange title:%s\n", strAsciiWindowTitle.c_str());
}
virtual void OnAfterCreated(CefRefPtr<CefBrowser> refBrowser) OVERRIDE {
//当浏览器创建后的回调
CEF_REQUIRE_UI_THREAD();
printf("[%s] methods %s : %s %p\n", "debug", "MyCefClient::OnAfterCreated", "browser created! hand = ", refBrowser->GetHost()->GetWindowHandle());
CefBrowser* ptrBrowser = refBrowser.get();
((void**)(g_mainParams))[3] = (ptrBrowser);
//printf("[%s] methods %s : %s %p\n", "debug", "MyCefClient::OnAfterCreated", "browser! ptr = ", GET_PARAMS(g_mainParams, CefBrowser*,3));
m_listBrowser.push_back(refBrowser);
}
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE {
CEF_REQUIRE_UI_THREAD();
// Remove from the list of existing browsers.
auto bit = m_listBrowser.begin();
for (; bit != m_listBrowser.end(); ++bit) {
if ((*bit)->IsSame(browser)) {
m_listBrowser.erase(bit);
break;
}
}
if (m_listBrowser.empty()) {
m_bClosing = true;
// All browser windows have closed. Quit the application message loop.
CefQuitMessageLoop();
}
return;
}
void CloseAllBrowsers(bool bForceClose) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute on the UI thread.
CefRefPtr<ClientCloseAllTask> task(new ClientCloseAllTask(this, bForceClose));
CefPostTask(TID_UI, task);
return;
}
if (m_listBrowser.empty())
return;
auto it = m_listBrowser.begin();
for (; it != m_listBrowser.end(); ++it)
(*it)->GetHost()->CloseBrowser(bForceClose);
}
public:
IMPLEMENT_REFCOUNTING(MyCefClient);
private:
class ClientCloseAllTask : public CefTask
{
IMPLEMENT_REFCOUNTING(ClientCloseAllTask);
public:
ClientCloseAllTask(MyCefClient* than, bool bForceClose) {
m_ptrThis = than;
_bForceClose = bForceClose;
}
private:
MyCefClient* m_ptrThis;
bool _bForceClose;
public:
void Execute() {
m_ptrThis->CloseAllBrowsers(_bForceClose);
}
};
};
class MyCefApp :
public CefApp,
public CefBrowserProcessHandler {
public:
MyCefApp() {
//m_mainBrowser = nullptr;
//m_client = nullptr;
printf("[%s] methods %s : %s %p\n", "debug", "MyCefApp::MyCefApp", "app create! hand = ", this);
};
~MyCefApp() {
printf("[%s] methods %s : %s %p\n", "debug", "MyCefApp::~MyCefApp", "app delete! hand = ", this);
}
public:
virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() override {
return this;
};
virtual void OnContextInitialized() override
{
printf("[info] MyCefApp::OnContextInitialized -- init\n");
/*
CefWindowInfo windowInfo;
windowInfo.SetAsPopup(NULL, "cefsimple");
windowInfo.width = 800;
windowInfo.height = 600;
CefRefPtr<CefClient> client(new MyCefClient);
CefString url = "www.baidu.com";
CefBrowserSettings settings;
bool bRet = CefBrowserHost::CreateBrowser(windowInfo,client,url, settings,NULL,NULL);
if (bRet == false) {
printf("[error] CefBrowserHost::CreateBrowser -- normal\n");
}
*/
printf("[info] MyCefApp::OnContextInitialized -- done\n");
};
public:
IMPLEMENT_REFCOUNTING(MyCefApp);
public:
//CefRefPtr<MyCefClient> m_client;
//CefRefPtr<CefBrowser> m_mainBrowser;
};
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static clock_t clcOldLbuttonDownTime = 0;
static clock_t clcOldLbuttonClickTime = 0;
switch (message)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// TODO: 在此处添加使用 hdc 的任何绘图代码...
EndPaint(hWnd, &ps);
}
break;
case WM_CREATE:
{
}
break;
case WM_MOUSEMOVE: {
CefBrowser* brower = (CefBrowser*)(((void**)(g_mainParams))[3]);
if (brower == NULL) break;
//printf("[%s] methods %s : %s %p\n", "debug", "WndProc", "browser! ptr = ", brower);
CefMouseEvent mouseEvent;
mouseEvent.x = GET_X_LPARAM(lParam);
mouseEvent.y = GET_Y_LPARAM(lParam);
brower->GetHost()->SendMouseMoveEvent(mouseEvent, false);
}break;
case WM_LBUTTONDOWN: {
clcOldLbuttonDownTime = clock();
CefBrowser* brower = (CefBrowser*)(((void**)(g_mainParams))[3]);
if (brower == NULL) break;
clock_t clcCurrentTime = clock();
CefMouseEvent mouseEvent;
mouseEvent.x = GET_X_LPARAM(lParam);
mouseEvent.y = GET_Y_LPARAM(lParam);
brower->GetHost()->SendMouseClickEvent(mouseEvent, CefBrowserHost::MouseButtonType::MBT_LEFT, false, 0);
//brower->GetHost()->SendMouseClickEvent(mouseEvent, CefBrowserHost::MouseButtonType::MBT_LEFT, false, 0);
}break;
case WM_LBUTTONUP: {
CefBrowser* brower = (CefBrowser*)(((void**)(g_mainParams))[3]);
if (brower == NULL) break;
clock_t clcCurrentTime = clock();
CefMouseEvent mouseEvent;
mouseEvent.x = GET_X_LPARAM(lParam);
mouseEvent.y = GET_Y_LPARAM(lParam);
brower->GetHost()->SendMouseClickEvent(mouseEvent, CefBrowserHost::MouseButtonType::MBT_LEFT, true, 0);
//
if (clcCurrentTime - clcOldLbuttonDownTime < 300) {
clcOldLbuttonClickTime = clcCurrentTime;
}
}break;
case WM_CLOSE: {
printf("[%s] methods %s : %s %p\n", "info", "WndProc", "close than window! ptr = ", hWnd);
DestroyWindow(hWnd);
printf("[%s] methods %s : %s %p\n", "info", "WndProc", "closed! ptr = ", hWnd);
}break;
ca
没有合适的资源?快使用搜索试试~ 我知道了~
CEF x64 -vs2019
共321个文件
h:260个
tlog:16个
lib:6个
5星 · 超过95%的资源 需积分: 0 7 下载量 63 浏览量
2023-10-25
22:55:59
上传
评论
收藏 100.85MB ZIP 举报
温馨提示
CEF x64 -vs2019
资源推荐
资源详情
资源评论
收起资源包目录
CEF x64 -vs2019 (321个子文件)
simple_handler.cc 4KB
simple_app.cc 4KB
cefsimple_win.cc 1KB
simple_handler_win.cc 561B
main.cpp 15KB
desktop.cpp 5KB
charswap.cpp 3KB
data_0 8KB
data_1 264KB
data_2 8KB
data_3 8KB
CefTest.vcxproj.filters 1KB
cef_pack_strings.h 360KB
cef_bind_internal.h 118KB
cef_types.h 88KB
cef_pack_resources.h 70KB
cef_tuple.h 57KB
cef_browser_capi.h 39KB
cef_browser.h 37KB
cef_v8_capi.h 37KB
cef_net_error_list.h 36KB
cef_v8.h 33KB
cef_callback.h 33KB
cef_types_wrappers.h 32KB
cef_logging.h 29KB
cef_bind.h 29KB
cef_values_capi.h 27KB
cef_scoped_ptr.h 24KB
cef_string_wrappers.h 23KB
cef_values.h 23KB
cef_translator_test_capi.h 23KB
cef_trace_event.h 22KB
cef_translator_test.h 20KB
cef_bind_helpers.h 19KB
cef_menu_model_capi.h 19KB
cef_message_router.h 18KB
cef_request_context_capi.h 17KB
cef_request_context.h 16KB
cef_menu_model.h 16KB
cef_server_capi.h 15KB
cef_view_capi.h 15KB
cef_resource_manager.h 14KB
cef_callback_list.h 14KB
cef_server.h 14KB
cef_weak_ptr.h 13KB
cef_view.h 13KB
cef_request_handler_capi.h 12KB
cef_bind_internal_win.h 12KB
cef_media_router_capi.h 12KB
cef_request_handler.h 12KB
cef_resource_request_handler.h 12KB
cef_request_capi.h 12KB
cef_resource_request_handler_capi.h 12KB
cef_move.h 11KB
cef_context_menu_handler_capi.h 11KB
cef_life_span_handler_capi.h 11KB
cef_life_span_handler.h 11KB
cef_window_capi.h 11KB
cef_dom_capi.h 11KB
cef_render_handler_capi.h 10KB
cef_media_router.h 10KB
cef_xml_reader_capi.h 10KB
cef_request.h 10KB
cef_cancelable_callback.h 10KB
cef_ref_counted.h 10KB
cef_context_menu_handler.h 10KB
cef_render_handler.h 9KB
cef_resource_handler_capi.h 9KB
cef_textfield_capi.h 9KB
cef_window.h 9KB
cef_frame_capi.h 9KB
cef_atomicops.h 9KB
cef_extension_handler_capi.h 9KB
cef_web_plugin_capi.h 9KB
cef_callback_internal.h 9KB
cef_resource_handler.h 9KB
cef_app_capi.h 9KB
cef_extension_handler.h 9KB
cef_app.h 8KB
cef_dom.h 8KB
cef_string_types.h 8KB
cef_frame.h 8KB
cef_macros.h 8KB
cef_xml_reader.h 8KB
cef_image_capi.h 8KB
cef_urlrequest_capi.h 8KB
cef_stream_capi.h 8KB
cef_cookie_capi.h 8KB
cef_web_plugin.h 8KB
cef_drag_data_capi.h 8KB
cef_command_line_capi.h 8KB
cef_atomicops_x86_msvc.h 8KB
cef_ptr.h 8KB
cef_image.h 8KB
cef_urlrequest.h 8KB
cef_textfield.h 8KB
cef_parser_capi.h 7KB
cef_template_util.h 7KB
cef_cookie.h 7KB
cef_build.h 7KB
共 321 条
- 1
- 2
- 3
- 4
资源评论
- yuyizxia2024-04-26编译通不过呢
东方Code
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功