Forum > Carbon

Minimize on 'x' and close by system application menu?

<< < (3/3)

fabienwang:
procedure TFrmMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  CloseAction := caHide;
end;

In your menu item to Quit:

Application.Terminate;

rajivsoft:

--- Quote from: FabienWang on March 11, 2011, 12:32:06 pm ---procedure TFrmMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  CloseAction := caHide;
end;

In your menu item to Quit:

Application.Terminate;

--- End quote ---

On MAC OS X all application have their own system exit menu, it's default, all application have it with or without custom main menu, and you can't change it, so if i use your code as i said in post before when user click system application exit menu the apllication will hide, and it's not exit...

btw i have found a solution via stack and custom form class inspection:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses LMessages, ... type  { TFrm_Main }   TFrm_Main = class(TForm)  ...  procedure WMCloseQuery(var message: TLMessage); message LM_CLOSEQUERY; ... procedure TFrm_Main.WMCloseQuery(var message: TLMessage);begin  Self.WindowState := wsMinimized;end;WMCloseQuery is called when you press 'x' and if not rewrited by you in your form call's Close.

Now the only problem is that as you see i must use Self.WindowState := wsMinimized because if i use Self.Hide it hides form ( XD ) and you can no more show it by only clicking on application dock icon, so the question is:
What event is fired when you click on dock icon?

guest48704:
var
Form1: TForm1;
       RemoteCanClose : boolean = True;


//WMSysCommand
procedure TForm1.WMSysCommand(VAR Msg: TWMSysCommand);
begin
     if Msg.CmdType = SC_CLOSE then          // - button  (upper right of form next to X button)
        RemoteCanClose := False;
end;

//Close button
procedure TForm1.Button1Click(Sender: TObject);
begin
     RemoteCanClose := True;
     Close;
end;

//FormCloseQuery
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
     CanClose := RemoteCanClose;
     Form1.Show;         // X will not work again unless this done before hide
     Form1.Hide;
end;

dbannon:
lazarus9, did you spot that this was a seven year old thread ?

Anyway, its a topic that interests me too. I do that in tomboy-ng, it works on carbon but not on cocoa in my model at least.
With cocoa, when you hide the main form, the apple provided menu hides, the forms main menu hides and even the tray icon (if you have one) hides.

So be careful in basing a project on being able to do this, carbon will not be around for long.

Davo

Navigation

[0] Message Index

[*] Previous page

Go to full version