diff --git a/source/forms/CustomScpExplorer.cpp b/source/forms/CustomScpExplorer.cpp index eaa8fd366..8bfaae0d0 100644 --- a/source/forms/CustomScpExplorer.cpp +++ b/source/forms/CustomScpExplorer.cpp @@ -7886,7 +7886,7 @@ void __fastcall TCustomScpExplorerForm::WMQueryEndSession(TMessage & Message) void __fastcall TCustomScpExplorerForm::WMEndSession(TWMEndSession & Message) { AppLog(L"Windows session end"); - if (Message.EndSession && IsApplicationMinimized()) + if (Message.EndSession && IsMainFormMinimized()) { // WORKAROUND // TApplication.WndProc() calls Application.Terminate() before Halt(), @@ -8182,7 +8182,7 @@ void __fastcall TCustomScpExplorerForm::QueueEvent(TManagedTerminal * ATerminal, UnicodeString Message; TNotifyEvent OnClick = NULL; TObject * UserData = NULL; - bool QueueInvisible = !ComponentVisible[fcQueueView] || IsApplicationMinimized(); + bool QueueInvisible = !ComponentVisible[fcQueueView] || IsMainFormMinimized(); switch (Event) { case qeEmptyButMonitored: @@ -10571,7 +10571,7 @@ void __fastcall TCustomScpExplorerForm::LockWindow(bool Force) // minimize is no longer possible // ("keep up to date" dialog - though does not seem to be the case with "find file" - // so it has probably something to do with the semi-modalness of the "keep up to date" dialog) - // Shouldn't we use IsApplicationMinimized() here? + // Shouldn't we use IsMainFormMinimized() here? if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this))) { AppLog(L"Disabling window"); diff --git a/source/forms/Progress.cpp b/source/forms/Progress.cpp index 11602f18f..876166778 100644 --- a/source/forms/Progress.cpp +++ b/source/forms/Progress.cpp @@ -115,7 +115,7 @@ __fastcall TProgressForm::~TProgressForm() ClearGlobalMinimizeHandler(GlobalMinimize); - if (IsApplicationMinimized() && FMinimizedByMe) + if (IsMainFormMinimized() && FMinimizedByMe) { ShowNotification( NULL, MainInstructions(LoadStr(BALLOON_OPERATION_COMPLETE)), @@ -408,7 +408,7 @@ bool __fastcall TProgressForm::ReceiveData(bool Force, int ModalLevelOffset) // Delay showing the progress until the application is restored, // otherwise the form popups up unminimized. // See solution in TMessageForm::CMShowingChanged. - if (!IsApplicationMinimized() && + if (!IsMainFormMinimized() && (Force || (MilliSecondsBetween(Now(), FStarted) > DelayStartInterval))) { FDataReceived = true; diff --git a/source/forms/Synchronize.cpp b/source/forms/Synchronize.cpp index bba7fb4bd..58f33e497 100644 --- a/source/forms/Synchronize.cpp +++ b/source/forms/Synchronize.cpp @@ -514,7 +514,7 @@ void __fastcall TSynchronizeDialog::Stop() OnlyStop(); UpdateControls(); Repaint(); - if (IsApplicationMinimized() && FMinimizedByMe) + if (IsMainFormMinimized() && FMinimizedByMe) { FMinimizedByMe = false; ApplicationRestore(); diff --git a/source/forms/SynchronizeProgress.cpp b/source/forms/SynchronizeProgress.cpp index 1f9aa40fb..6e2ad6a54 100644 --- a/source/forms/SynchronizeProgress.cpp +++ b/source/forms/SynchronizeProgress.cpp @@ -55,7 +55,7 @@ __fastcall TSynchronizeProgressForm::~TSynchronizeProgressForm() ReleaseAsModal(this, FShowAsModalStorage); UnhookFormActivation(this); - if (IsApplicationMinimized() && FMinimizedByMe) + if (IsMainFormMinimized() && FMinimizedByMe) { ShowNotification( NULL, MainInstructions(LoadStr(BALLOON_OPERATION_COMPLETE)), @@ -71,7 +71,7 @@ void __fastcall TSynchronizeProgressForm::Start() StartTimeLabel->Caption = FStartTime.TimeString(); OperationProgress->Position = OperationProgress->Min; UpdateControls(); - if (!IsApplicationMinimized()) + if (!IsMainFormMinimized()) { // Do not show the progress when the application is minimized, // otherwise the form popups up unminimized. diff --git a/source/windows/TerminalManager.cpp b/source/windows/TerminalManager.cpp index 760a37e70..c7800ad82 100644 --- a/source/windows/TerminalManager.cpp +++ b/source/windows/TerminalManager.cpp @@ -1026,7 +1026,7 @@ void __fastcall TTerminalManager::QueueStatusUpdated() //--------------------------------------------------------------------------- bool __fastcall TTerminalManager::ShouldDisplayQueueStatusOnAppTitle() { - bool Result = IsApplicationMinimized(); + bool Result = IsMainFormMinimized(); if (!Result && (ScpExplorer != NULL)) { HWND Window = GetActiveWindow(); diff --git a/source/windows/WinInterface.cpp b/source/windows/WinInterface.cpp index 2d359e373..573997369 100644 --- a/source/windows/WinInterface.cpp +++ b/source/windows/WinInterface.cpp @@ -1391,16 +1391,22 @@ void __fastcall ApplicationRestore() DoApplicationMinimizeRestore(false); } //--------------------------------------------------------------------------- -bool __fastcall IsApplicationMinimized() +bool IsMainFormMinimized() { // VCL help recommends handling Application->OnMinimize/OnRestore // for tracking state, but OnRestore is actually not called - // (OnMinimize is), when app is minimized from e.g. Progress window + // (OnMinimize is), when app is minimized from e.g. Progress window. + // Checking Application->Handle might be obsolete. bool AppMinimized = IsIconic(Application->Handle); bool MainFormMinimized = IsIconic(Application->MainFormHandle); return AppMinimized || MainFormMinimized; } //--------------------------------------------------------------------------- +bool IsApplicationMinimized() +{ + return (Screen->ActiveForm != nullptr) && IsIconic(Screen->ActiveForm->Handle); +} +//--------------------------------------------------------------------------- bool __fastcall HandleMinimizeSysCommand(TMessage & Message) { TWMSysCommand & SysCommand = reinterpret_cast(Message); diff --git a/source/windows/WinInterface.h b/source/windows/WinInterface.h index 39b2097a5..ad0cb97c9 100644 --- a/source/windows/WinInterface.h +++ b/source/windows/WinInterface.h @@ -537,7 +537,8 @@ int __fastcall AdjustLocaleFlag(const UnicodeString & S, TLocaleFlagOverride Loc void __fastcall SetGlobalMinimizeHandler(TCustomForm * Form, TNotifyEvent OnMinimize); void __fastcall ClearGlobalMinimizeHandler(TNotifyEvent OnMinimize); void __fastcall CallGlobalMinimizeHandler(TObject * Sender); -bool __fastcall IsApplicationMinimized(); +bool IsMainFormMinimized(); +bool IsApplicationMinimized(); void __fastcall ApplicationMinimize(); void __fastcall ApplicationRestore(); bool __fastcall HandleMinimizeSysCommand(TMessage & Message);