2007. március 22., csütörtök

Minimize an application when modal forms are present


Problem/Question/Abstract:

My application (non MDI) has many modal forms which are open most of the time. When the user wants to minimize the application and presses the minimize system button, he experiences only the top modal form gets minimized while the other forms (at least app's main form) are still at their current size. Moreover, the user now is confused because clicking on the main form does nothing but giving errors to him. I can not change the application's appearance or exchange the modal forms to some other solution. Is there a way I can keep my modal design and still enable users to minimize the application the way they are used to?

Answer:

Add a handler for WM_SYSCOMMAND to your modal forms. The handler should look like this:

private {form declaration}

procedure WMSyscommand(var msg: TWmSysCommand); message WM_SYSCOMMAND;

procedure TForm2.WMSyscommand(var msg: TWmSysCommand);
begin
  case (msg.cmdtype and $FFF0) of
    SC_MINIMIZE:
      begin
        msg.result := 0;
        EnableWindow(Application.handle, true);
        Application.Minimize;
      end;
  else
    inherited;
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése