Recent

Author Topic: How to react on user's click on minimize button?  (Read 24651 times)

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
How to react on user's click on minimize button?
« on: October 15, 2009, 07:54:44 pm »
In an application I have a modal form, and, when user clicks on minimize button of that form, I want the whole Application, not just that form, to be minimized.

In Delphi, on Windows, I achieve this behavior this way:

Code: [Select]
...
private
  procedure WmSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;

...

procedure TForm2.WmSysCommand(var Msg: TWMSysCommand);
begin
  if msg.CmdType = SC_MINIMIZE then
    Application.Minimize
  else
    inherited;
end;

In Lazarus, when I cannot use Windows message, what can I do to achieve this?
« Last Edit: October 15, 2009, 07:56:34 pm by zoran »

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How to react on user's click on minimize button?
« Reply #1 on: October 15, 2009, 08:25:58 pm »
Why you cannot use message under lazarus ?

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: How to react on user's click on minimize button?
« Reply #2 on: October 15, 2009, 09:16:11 pm »
Well... I just assumed I couldn't... But, now I tried and... No, I can't :(

v-t-l

  • New Member
  • *
  • Posts: 10
Re: How to react on user's click on minimize button?
« Reply #3 on: October 16, 2009, 01:19:16 pm »
Code: [Select]
procedure TForm1.FormWindowStateChange(Sender: TObject);
begin
  case WindowState of
    wsNormal: Application.Title := 'Normal';
    wsMaximized: Application.Title := 'Maximized';
    wsMinimized: Application.Title := 'Minimized';
  end;
end;

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: How to react on user's click on minimize button?
« Reply #4 on: October 16, 2009, 03:54:51 pm »
Code: [Select]
procedure TForm1.FormWindowStateChange(Sender: TObject);
begin
  case WindowState of
    wsNormal: Application.Title := 'Normal';
    wsMaximized: Application.Title := 'Maximized';
    wsMinimized: Application.Title := 'Minimized';
  end;
end;

Thank you, v-t-l, but OnWindowStateChange event is triggered after the form is minimized. I want to intercept the user's minimize request. I would need something like form's OnCloseQuery event, which is used to intercept closing of the form.

Is there some way to do it?

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
Re: How to react on user's click on minimize button?
« Reply #5 on: October 19, 2009, 11:11:00 am »
instead of intercepting, which leads to user confusion, disable the minimize button.
See TForm.BorderIcons property
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: How to react on user's click on minimize button?
« Reply #6 on: October 19, 2009, 11:31:38 am »
instead of intercepting, which leads to user confusion, disable the minimize button.
See TForm.BorderIcons property


Thank you, Marc, but I don't think that intercepting would confuse user, when clicking a modal form's minimize button would result in minimizing the application, instead of the modal form only. Wouldn't it be the expected behavior for the user?

For now, I leave the minimize button and in OnFormWindowStateChange event I put "if WindowState = wsMinimized then Application.Minimize;". Now the form gets down first, then followed by the whole application. I'd rather see only the application's minimization.

So, there really seems to be no way of doing it? :(
« Last Edit: October 19, 2009, 11:34:45 am by zoran »

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
Re: How to react on user's click on minimize button?
« Reply #7 on: October 19, 2009, 11:37:17 am »
Thank you, Marc, but I don't think that intercepting would confuse user, when clicking a modal form's minimize button would result in minimizing the application, instead of the modal form only. Wouldn't it be the expected behavior for the user?

Sorry, I wasn't fully awake, I forgot about the whole topic and read only your intercept message. Indeed, minimizing all wouldn't confuse I think. (clicking and do nothing would, but that was not your intention)
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How to react on user's click on minimize button?
« Reply #8 on: October 19, 2009, 01:32:52 pm »
Think that TApplication.OnEvent() could help here (CLX have such thing , don't know VCL)

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: How to react on user's click on minimize button?
« Reply #9 on: October 19, 2009, 02:33:13 pm »
Think that TApplication.OnEvent() could help here (CLX have such thing , don't know VCL)

No. There is no such thing.  :(

cdbc

  • Hero Member
  • *****
  • Posts: 1090
    • http://www.cdbc.dk
Re: How to react on user's click on minimize button?
« Reply #10 on: November 02, 2009, 07:06:58 pm »
Hello...

How about TApplication.OnUserInput ?!?

Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: How to react on user's click on minimize button?
« Reply #11 on: November 04, 2009, 06:48:15 pm »
Hello...

How about TApplication.OnUserInput ?!?

Regards Benny

How? Can you help me with this? I dont know how to achieve what I intend to. %)

cdbc

  • Hero Member
  • *****
  • Posts: 1090
    • http://www.cdbc.dk
Re: How to react on user's click on minimize button?
« Reply #12 on: November 04, 2009, 08:02:00 pm »
Hi Zoran.
Ok... I'll try, here goes:
Code: [Select]
{ in your test unit }
uses forms,....

type
  TfrmMain = class(TForm)
    ...
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    ...
    fLog: TStrings;
    fLogMessages: boolean;
  public
    ...
    procedure User_Input_Test(Sender: TObject; Msg: Cardinal);
  end;

implementation

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  fLog:= TStringlist.Create;
  Application.OnUserInput:= @User_Input_Test;
end;

procedure TfrmMain.Button1Click(Sender: TObject);
begin
  fLogMessages:= not fLogMessages; { toggle logging or not }
end;

procedure TfrmMain.User_Input_Test(Sender: TObject; Msg: Cardinal);
var S: string;
begin
  if fLogMessages then begin
    S:= DateTimeToStr(Now)+' '+Sender.ClassName+' Msg = '+IntToStr(Msg);
    fLog.Add(S);
  end;
end;

procedure TfrmMain.FormDestroy(Sender: TObject);
begin
  fLog.SaveToFile('UserInputTest.log');
  FreeThenNil(fLog);
end;
{ one could trace mousemoves too... }
{ you'll have to excuse me the quick 'n dirty style }
With these snippets, you should be able to figure out, which msg'es comes from where and goes where...
It generates a lot of msg'es, thus the button to turn of logging.

You might try clicking the 'minimize' button, a few times after another  ::)

After a run, open your texteditor to view your results...

Anyway, that's what I would do...

HTH ;-)
Regards Benny
« Last Edit: November 04, 2009, 08:05:09 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: How to react on user's click on minimize button?
« Reply #13 on: November 05, 2009, 07:29:01 pm »
Thank you, Benny, for trying to help.

However, now I only managed to find out that minimizing a form doesn't trigger Application.OnUserInput event.  :(

 

TinyPortal © 2005-2018