Новый участник
Сообщения: 41
Благодарности: 0
|
Профиль
|
Отправить PM
| Цитировать
Здравствуйте!
Помогите, пожалуйста, разобраться с функцией AnimateWindow+прозрачностью окна при перемещении.
Проблема в следующем:
1) Плавное закрытие инсталлятора при выходе - работает (или работало) на отлично!
2) Добавил прозрачность окна при перемещении - работает, но плавное закрытие окна инсталлятора при нажатии на кнопку "Отмена" работать перестаёт.
Заранее Большое Спасибо!!!
Скрипт:
Код: 
const
WM_NCLBUTTONDOWN = $00A1;
HTCAPTION = 2;
WM_NCMOUSEMOVE = $00A0;
GWL_EXSTYLE = -20;
WS_EX_LAYERED = $80000;
LWA_ALPHA = 2;
TransparentPercent = 50;
var
ComponentPage : TWizardPage;
InstallGroupBox : TNewGroupBox;
Installer : TNewRadioButton;
Portable : TNewRadioButton;
function InstallerCheck: Boolean;
begin
Result := Installer.Checked;
end;
function PortableCheck: Boolean;
begin
Result := Portable.Checked;
end;
type TGUID = record Data1: Cardinal; Data2, Data3: Word; Data4: array [0..8] of Char; end;
const PlayTask = 0;
SupportTask = 1;
var GameuxGUID: TGUID;
function GenerateGUID(var GUID: TGUID): Cardinal; external 'GenerateGUID@files:GameuxInstallHelper.dll stdcall setuponly';
function AddToGameExplorer(Binary: String; Path: String; InstallType: Integer; var GUID: TGUID): Cardinal; external 'AddToGameExplorerA@files:GameuxInstallHelper.dll stdcall setuponly';
function CreateTask(InstallType: Integer; var GUID: TGUID; TaskType: Integer; TaskNumber: Integer; TaskName: String; Binary: String; Parameters: String): Cardinal; external 'CreateTaskA@files:GameuxInstallHelper.dll stdcall setuponly';
function RetrieveGUIDForApplication(Binary: String; var GUID: TGUID): Cardinal; external 'RetrieveGUIDForApplicationA@{localappdata}\GameuxInstallHelper.dll stdcall uninstallonly';
function RemoveFromGameExplorer(var GUID: TGUID): Cardinal; external 'RemoveFromGameExplorer@{localappdata}\GameuxInstallHelper.dll stdcall uninstallonly';
function RemoveTasks(var GUID: TGUID): Cardinal; external 'RemoveTasks@{localappdata}\GameuxInstallHelper.dll stdcall uninstallonly';
procedure LoadSkin(lpszPath: String; lpszIniFileName: String); external 'LoadSkin@files:isskin.dll stdcall';
procedure UnloadSkin(); external 'UnloadSkin@files:isskin.dll stdcall';
function IntToHex(Int: Cardinal; Digits: Integer): String; var i, Digit: Integer; ch: Byte;
begin
result:='';
for i:=0 to Digits-1 do
begin
digit:=Int mod 16;
Int:=Int div 16;
if digit<0 then
digit:=digit+16;
ch:=Ord('0')+digit;
if digit>9 then
ch:=ch+7;
result:=chr(ch)+result;
end;
end;
function GetGUID(GGUID: TGUID): String; var i: Integer;
begin
result:='{'+IntToHex(GGUID.Data1, 8)+'-'+IntToHex(GGUID.Data2, 4)+'-'+IntToHex(GGUID.Data3, 4)+'-'+IntToHex(Ord(GGUID.Data4[0]), 2)+IntToHex(Ord(GGUID.Data4[1]), 2)+'-';
for i:=2 to 7 do result:=result+IntToHex(Ord(GGUID.Data4[i]), 2); result:=result+'}';
end;
procedure GDFInstall(Binary, MainExe: String);
begin
GenerateGUID(GameuxGUID);
AddToGameExplorer(ExpandConstant(Binary), ExpandConstant('{app}'), 3, GameuxGUID);
CreateTask(3, GameuxGUID, PlayTask, 0, 'Play', ExpandConstant(MainExe), '');
end;
procedure win7fix;
var regGDF: Cardinal;
var GUXPath: string;
begin
GUXPath := 'Software\Microsoft\Windows\CurrentVersion\GameUX\Games\' + GetGUID(GameuxGUID);
if isWin64 then
begin
if RegQueryDWordValue(HKLM64, GUXPath, 'IsSigned', regGDF) then
if regGDF=0 then
if RegDeleteValue(HKLM64, GUXPath, 'IsSigned') then
RegWriteDWordValue(HKLM64, GUXPath, 'IsSigned', 1);
end
else
begin
if RegQueryDWordValue(HKLM, GUXPath, 'IsSigned', regGDF) then
if regGDF=0 then
if RegDeleteValue(HKLM, GUXPath, 'IsSigned') then
RegWriteDWordValue(HKLM, GUXPath, 'IsSigned', 1);
end;
end;
type
TPBProc = function (h:hWnd;Msg,wParam,lParam:Longint):Longint;
var
TimeLeftLabel : TLabel;
PBOldProc : Longint;
eTime, sTime : DWORD;
var
BASS_Initialized: Boolean;
const
AW_BLEND = $00080000;
AW_HIDE = $00010000;
const
LOAD_LIBRARY_AS_DATAFILE = $2;
#define A = (Defined UNICODE) ? "W" : "A"
function AnimateWindow(hWnd: HWND; dwTime: DWORD; dwFlags: DWORD): Boolean;
external 'AnimateWindow@user32 stdcall';
function LoadLibraryEx(lpFileName: String; hFile: THandle; dwFlags: DWORD): THandle; external 'LoadLibraryEx{#A}@kernel32.dll stdcall';
function LoadString(hInstance: THandle; uID: SmallInt; var lpBuffer: Char; nBufferMax: Integer): Integer; external 'LoadString{#A}@user32.dll stdcall';
function SHGetNewLinkInfo(pszLinkTo, pszDir: String; var pszName: Char; var pfMustCopy: Longint; uFlags: UINT): BOOL; external 'SHGetNewLinkInfo{#A}@shell32.dll stdcall';
function PinToTaskbar(const szFilename: String; IsPin: Boolean): Boolean;
var
hInst: THandle;
buf: array [0..255] of Char;
i, res: Integer;
strLnk, strVerb: String;
objShell, colVerbs: Variant;
begin
Result := False;
if (GetWindowsVersion < $06010000) or not FileExists(szFilename) then Exit; { below Windows 7 }
{ String resources }
if IsPin then
begin
if SHGetNewLinkInfo(szFilename, ExpandConstant('{tmp}'), buf[0], res, 0) then
begin
while buf[Length(strLnk)] <> #0 do Insert(buf[Length(strLnk)], strLnk, Length(strLnk)+1);
if FileExists(ExpandConstant('{userappdata}\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\') + ExtractFileName(strLnk)) then Exit;
end;
res := 5386; { Pin to Tas&kbar }
end else res := 5387; { Unpin from Tas&kbar }
{ Load string resource }
hInst := LoadLibraryEx(ExpandConstant('{sys}\shell32.dll'), 0, LOAD_LIBRARY_AS_DATAFILE);
if hInst <> 0 then
try
for i := 0 to LoadString(hInst, res, buf[0], 255)-1 do Insert(buf[i], strVerb, i+1);
try
objShell := CreateOleObject('Shell.Application');
colVerbs := objShell.Namespace(ExtractFileDir(szFilename)).ParseName(ExtractFileName(szFilename)).Verbs;
for i := 1 to colVerbs.Count do if CompareText(colVerbs.Item[i].Name, strVerb) = 0 then
begin
colVerbs.Item[i].DoIt;
Result := True;
Break;
end;
except
Exit;
end;
finally
FreeDLL(hInst);
end;
end;
type
TTimerProc = procedure(HandleW, Msg, idEvent, TimeSys: LongWord);
var
PercentsTimer: LongWord;
PercentsLabel: TLabel;
function GetWindowLong(hWnd: HWND; nIndex: Integer): Longint; external 'GetWindowLongA@user32.dll stdcall delayload';
function SetWindowLong(hWnd: HWND; nIndex: Integer; dwNewLong: Longint): Longint; external 'SetWindowLongA@user32.dll stdcall';
function SetLayeredWindowAttributes(hwnd: HWND; crKey: TColor; bAlpha: BYTE; dwFlags: DWORD): Boolean; external 'SetLayeredWindowAttributes@user32.dll stdcall';
function CallBackProc(P:TPBProc;ParamCount:integer):LongWord; external 'wrapcallbackaddr@files:CallbackCtrl.dll stdcall';
function CallWindowProc(lpPrevWndFunc: Longint; hWnd: HWND; Msg: UINT; wParam, lParam: Longint): Longint; external 'CallWindowProcA@user32.dll stdcall';
function GetTickCount: DWORD; external 'GetTickCount@kernel32.dll stdcall';
function WrapTimerProc(callback: TTimerProc; Paramcount: Integer): longword; external 'wrapcallback@files:innocallback.dll stdcall';
function SetTimer(hWnd, nIDEvent, uElapse, lpTimerFunc: LongWord): longword; external 'SetTimer@user32';
function KillTimer(hWnd, nIDEvent: LongWord): LongWord; external 'KillTimer@user32 stdcall delayload';
procedure EnableTransparencyOnDrag(var Msg: TMsg; var Handled: Boolean);
begin
if (Msg.message = WM_NCLBUTTONDOWN) and (Msg.wParam = HTCAPTION) then
begin
SetWindowLong(WizardForm.Handle, GWL_EXSTYLE, GetWindowLong(WizardForm.Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
SetLayeredWindowAttributes(WizardForm.Handle, 0, (255 * TransparentPercent) / 100, LWA_ALPHA);
Handled := False;
end;
if Msg.message = WM_NCMOUSEMOVE then
begin
SetWindowLong(WizardForm.Handle, GWL_EXSTYLE, GetWindowLong(WizardForm.Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
SetLayeredWindowAttributes(WizardForm.Handle, 0, 255, LWA_ALPHA);
Handled := False;
end;
end;
function LongintToStringTime(t:Longint):string;
var
h,m,s:integer;
begin
h:=t div 3600;
t:=t-h*3600;
m:=t div 60;
s:=t-m*60;
Result:='';
if h>0 then Result:=Result+IntToStr(h)+' ÷. ';
if (m>0) or (h>0) then Result:=Result+IntToStr(m)+' ìèí. ';
if (m>0) or (h>0) or (s>0) then Result:=Result+IntToStr(s)+' ñåê.';
end;
function PBProc(h:hWnd;Msg,wParam,lParam:Longint):Longint;
var
lt:Longint;
dt,at,pr,i1,i2:Extended;
p:string;
tc:DWORD;
begin
Result:=CallWindowProc(PBOldProc,h,Msg,wParam,lParam);
if (Msg=$402) and (WizardForm.ProgressGauge.Position>WizardForm.ProgressGauge.Min) then begin
i1:=WizardForm.ProgressGauge.Position-WizardForm.ProgressGauge.Min;
i2:=WizardForm.ProgressGauge.Max-WizardForm.ProgressGauge.Min;
tc:=GetTickCount;
if (tc-eTime)>=1000 then begin //???????????? ????? ?????????? ?? ????? ????????? ?? ????, ??? ??? ? 1 ???????
dt:=(tc-sTime)/1000;
at:=i2*dt/i1;
lt:=Round(at-dt)
TimeLeftLabel.Caption:='Îñòàëîñü - '+LongintToStringTime(lt);
eTime:=tc;
end;
pr:=i1*100/i2;
p:=' - ['+Format('%f',[pr])+'%]';
StringChange(p,',','.');
end;
end;
procedure AllCancel;
begin
SetWindowLong(WizardForm.ProgressGauge.Handle,-4,PBOldProc);
TimeLeftLabel.Free;
end;
function InitializeSetup:boolean;
begin
ExtractTemporaryFile('steam.cjstyles');
if not FileExists(ExpandConstant('{tmp}\CallbackCtrl.dll')) then ExtractTemporaryFile('CallbackCtrl.dll');
LoadSkin(ExpandConstant('{tmp}')+'\steam.cjstyles', '');
Result:=True;
end;
Function NumToStr(Float: Extended): String;
Begin
Result:= Format('%.1n', [Float]); StringChange(Result, ',', '.');
while ((Result[Length(Result)] = '0') or (Result[Length(Result)] = '.')) and (Pos('.', Result) > 0) do
SetLength(Result, Length(Result)-1);
End;
Procedure PercentsProc(h, msg, idevent, dwTime: Longword);
Begin
with WizardForm.ProgressGauge do
begin
PercentsLabel.Caption:= 'Âûïîëíåíî ' + NumToStr((Position*100)/Max) + ' %';
end;
End;
const
Indent=25;
function ssInitialize(hParent:HWND;ssTimeShow:integer;FadeOut:boolean;StretchMode:integer;BkgColor:DWORD):boolean; external 'ssInitialize@files:isgsg.dll stdcall delayload';
procedure ssDeInitialize; external 'ssDeInitialize@files:isgsg.dll stdcall delayload';
procedure ssSetBkgImage(FileName:PChar); external 'ssSetBkgImage@files:isgsg.dll stdcall delayload';
procedure ssAddImage(FileName:PChar); external 'ssAddImage@files:isgsg.dll stdcall delayload';
procedure ssStartShow; external 'ssStartShow@files:isgsg.dll stdcall delayload';
procedure ssStopShow; external 'ssStopShow@files:isgsg.dll stdcall delayload';
procedure ShowSplashScreen(p1:HWND;p2:string;p3,p4,p5,p6,p7:integer;p8:boolean;p9:Cardinal;p10:integer); external 'ShowSplashScreen@files:isgsg.dll stdcall delayload';
function GetSystemMetrics(nIndex:Integer):integer; external 'GetSystemMetrics@user32.dll stdcall delayload';
procedure RunListClickCheck(Sender: TObject);
var
i:integer;
begin
if WizardForm.RunList.Checked[WizardForm.RunList.ItemIndex] then begin
for i:=0 to WizardForm.RunList.Items.Count-1 do
WizardForm.RunList.Checked[i]:=False;
WizardForm.RunList.Checked[WizardForm.RunList.ItemIndex]:=True;
end;
end;
procedure InitializeWizard();
begin
Application.OnMessage:=@EnableTransparencyOnDrag;
begin
ComponentPage := CreateCustomPage(wpInfoBefore, 'Âûáîð âåðñèè èãðû', 'Ïîæàëóéñòà, ñäåëàéòå âûáîð ïåðåä òåì, êàê ïðîäîëæèòü.');
{ InstallGroupBox }
InstallGroupBox := TNewGroupBox.Create(WizardForm);
with InstallGroupBox do
begin
Parent := ComponentPage.Surface;
SetBounds(ScaleX(0),ScaleY(0),ScaleX(63),ScaleY(70));
Caption := 'Version:';
end;
{ Installer }
Installer := TNewRadioButton.Create(WizardForm);
with Installer do
begin
Parent := ComponentPage.Surface;
SetBounds(ScaleX(9),ScaleY(19),ScaleX(45),ScaleY(17));
Caption := '32-bit';
end;
{ Portable }
Portable := TNewRadioButton.Create(WizardForm);
with Portable do
begin
Parent := ComponentPage.Surface;
SetBounds(ScaleX(9),ScaleY(43),ScaleX(45),ScaleY(17));
Caption := '64-bit';
Checked := True;
end;
begin
ExtractTemporaryFile('Bass.dll');
ExtractTemporaryFile('botva2.dll');
ExtractTemporaryFile('volmax.png');
ExtractTemporaryFile('volmin.png');
ExtractTemporaryFile('volpb.png');
ExtractTemporaryFile('voldote.png');
ExtractTemporaryFile('Music.mp3');
ExtractTemporaryFile('MusicButton.png');
ExtractTemporaryFile('EG.png');
ShowSplashScreen(WizardForm.Handle,ExpandConstant('{tmp}')+'\EG.png',5000,4000,3000,0,255,False,$FFFFFF,10);
ssInitialize(GetWindowLong(MainForm.Handle,-8),18,True,2,$FF000000);
WizardForm.RunList.OnClickCheck:=@RunListClickCheck;
BASS_Init('{tmp}\Music.mp3')
BASS_CreateMediaPlayer(WizardForm, '{tmp}\volmax.png', '{tmp}\volmin.png', '{tmp}\volpb.png', '{tmp}\voldote.png', 20, 325)
BASS_Initialized := True;
ExtractTemporaryFile('0.png');
ssSetBkgImage(ExpandConstant('{tmp}')+'\0.png');
WizardForm.TypesCombo.ItemIndex:=0;
PercentsLabel:= TLabel.Create(WizardForm);
with PercentsLabel do
begin
Left:= WizardForm.ProgressGauge.Left;
Top:= WizardForm.ProgressGauge.Top + WizardForm.ProgressGauge.Height + ScaleY(10);
Width:= WizardForm.StatusLabel.Width;
Height:= WizardForm.StatusLabel.Height;
AutoSize:= False;
Transparent := True;
Parent:= WizardForm.InstallingPage;
end;
end;
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
var Version: TWindowsVersion;
begin
GetWindowsVersionEx(Version);
if (CurStep = ssPostInstall) and Version.NTPlatform and (Version.Major > 5) then begin
GDFInstall('{#GDFBinary}', '{#GDFExe}');
win7fix;
end;
begin
case CurStep of
ssInstall: begin
TimeLeftLabel:=TLabel.Create(nil);
with TimeLeftLabel do begin
Parent:=WizardForm.InstallingPage;
AutoSize:=True;
SetBounds(WizardForm.ProgressGauge.Left + ScaleX(250),WizardForm.ProgressGauge.Top + ScaleY(30),ScaleY(80),ScaleY(21));
end;
sTime:=GetTickCount;
eTime:=sTime;
PBOldProc:=SetWindowLong(WizardForm.ProgressGauge.Handle,-4,CallBackProc(@PBProc,4));
end;
ssPostInstall: AllCancel;
end;
begin
if CurStep=ssInstall then begin
ExtractTemporaryFile('1.png');
ssAddImage(ExpandConstant('{tmp}')+'\1.png');
ExtractTemporaryFile('2.png');
ssAddImage(ExpandConstant('{tmp}')+'\2.png');
ExtractTemporaryFile('3.png');
ssAddImage(ExpandConstant('{tmp}')+'\3.png');
ExtractTemporaryFile('4.png');
ssAddImage(ExpandConstant('{tmp}')+'\4.png');
ExtractTemporaryFile('5.png');
ssAddImage(ExpandConstant('{tmp}')+'\5.png');
ExtractTemporaryFile('6.png');
ssAddImage(ExpandConstant('{tmp}')+'\6.png');
ExtractTemporaryFile('7.png');
ssAddImage(ExpandConstant('{tmp}')+'\7.png');;
ExtractTemporaryFile('8.png');
ssAddImage(ExpandConstant('{tmp}')+'\8.png');
ExtractTemporaryFile('9.png');
ssAddImage(ExpandConstant('{tmp}')+'\9.png');
ExtractTemporaryFile('10.png');
ssAddImage(ExpandConstant('{tmp}')+'\10.png');
PercentsTimer:= SetTimer(0, 0, 100, WrapTimerProc(@PercentsProc, 4));
ExtractTemporaryFile('0.png');
ssAddImage(ExpandConstant('{tmp}')+'\0.png');
ssStartShow;
end;
if CurStep=ssPostInstall then ssStopShow;
end;
end;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
case CurPageID of
wpFinished: end
if IsTaskSelected('Pin') then
PinToTaskbar(ExpandConstant('{app}\Eternal Darkness-Sanitys Requiem.exe'), True);
if CurPageID=wpInstalling then begin;
WizardForm.MainPanel.Visible:=False;
WizardForm.Bevel1.Visible:=False;
WizardForm.Width:=ScaleX(395);
WizardForm.Height:=ScaleY(142);
WizardForm.Left:=ScaleX(GetSystemMetrics(0)-WizardForm.Width-Indent);
WizardForm.Top:=ScaleY(GetSystemMetrics(1)-WizardForm.Height-Indent);
WizardForm.InnerNotebook.Left:=ScaleX(10);
WizardForm.InnerNotebook.Top:=ScaleY(10);
WizardForm.InnerNotebook.Width:=ScaleX(370);
WizardForm.StatusLabel.Left:=ScaleX(0);
WizardForm.StatusLabel.Top:=ScaleY(0);
WizardForm.StatusLabel.Width:=WizardForm.InnerNotebook.Width;
WizardForm.FileNameLabel.Left:=ScaleX(0);
WizardForm.FileNameLabel.Top:=ScaleY(20);
WizardForm.FileNameLabel.Width:=WizardForm.InnerNotebook.Width;
WizardForm.ProgressGauge.Top:=ScaleY(40);
WizardForm.ProgressGauge.Width:=WizardForm.InnerNotebook.Width;
WizardForm.CancelButton.Left:=ScaleX(154);
WizardForm.CancelButton.Top:=ScaleY(80);
end;
if (CurPageID=wpFinished) or (CurPageID=wpInfoAfter) then begin
WizardForm.RunList.Checked[0]:=True;
if WizardForm.Width<>502 then begin
WizardForm.Visible:=False;
WizardForm.Width:=ScaleX(502);
WizardForm.Height:=ScaleY(392);
WizardForm.Left:=(GetSystemMetrics(0)-WizardForm.Width) div 2;
WizardForm.Top:=(GetSystemMetrics(1)-WizardForm.Height) div 2;
WizardForm.MainPanel.Visible:=True;
WizardForm.Bevel1.Visible:=True;
WizardForm.InnerNotebook.Left:=ScaleX(40);
WizardForm.InnerNotebook.Top:=ScaleY(72);
WizardForm.InnerNotebook.Width:=ScaleX(417);
WizardForm.Visible:=True;
end;
end;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := True;
if CurPageID=wpFinished then
begin
if WizardForm.RunList.Checked[0] then
Result := True;
end;
end;
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
if MsgBox(SetupMessage(msgExitSetupMessage), mbConfirmation, MB_OKCANCEL) = IDOK then
begin
Confirm := False;
AnimateWindow(WizardForm.Handle, 2500, AW_BLEND or AW_HIDE);
Cancel := True;
end else
Cancel := False;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
Binary: String;
GUID: TGUID;
begin
if CurUninstallStep=usUninstall then
begin
Binary:=ExpandConstant('{#GDFBinary}');
RetrieveGUIDForApplication(Binary, GUID);
RemoveFromGameExplorer(GUID);
RemoveTasks(GUID);
UnloadDll(ExpandConstant('{localappdata}\GameuxInstallHelper.dll'));
end;
begin
if (CurUninstallStep=usUninstall) then
begin
case CurUninstallStep of
usUninstall: begin
PinToTaskbar(ExpandConstant('{app}\Eternal Darkness-Sanitys Requiem.exe'), False);
end;
end;
end;
end;
end;
procedure DeinitializeSetup();
begin
if BASS_Initialized then
begin
KillTimer(0, PercentsTimer);
UnloadSkin();
ssDeInitialize;
BASS_DeInit;
gdipShutdown
end;
end;
|