Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-04

How to minimize application showing modal form(s)

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Frank Poretzky

Hi!

In an SDI application I open a modal form with .ShowModal and from there a dialog window with Dialogs.MessageDlg().

Now, when I call Application.Minimize with a TrayIcon.OnClick() event the main form and the message dialog disappear, whereas my custom modal form in-between remains visible.

Is there a way to modify my modal form to get it minimized as well?

object FormModal: TFormModal
Left = 372
Height = 159
Top = 162
Width = 297
Caption = 'Modal Form'
ClientHeight = 159
ClientWidth = 297
LCLVersion = '1.0.14.0'
object B_MsgDlg: TButton
Left = 72
Height = 25
Top = 60
Width = 147
Caption = 'Open Message Dialog'
OnClick = DoOnClickMsgDlg
TabOrder = 0

  end

end

Lazarus 1.0.14 / FPC 2.6.2 / SVN Rev 43446 / i386-win32-win32/win64

Thanks

Frank

Reply by email

zeljko
to Frank Poretzky
Frank Poretzky wrote 32 lines
Hi! In an SDI application I open a modal form with .ShowModal and from there a dialog window with Dialogs.MessageDlg(). Now, when I call Application.Minimize with a TrayIcon.OnClick() event the main form and the message dialog disappear, whereas my custom modal form in-between remains visible. Is there a way to modify my modal form to get it minimized as well? object FormModal: TFormModal Left = 372 Height = 159 Top = 162 Width = 297 Caption = 'Modal Form' ClientHeight = 159 ClientWidth = 297 LCLVersion = '1.0.14.0' object B_MsgDlg: TButton Left = 72 Height = 25 Top = 60 Width = 147 Caption = 'Open Message Dialog' OnClick = DoOnClickMsgDlg TabOrder = 0 end end Lazarus 1.0.14 / FPC 2.6.2 / SVN Rev 43446 / i386-win32-win32/win64

Application.Minimize should minimize all visible forms of application. If it doesn't work so it could be the bug, also it could be fixed in trunk.

zeljko

Reply by email

Howard Page-Clark
to Frank Poretzky: Hi! In an SDI application I open a modal form with .ShowModal and from there a dialog…
Frank Poretzky wrote
Is there a way to modify my modal form to get it minimized as well?

Create your modal form with the main form as its owner, and give it a unique your main form's declaration set up two Application handlers, OnMinimize and OnRestore (of type TNotifyEvent), and hook them up in your main form's OnCreate code.
In the OnMinimize and OnRestore handler implementations use FindComponent (or some other means) to locate your previously named modal form, and either Hide it or Show it as appropriate.

Howard

Reply by email

Frank Poretzky
to Howard Page-Clark

Hi Howard,

you wrote 11 lines
On 12/04/2014 17:06, Frank Poretzky wrote: > Is there a way to modify my modal form to get it minimized as well? Create your modal form with the main form as its owner, and give it a unique Name at creation. In your main form's declaration set up two Application handlers, OnMinimize and OnRestore (of type TNotifyEvent), and hook them up in your main form's OnCreate code. In the OnMinimize and OnRestore handler implementations use FindComponent (or some other means) to locate your previously named modal form, and either Hide it or Show it as appropriate.

Apart from FindComponent, which makes an application with lots of modal windows very complex, I tried various versions of

procedure TFormMain.AppOnRestore( Sender: TObject);
  var
    posit : integer;
  begin
    for posit := 0 to Screen.FormCount - 1 do
      begin
        if Screen.Forms[ posit].WindowState = wsMinimized
        // if Screen.Forms[ posit].FormState  [fsFirstShow]
          then
            Screen.Forms[ posit].WindowState := wsNormal;
            // Screen.Forms[ posit].Show; //
      end;
  end;

with a corresponding AppOnMinimize() procedure. None of them worked well, especially with the modal sub-sub-form scenario described above.

Many thanks

Frank

Reply by email

Howard Page-Clark
to Frank Poretzky
Frank Poretzky wrote 5 lines
Apart from FindComponent, which makes an application with lots of modal windows very complex, I tried various versions of ... with a corresponding AppOnMinimize() procedure. None of them worked well, especially with the modal sub-sub-form scenario described above.

As Zeljko pointed out, you have uncovered a bug. If it is not addressed in trunk, you should raise the issue in the Mantis bugtracker so it gets nailed. Then unsatisfactory workarounds would not be needed.

Howard

Reply by email