【问题标题】:Making other applications window's translucent in Delphi在 Delphi 中使其他应用程序窗口的半透明
【发布时间】:2011-07-31 22:54:40
【问题描述】:

大家好

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

Delphi 有可能吗?我正在使用 Delphi XE 和 Lazarus。如果有人能指出我从哪里开始的大致方向,我将非常感激。

提前致谢,

【问题讨论】:

    标签: windows delphi delphi-xe lazarus translucency


    【解决方案1】:

    Windows 可以做到这一点,但应用程序没有希望稳健地做到这一点。

    【讨论】:

    • 您所要求的听起来像是一种在另一种形式上强制玻璃或 alpha 混合的方法。正如大卫所说,两者都会有问题和故障。也许在 Linux 上,如果你对 Gnome3 和 X11 (x.org) 的源代码进行了足够多的攻击,你也许可以做到这一点,但在 Windows 上却不行。
    【解决方案2】:

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

    透明度

    您必须使用带有WS_EX_LAYERED 标志的SetWindowLong 函数和带有LWA_ALPHASetLayeredWindowAttributes 函数来设置透明度。

    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;
    

    【讨论】:

    • 非常感谢您的帮助。
    猜你喜欢
    • 2015-05-02
    • 1970-01-01
    • 2021-04-10
    • 2011-10-12
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多