必須是在Windows2000以下的系統才支持SetLayeredWindowAttributes這個API,原理就是先找到窗口句柄,然後設置窗口屬性
program opacity;
{$APPTYPE CONSOLE}
uses
SysUtils,
Windows;
var
handle,AStyle:integer;
begin
try
if ParamCount<2 then
begin
Writeln('parameter must');
exit;
end;
handle:=findwindow(nil,pchar(ParamStr(1)));//目前是找窗口的Text,也可以是找ClassName
AStyle := GetWindowLong(Handle, GWL_EXSTYLE);
SetWindowLong(Handle, GWL_EXSTYLE, AStyle or WS_EX_LAYERED);
if SetLayeredWindowAttributes(Handle, 0, strtoint(ParamStr(2)),LWA_ALPHA) then
Writeln(ParamStr(1)+' update successed to '+ParamStr(2))
else
Writeln('Opacity update failed');
except
Writeln('parameter error');
end;
end.