您可以这样做但不推荐,因为这种行为必须由自己的应用程序处理。无论如何,如果你坚持是因为你有一个很好的理由这样做,我在这里留下代码来设置窗口的透明度并让一个窗口置顶,只是为了展示如何做到这一点。
透明度
您必须使用带有WS_EX_LAYERED 标志的SetWindowLong 函数和带有LWA_ALPHA 的SetLayeredWindowAttributes 函数来设置透明度。
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;