duilib中嵌入cef3, 并和js交互


duilib嵌入cef3, 并和js交互
资源截图
代码片段和文件信息
#include “MainWnd.h“

#include “includecef_browser.h“

CMainWnd::CMainWnd(void): m_handler(new SimpleHandler)
{
}


CMainWnd::~CMainWnd(void)
{
}

void CMainWnd::InitWindow()
{
m_pBtnClose = static_cast(m_PaintManager.FindControl(L“btn_close“));
m_pURL = static_cast(m_PaintManager.FindControl(L“edit_url“));
m_pBtnGo = static_cast(m_PaintManager.FindControl(L“btn_go“));
m_pBtnBack = static_cast(m_PaintManager.FindControl(L“btn_back“));
m_pBtnCallJs = static_cast(m_PaintManager.FindControl(L“btn_calljs“));

RECT rt;
::GetClientRect(m_hWnd &rt);
rt.top += 100;
rt.bottom -= 3;
rt.left += 3;
rt.right -= 3;

CefWindowInfo info;
info.SetAsChild(m_hWnd rt);

CefBrowserSettings settings;
CefBrowserHost::CreateBrowser(info m_handler.get() L“http://www.baidu.com“ settings NULL);
}

void CMainWnd::OnFinalMessage( HWND hWnd )
{
while(m_handler->GetBrowser())
{
Sleep(10);
}
::PostQuitMessage(0);
}

void CMainWnd::Notify(TNotifyUI& msg)
{
if(msg.sType == DUI_MSGTYPE_CLICK)
{
if(msg.pSender == m_pBtnClose)
{
//
Close();
}
else if(msg.pSender == m_pBtnCallJs)
{
CefRefPtr msg = CefProcessMessage::Create(“callback_func“);
CefRefPtr args = msg->GetArgumentList();
args->SetString(0 “call js call back function“);
args->SetInt(1 10);
m_handler->GetBrowser()->SendProcessMessage(PID_RENDERER msg);
}
else if(msg.pSender == m_pBtnGo)
{
if(m_pURL->GetText().Compare(L““) == 0)
{
m_handler->GetBrowser()->GetMainframe()->Executejavascript(L“alert(“url is empty“);“ m_handler->GetBrowser()->GetMainframe()->GetURL() 0);
return ;
}
std::wstring strUrl = m_pURL->GetText();
if(!m_pURL->GetText().IsEmpty() /*&& m_pURL->GetText().Compare(L““) != 0*/)
m_handler->GetBrowser()->GetMainframe()->LoadURL(strUrl);
}
else if(msg.pSender == m_pBtnBack)
{
//m_handler->GetBrowser()->GoBack();
CallJsFunc(L“GoBack()“);
}
}
}

LRESULT CMainWnd::HandleCustomMessage(UINT uMsg WPARAM wParam LPARAM lParam BOOL& bHandled)
{
if(uMsg == WM_SIZE)
{
HWND hwnd = ::FindWindowEx(m_hWnd NULL L“CefBrowserWindow“ NULL);
::MoveWindow(hwnd 3 100 LOWORD(lParam)-6 HIWORD(lParam)-103 TRUE);
}
else if(uMsg == WM_DROPFILES)
{
WCHAR wcFile[MAX_PATH] = {0};
UINT count = DragQueryFile((HDROP)wParam 0xFFFFFFFF NULL 0);
if(count)
{
DragQueryFile((HDROP)wParam 0 wcFile MAX_PATH);
wstring str = wcFile;
m_handler->GetBrowser()->GetMainframe()->LoadURL(str);
m_pURL->SetText(wcFile);
}
}
else if(uMsg == WM_COPYDATA)
{
COPYDATASTRUCT* pData = (COPYDATASTRUCT*)lParam;
::MessageBox(NULL (LPCWSTR)pData->lpData L“js func“ MB_OK);
}
return 0;
}

void CMainWnd::CallJsFunc(LPCWSTR strJSFuncName)
{
if(strJSFuncName[0] == L‘‘ || strJSFuncName == NULL)
return;

m

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)