diff --git a/Components/TaskbarProgressFunc.pas b/Components/TaskbarProgressFunc.pas index cb988d79..3de90c54 100644 --- a/Components/TaskbarProgressFunc.pas +++ b/Components/TaskbarProgressFunc.pas @@ -48,14 +48,16 @@ procedure SetAppTaskbarProgressState(const State: TTaskbarProgressState); StateFlags: array[TTaskbarProgressState] of Integer = ( TBPF_NOPROGRESS, TBPF_INDETERMINATE, TBPF_NORMAL, TBPF_ERROR, TBPF_PAUSED); begin - if InitializeTaskbarList then - TaskbarListInterface.SetProgressState(Application.Handle, StateFlags[State]); + if InitializeTaskbarList and Assigned(Application.MainForm) and + Application.MainForm.HandleAllocated then + TaskbarListInterface.SetProgressState(Application.MainForm.Handle, StateFlags[State]); end; procedure SetAppTaskbarProgressValue(const Completed, Total: Cardinal); begin - if InitializeTaskbarList then - TaskbarListInterface.SetProgressValue(Application.Handle, Completed, Total); + if InitializeTaskbarList and Assigned(Application.MainForm) and + Application.MainForm.HandleAllocated then + TaskbarListInterface.SetProgressValue(Application.MainForm.Handle, Completed, Total); end; end. diff --git a/Projects/Src/Setup.MainFunc.pas b/Projects/Src/Setup.MainFunc.pas index bbc4380c..c30616ad 100644 --- a/Projects/Src/Setup.MainFunc.pas +++ b/Projects/Src/Setup.MainFunc.pas @@ -2389,14 +2389,6 @@ procedure RestartComputerFromThisProcess; RestartInitiatedByThisProcess := True; { Note: Depending on the OS, RestartComputer may not return if successful } if not RestartComputer then begin - { Hack for when called from RespawnSetupElevated: re-show the - application's taskbar button } - ShowWindow(Application.Handle, SW_SHOW); - { If another app denied the shutdown, we probably lost the foreground; - try to take it back. (Note: Application.BringToFront can't be used - because we have no visible forms, and MB_SETFOREGROUND doesn't make - the app's taskbar button blink.) } - SetForegroundWindow(Application.Handle); LoggedMsgBox(SetupMessages[msgErrorRestartingComputer], '', mbError, MB_OK, True, IDOK); end; @@ -2415,9 +2407,6 @@ procedure RespawnSetupElevated(const AParams: String); NotifyNewLanguage: Integer; end; begin - { Hide the taskbar button } - SetWindowPos(Application.Handle, 0, 0, 0, 0, 0, SWP_NOSIZE or - SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or SWP_HIDEWINDOW); Cancelled := False; try Server := TSpawnServer.Create; @@ -2438,11 +2427,8 @@ procedure RespawnSetupElevated(const AParams: String); { If the user clicked Cancel on the dialog, halt with special exit code } if ExceptObject is EAbort then Cancelled := True - else begin - { Otherwise, re-show the taskbar button and re-raise } - ShowWindow(Application.Handle, SW_SHOW); + else raise; - end; end; if Cancelled then Halt(ecCancelledBeforeInstall); @@ -2461,7 +2447,6 @@ procedure RespawnSetupElevated(const AParams: String); except { In the unlikely event that something above raises an exception, handle it here so the right exit code will still be returned below } - ShowWindow(Application.Handle, SW_SHOW); Application.HandleException(nil); end; end; diff --git a/Projects/Src/Setup.RegSvr.pas b/Projects/Src/Setup.RegSvr.pas index ed155905..a2e41f49 100644 --- a/Projects/Src/Setup.RegSvr.pas +++ b/Projects/Src/Setup.RegSvr.pas @@ -119,9 +119,7 @@ procedure RunRegSvr; { Set default title; it's set again below after the messages are read } Application.Title := 'Setup'; - { This is needed for D3+: Must force the application window visible since - we aren't displaying any forms } - ShowWindow(Application.Handle, SW_SHOW); + Application.MainFormOnTaskBar := True; InitializeCommonVars; @@ -133,7 +131,6 @@ procedure RunRegSvr; registry entries be in an incomplete/inconsistent state? I'm not sure, so a mutex is used here to ensure registrations are serialized. } Mutex := Windows.CreateMutex(nil, False, 'Inno-Setup-RegSvr-Mutex'); - ShowWindow(Application.Handle, SW_HIDE); { hide taskbar button while waiting } if Mutex <> 0 then begin { Even though we have no visible windows, process messages while waiting so Windows doesn't think we're hung } @@ -142,7 +139,6 @@ procedure RunRegSvr; until MsgWaitForMultipleObjects(1, Mutex, False, INFINITE, QS_ALLINPUT) <> WAIT_OBJECT_0+1; end; - ShowWindow(Application.Handle, SW_SHOW); try MsgFilename := PathChangeExt(NewParamStr(0), '.msg'); ListFilename := PathChangeExt(NewParamStr(0), '.lst'); diff --git a/Projects/Src/Setup.Uninstall.pas b/Projects/Src/Setup.Uninstall.pas index 26bdb54e..a01ad046 100644 --- a/Projects/Src/Setup.Uninstall.pas +++ b/Projects/Src/Setup.Uninstall.pas @@ -349,19 +349,9 @@ function RespawnFirstPhaseIfNeeded: Boolean; RequireAdmin := (ufAdminInstalled in Flags) or (ufPowerUserInstalled in Flags); if NeedToRespawnSelfElevated(RequireAdmin, False) then begin - { Hide the taskbar button } - SetWindowPos(Application.Handle, 0, 0, 0, 0, 0, SWP_NOSIZE or - SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or SWP_HIDEWINDOW); - try - RespawnSelfElevated(UninstExeFilename, - Format('/INITPROCWND=$%x ', [Application.Handle]) + GetCmdTail, - UninstallExitCode); - except - { Re-show the taskbar button and re-raise } - if not(ExceptObject is EAbort) then - ShowWindow(Application.Handle, SW_SHOW); - raise; - end; + RespawnSelfElevated(UninstExeFilename, + Format('/INITPROCWND=$%x ', [Application.Handle]) + GetCmdTail, + UninstallExitCode); Result := True; end; end; @@ -402,11 +392,6 @@ procedure RunFirstPhase; Longint(OldWindowProc) := SetWindowLong(Wnd, GWL_WNDPROC, Longint(@FirstPhaseWindowProc)); try - { Hide the application window so that we don't end up with two taskbar - buttons once the second phase starts } - SetWindowPos(Application.Handle, 0, 0, 0, 0, 0, SWP_NOSIZE or - SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or SWP_HIDEWINDOW); - { Execute the copy of itself ("second phase") } ProcessHandle := Exec(TempFile, Format('/SECONDPHASE="%s" /FIRSTPHASEWND=$%x ', [NewParamStr(0), Wnd]) + GetCmdTail); @@ -733,11 +718,6 @@ procedure RunSecondPhase; Log('Restarting Windows.'); RestartInitiatedByThisProcess := True; if not RestartComputer then begin - { If another app denied the shutdown, we probably lost the foreground; - try to take it back. (Note: Application.BringToFront can't be used - because we have no visible forms, and MB_SETFOREGROUND doesn't make - the app's taskbar button blink.) } - SetForegroundWindow(Application.Handle); LoggedAppMessageBox(PChar(SetupMessages[msgErrorRestartingComputer]), PChar(SetupMessages[msgErrorTitle]), MB_OK or MB_ICONEXCLAMATION, True, IDOK);