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