How to react on user's click on minimize button? lazarus / 10-Designer ---------------------------------------------------------------------- Zoran · 2009-10-15 17:54 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? ---------------------------------------------------------------------- zeljko · 2009-10-15 18:25 Why you cannot use message under lazarus ? ---------------------------------------------------------------------- Zoran · 2009-10-15 19:16 Well... I just assumed I couldn't... But, now I tried and... No, I can't ---------------------------------------------------------------------- v-t-l · 2009-10-16 11:19 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 · 2009-10-16 13:54 Quote from: v-t-l on October 16, 2009, 01:19:16 pmCode: [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 · 2009-10-19 09:11 instead of intercepting, which leads to user confusion, disable the minimize button. See TForm.BorderIcons property ---------------------------------------------------------------------- Zoran · 2009-10-19 09:31 Quote from: Marc on October 19, 2009, 11:11:00 aminstead 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? ---------------------------------------------------------------------- Marc · 2009-10-19 09:37 Quote from: zoran on October 19, 2009, 11:31:38 amThank 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) ---------------------------------------------------------------------- zeljko · 2009-10-19 11:32 Think that TApplication.OnEvent() could help here (CLX have such thing , don't know VCL) ---------------------------------------------------------------------- Zoran · 2009-10-19 12:33 Quote from: zeljko on October 19, 2009, 01:32:52 pmThink that TApplication.OnEvent() could help here (CLX have such thing , don't know VCL) No. There is no such thing. ---------------------------------------------------------------------- cdbc · 2009-11-02 18:06 Hello... How about TApplication.OnUserInput ?!? Regards Benny ---------------------------------------------------------------------- Zoran · 2009-11-04 17:48 Quote from: cdbc on November 02, 2009, 07:06:58 pmHello... How about TApplication.OnUserInput ?!? Regards Benny How? Can you help me with this? I dont know how to achieve what I intend to. ---------------------------------------------------------------------- cdbc · 2009-11-04 19:02 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 ---------------------------------------------------------------------- Zoran · 2009-11-05 18:29 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.