[1225/181834.383:FATAL:receiver.h(159)] Check failed: !is_bound(). Receiver for network.mojom.TrustedHeaderClient is already bound
解决方案: 增加命令行参数
--disable-request-handling-for-testing
解决方案: 检查语言区域设置是否正确(本例设置为中文)
CefSettings settings;
CefString(&settings.locale).FromWString(L"zh-CN");
FATAL:event.cc(567)] Check failed : 3 >= click_count(3 vs. 4)
解决方案: SendMouseClickEvent判断点击次数是否大于3,如果大于3则默认为3
browser_host->SendMouseClickEvent(mouse_event, btnType, false,last_click_count_ >=4 ? 3: last_click_count_);
解决方案: 不使用opengl,改用原始方式UpdateLayeredWindow
实现(cef 109 demo基础改)
void DrawBuffer(HDC hDC, RECT rtDest,const void *buf)
{
COLORREF* pColors = nullptr;
HDC hMemDC = ::CreateCompatibleDC(hDC);
HBITMAP hBitMap = CreateRGBA32Bitmap(hDC, rtDest.right - rtDest.left, rtDest.bottom - rtDest.top, &pColors);
::SelectObject(hMemDC, hBitMap);
int w = rtDest.right - rtDest.left;
int h = rtDest.bottom - rtDest.top;
memcpy(pColors, buf, (rtDest.right - rtDest.left) * (rtDest.bottom - rtDest.top) * 4);
for (int ih = 0; ih < h/2; ++ih)
{
for (int iw = 0; iw < w; ++iw)
{
COLORREF temp = pColors[ih * w + iw];
pColors[ih * w + iw] = pColors[(h - 1 - ih) * w + iw];
pColors[(h - 1 - ih) * w + iw] = temp;
}
}
BLENDFUNCTION bf = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
AlphaBlend(hDC, rtDest.left, rtDest.top, rtDest.right - rtDest.left, rtDest.bottom - rtDest.top, hMemDC, 0, 0, rtDest.right - rtDest.left, rtDest.bottom - rtDest.top, bf);
DeleteObject(hBitMap);
DeleteDC(hMemDC);
}
void PaintContent(HDC hDc, RECT rcPaint,const void *buf)
{
//DrawAColor(hDc, rcPaint, 0xffff0000);
DrawBuffer(hDc, rcPaint, buf);
}
void OsrRenderHandlerWinGL::OnPaint(
CefRefPtr<CefBrowser> browser,
CefRenderHandler::PaintElementType type,
const CefRenderHandler::RectList& dirtyRects,
const void* buffer,
int width,
int height) {
CEF_REQUIRE_UI_THREAD();
RECT rtWindow;
GetWindowRect(hwnd(), &rtWindow);
if (buffer == nullptr || (rtWindow.right - rtWindow.left) != width || (rtWindow.bottom - rtWindow.top) != height)
{
return;
}
COLORREF* pOffscreenBits = NULL;
HDC hdc = GetDC(hwnd());
HDC hDcOffscreen = ::CreateCompatibleDC(hdc);
HBITMAP hbmpOffscreen = CreateRGBA32Bitmap(hdc, width, height, &pOffscreenBits);
HBITMAP hOldBitmap = (HBITMAP) ::SelectObject(hDcOffscreen, hbmpOffscreen);
RECT rtPaint = { 0,0,rtWindow.right - rtWindow.left, rtWindow.bottom - rtWindow.top };
PaintContent(hDcOffscreen, rtPaint,buffer);
BLENDFUNCTION bf = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
SIZE sizeWnd = { rtWindow.right - rtWindow.left, rtWindow.bottom - rtWindow.top };
POINT ptPos = { rtWindow.left, rtWindow.top };
//::ClientToScreen(hWnd, &ptPos);
POINT ptSrc = { 0,0 };
UpdateLayeredWindow(hwnd(), hdc, &ptPos, &sizeWnd, hDcOffscreen, &ptSrc, 0, &bf, ULW_ALPHA);
DeleteDC(hDcOffscreen);
DeleteObject(hbmpOffscreen);
ReleaseDC(hwnd(),hdc);
if (type == PET_VIEW && !renderer_.popup_rect().IsEmpty()) {
painting_popup_ = true;
browser->GetHost()->Invalidate(PET_POPUP);
painting_popup_ = false;
}
}