windows - 在Delphi中使其他应用程序窗口半透明

标签 windows delphi delphi-xe lazarus translucency

大家好

我在网上搜索了有关这是否可行的任何说明,但无济于事。我需要编写一个允许我选择另一个应用程序的应用程序,并通过这样做使所选应用程序半透明并位于顶部(如重影图像覆盖)。

使用 Delphi 完全可以做到这一点吗?我正在使用 Delphi XE 和 Lazarus。如果有人能指出我从哪里开始的大体方向,我将非常感激。

提前致谢

最佳答案

您可以这样做但不推荐,因为这种行为必须由自己的应用程序处理。无论如何,如果您因为您有充分的理由这样做而坚持,我在这里留下代码来设置窗口的透明度并使窗口成为最顶部,只是为了展示如何做到这一点。

透明度

您必须使用 SetWindowLong使用 WS_EX_LAYERED 标志和 SetLayeredWindowAttributes 函数使用 LWA_ALPHA 设置透明度。

Procedure SethWndTrasparent(hWnd: HWND;Transparent:boolean);
var
 l        : Longint;
 lpRect   : TRect;
begin
    if Transparent then
    begin
      l := GetWindowLong(hWnd, GWL_EXSTYLE);
      l := l or WS_EX_LAYERED;
      SetWindowLong(hWnd, GWL_EXSTYLE, l);
      SetLayeredWindowAttributes(hWnd, 0, 180, LWA_ALPHA);
    end
    else
    begin
      l := GetWindowLong(hWnd, GWL_EXSTYLE);
      l := l xor WS_EX_LAYERED;
      SetWindowLong(hWnd, GWL_EXSTYLE, l);
      GetWindowRect(hWnd, lpRect);
      InvalidateRect(hWnd, lpRect, true);
    end;
end;

将窗口置顶

您必须使用 SetWindowPos函数传递 HWND_TOPMOST 值,该值将窗口置于所有非最顶层窗口之上。该窗口即使在停用时也保持其最顶部的位置。

Procedure SethWndOnTop(hWnd: HWND);
var
  lpRect   : TRect;
begin
  if GetWindowRect(hWnd,lpRect) then
  SetWindowPos(hWnd , HWND_TOPMOST, lpRect.left, lpRect.top, lpRect.Right-lpRect.left, lpRect.Bottom-lpRect.Top, SWP_SHOWWINDOW);
end;

关于windows - 在Delphi中使其他应用程序窗口半透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5585975/

相关文章:

windows - ShowWindow 和 ShowWindowAsync 之间有什么区别?

forms - 启用表单大小调整

delphi - 接收 COM 事件,无需手动将 dispid 映射到方法

Windows批处理文件获取C :\drive total space and free space available

c++ - 我可以通过句柄判断可等待计时器何时触发吗?

MySQL 连接提示输入密码,即使它在连接字符串中

delphi - 确定要包含的 Delphi 运行时包

delphi - 如何在函数内添加查询

delphi - 如何使用 RTTI 获取数组的元素类型

windows - 在 Windows 上对 Git Bash 使用 "perl6"命令