Pārlūkot izejas kodu

Clean out remaining showing/hiding of app window, and fix taskbar progress.

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?

Jordan Russell 7 mēneši atpakaļ
vecāks
revīzija
aef9408ff2

+ 6 - 4
Components/TaskbarProgressFunc.pas

@@ -48,14 +48,16 @@ const
   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.

+ 1 - 16
Projects/Src/Setup.MainFunc.pas

@@ -2389,14 +2389,6 @@ begin
   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 @@ var
     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 @@ begin
     { 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 @@ begin
     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;

+ 1 - 5
Projects/Src/Setup.RegSvr.pas

@@ -119,9 +119,7 @@ begin
 
   { 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 @@ begin
     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 @@ begin
     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');

+ 3 - 23
Projects/Src/Setup.Uninstall.pas

@@ -349,19 +349,9 @@ begin
   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 @@ begin
   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 @@ begin
       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);