Skip to content

Commit

Permalink
Clean out remaining showing/hiding of app window, and fix taskbar pro…
Browse files Browse the repository at this point in the history
…gress.


The ShutdownBlockReason calls still pass Application.Handle for the window handle. The docs don't say what the handle is used for. Maybe to supply an icon to display with the specified text?
  • Loading branch information
jordanrussell authored Dec 15, 2024
1 parent 5682846 commit aef9408
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 48 deletions.
10 changes: 6 additions & 4 deletions Components/TaskbarProgressFunc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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.
17 changes: 1 addition & 16 deletions Projects/Src/Setup.MainFunc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions Projects/Src/Setup.RegSvr.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 }
Expand All @@ -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');
Expand Down
26 changes: 3 additions & 23 deletions Projects/Src/Setup.Uninstall.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit aef9408

Please sign in to comment.