【问题标题】:Make Transparent Window Not Clickthrough使透明窗口不点击
【发布时间】:2019-09-01 18:24:24
【问题描述】:

所以我在最新版本的 Window x64 上使用 CEF3,我需要创建一个 POC 来通过 CEF 加载特定网页并且窗口必须是半透明的。我设法做到了,但是现在,当您点击它加载的页面时,点击似乎是通过窗口点击的,因此您实际上无法浏览该页面。

有谁知道如何同时拥有一个半透明的窗口和不通过点击?

这是我用于透明度的代码。我已经用谷歌搜索了这个问题,但似乎无法找到解决我问题的方法。此外,我对 Win32 API 非常不满意,否则我敢打赌这会容易得多!

非常感谢您!

BOOL MakeWindowTransparent(HWND hWnd, unsigned char factor) {
/* First, see if we can get the API call we need. If we've tried
* once, we don't need to try again. */
if (!initialized) {
  HMODULE hDLL = LoadLibrary(L"user32");

  pSetLayeredWindowAttributes =
    (PSLWA) GetProcAddress(hDLL, "SetLayeredWindowAttributes");

  initialized = TRUE;
}

if (pSetLayeredWindowAttributes == NULL)
  return FALSE;

/* Windows need to be layered to be made transparent. This is done
* by modifying the extended style bits to contain WS_EX_LAYARED. */
SetLastError(0);

SetWindowLong(hWnd,
  GWL_EXSTYLE,
  GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);

if (GetLastError())
  return FALSE;

/* Now, we need to set the 'layered window attributes'. This
* is where the alpha values get set. */
return pSetLayeredWindowAttributes(hWnd,
  RGB(255, 255, 255),
  factor,
  LWA_COLORKEY | LWA_ALPHA);

}

【问题讨论】:

  • 如果您将 alpha 设置为 1 而不是 0,它看起来仍然是透明的,但点击会被记录。
  • Windows 实现了 Rockhard 规则,即对用户的眼睛透明的窗口对鼠标也是透明的。从技术上讲,您可以利用 Aero 中的错误。 一些颜色键值对鼠标不透明。非常随机,RGB(255, 0, 0) 会做到这一点。该错误已经存在很长时间了,他们不太可能仍然可以修复它。
  • Hans Passant,这部分满足了我的需要。是否还有其他存在此错误的值?它们是否记录在任何地方?
  • 还有其他的,它们的值是随机的。很难让任何人记录错误:)
  • pSetLayeredWindowAttributes 长什么样子?

标签: c++ winapi


【解决方案1】:

删除 LWA_COLORKEY (至少)在 AHK 中有效。 参考source并搜索:

MySetLayeredWindowAttributes(target_window, 0, value, LWA_ALPHA);

【讨论】:

    猜你喜欢
    • 2018-04-23
    • 1970-01-01
    • 2015-09-27
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    • 2013-02-21
    • 1970-01-01
    相关资源
    最近更新 更多