Prechádzať zdrojové kódy

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 8 mesiacov pred
rodič
commit
aef9408ff2

+ 6 - 4
Components/TaskbarProgressFunc.pas

@@ -48,14 +48,16 @@ const
   StateFlags: array[TTaskbarProgressState] of Integer = (
   StateFlags: array[TTaskbarProgressState] of Integer = (
     TBPF_NOPROGRESS, TBPF_INDETERMINATE, TBPF_NORMAL, TBPF_ERROR, TBPF_PAUSED);
     TBPF_NOPROGRESS, TBPF_INDETERMINATE, TBPF_NORMAL, TBPF_ERROR, TBPF_PAUSED);
 begin
 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;
 end;
 
 
 procedure SetAppTaskbarProgressValue(const Completed, Total: Cardinal);
 procedure SetAppTaskbarProgressValue(const Completed, Total: Cardinal);
 begin
 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;
 
 
 end.
 end.

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

@@ -2389,14 +2389,6 @@ begin
   RestartInitiatedByThisProcess := True;
   RestartInitiatedByThisProcess := True;
   { Note: Depending on the OS, RestartComputer may not return if successful }
   { Note: Depending on the OS, RestartComputer may not return if successful }
   if not RestartComputer then begin
   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,
     LoggedMsgBox(SetupMessages[msgErrorRestartingComputer], '', mbError,
       MB_OK, True, IDOK);
       MB_OK, True, IDOK);
   end;
   end;
@@ -2415,9 +2407,6 @@ var
     NotifyNewLanguage: Integer;
     NotifyNewLanguage: Integer;
   end;
   end;
 begin
 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;
   Cancelled := False;
   try
   try
     Server := TSpawnServer.Create;
     Server := TSpawnServer.Create;
@@ -2438,11 +2427,8 @@ begin
     { If the user clicked Cancel on the dialog, halt with special exit code }
     { If the user clicked Cancel on the dialog, halt with special exit code }
     if ExceptObject is EAbort then
     if ExceptObject is EAbort then
       Cancelled := True
       Cancelled := True
-    else begin
-      { Otherwise, re-show the taskbar button and re-raise }
-      ShowWindow(Application.Handle, SW_SHOW);
+    else
       raise;
       raise;
-    end;
   end;
   end;
   if Cancelled then
   if Cancelled then
     Halt(ecCancelledBeforeInstall);
     Halt(ecCancelledBeforeInstall);
@@ -2461,7 +2447,6 @@ begin
     except
     except
       { In the unlikely event that something above raises an exception, handle
       { In the unlikely event that something above raises an exception, handle
         it here so the right exit code will still be returned below }
         it here so the right exit code will still be returned below }
-      ShowWindow(Application.Handle, SW_SHOW);
       Application.HandleException(nil);
       Application.HandleException(nil);
     end;
     end;
   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 }
   { Set default title; it's set again below after the messages are read }
   Application.Title := 'Setup';
   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;
   InitializeCommonVars;
 
 
@@ -133,7 +131,6 @@ begin
     registry entries be in an incomplete/inconsistent state? I'm not sure, so
     registry entries be in an incomplete/inconsistent state? I'm not sure, so
     a mutex is used here to ensure registrations are serialized. }
     a mutex is used here to ensure registrations are serialized. }
   Mutex := Windows.CreateMutex(nil, False, 'Inno-Setup-RegSvr-Mutex');
   Mutex := Windows.CreateMutex(nil, False, 'Inno-Setup-RegSvr-Mutex');
-  ShowWindow(Application.Handle, SW_HIDE);  { hide taskbar button while waiting }
   if Mutex <> 0 then begin
   if Mutex <> 0 then begin
     { Even though we have no visible windows, process messages while waiting
     { Even though we have no visible windows, process messages while waiting
       so Windows doesn't think we're hung }
       so Windows doesn't think we're hung }
@@ -142,7 +139,6 @@ begin
     until MsgWaitForMultipleObjects(1, Mutex, False, INFINITE,
     until MsgWaitForMultipleObjects(1, Mutex, False, INFINITE,
       QS_ALLINPUT) <> WAIT_OBJECT_0+1;
       QS_ALLINPUT) <> WAIT_OBJECT_0+1;
   end;
   end;
-  ShowWindow(Application.Handle, SW_SHOW);
   try
   try
     MsgFilename := PathChangeExt(NewParamStr(0), '.msg');
     MsgFilename := PathChangeExt(NewParamStr(0), '.msg');
     ListFilename := PathChangeExt(NewParamStr(0), '.lst');
     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);
   RequireAdmin := (ufAdminInstalled in Flags) or (ufPowerUserInstalled in Flags);
 
 
   if NeedToRespawnSelfElevated(RequireAdmin, False) then begin
   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;
     Result := True;
   end;
   end;
 end;
 end;
@@ -402,11 +392,6 @@ begin
   Longint(OldWindowProc) := SetWindowLong(Wnd, GWL_WNDPROC,
   Longint(OldWindowProc) := SetWindowLong(Wnd, GWL_WNDPROC,
     Longint(@FirstPhaseWindowProc));
     Longint(@FirstPhaseWindowProc));
   try
   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") }
     { Execute the copy of itself ("second phase") }
     ProcessHandle := Exec(TempFile, Format('/SECONDPHASE="%s" /FIRSTPHASEWND=$%x ',
     ProcessHandle := Exec(TempFile, Format('/SECONDPHASE="%s" /FIRSTPHASEWND=$%x ',
       [NewParamStr(0), Wnd]) + GetCmdTail);
       [NewParamStr(0), Wnd]) + GetCmdTail);
@@ -733,11 +718,6 @@ begin
       Log('Restarting Windows.');
       Log('Restarting Windows.');
       RestartInitiatedByThisProcess := True;
       RestartInitiatedByThisProcess := True;
       if not RestartComputer then begin
       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]),
         LoggedAppMessageBox(PChar(SetupMessages[msgErrorRestartingComputer]),
           PChar(SetupMessages[msgErrorTitle]), MB_OK or MB_ICONEXCLAMATION,
           PChar(SetupMessages[msgErrorTitle]), MB_OK or MB_ICONEXCLAMATION,
           True, IDOK);
           True, IDOK);