我在这里增加了窗口透明度,但这将导致我的老鼠穿透问题。 我怎么解决呢
我在这里添加了窗口透明度,但这会导致我的鼠标穿透问题。我如何解决它? win32_edge.hh: noresult set_background_colour_impl(unsigned char r, unsigned char g, unsigned char b, unsigned char a) override { // 设置窗口背景颜色 如果 m_window 为空,则不执行此操作。 如果 m_window 不为空,则: COLORREF color = RGB(r, g, b); HBRUSH brush = CreateSolidBrush(color); HBRUSH oldBrush = (HBRUSH)SetClassLongPtr(m_window, GCLP_HBRBACKGROUND, (LONG_PTR)brush); 如果 oldBrush 不为空,则删除它。 // 处理整个窗口的分层窗口透明度 LONG ex_style = GetWindowLong(m_window, GWL_EXSTYLE); 如果 ex_style 不包含 WS_EX_LAYERED,则: SetWindowLong(m_window, GWL_EXSTYLE, ex_style | WS_EX_LAYERED); // 根据 alpha 值(0-255)设置窗口透明度 SetLayeredWindowAttributes(m_window, 0, 128, LWA_COLORKEY); InvalidateRect(m_window, nullptr, TRUE); // 设置小组件背景颜色 如果 m_widget 为空,则不执行此操作。 如果 m_widget 不为空,则: COLORREF color = RGB(r, g, b); HBRUSH brush = CreateSolidBrush(color); HBRUSH oldBrush = (HBRUSH)SetClassLongPtr(m_widget, GCLP_HBRBACKGROUND, (LONG_PTR)brush); 如果 oldBrush 不为空,则删除它。 InvalidateRect(m_widget, nullptr, TRUE); // 设置 WebView 背景颜色(WebView2 仅支持 alpha 值为 0(透明)或 255(不透明)) 如果 m_controller 为空,则不执行此操作。 如果 m_controller 不为空,则: // WebView2 仅支持 alpha 值为 0(透明)或 255(不透明) COREWEBVIEW2_COLOR color = {a, r, g, b}; ICoreWebView2Controller2 *controller2 = nullptr; 如果 SUCCEEDED(m_controller->QueryInterface(IID_ICoreWebView2Controller2, (void **)&controller2)) { controller2->put_DefaultBackgroundColor(color); controller2->Release(); } 返回空值。 }
内容来源: webview/webview