Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems with modal forms and minimizing

489 views
Skip to first unread message

Ralf Mimoun

unread,
Jun 5, 2002, 7:35:54 AM6/5/02
to
Hi,

I don't know if this is the best group for my question. I have an
application with many modal forms. Now, the user wants to minimize the
application - no problem so far, a "procedure WMSysCommand(var aMessage:
TMessage); message WM_SYSCOMMAND" like

if (aMessage.WParam AND $FFF0) = SC_MINIMIZE then begin
EnableWindow(Application.Handle, True);
Application.Minimize;
end
else begin
inherited;
end;

in every form does the trick - almost. Now, the whole application minimizes
if I click on the "minimize" button in the caption bar. But if I start the
application, open such a modal form and press "Win-M" (or the system key of
your choice to minimize all windows), the form/application remains open. The
message to minimize never reaches the form. If I minimize it via the caption
bar button, restore it and press Win-M again (in the application or
somewhere else, doesn't matter), the application minimizes. It seems that
Windows is surprised that the modal form can be minimized (by pressing the
caption bar button) and remembers this ability. So, Windows sends the
minimize message the next time I press Win-M.

Now, I want to know how I can let my application react on Win-M without
minimizing it by using the caption bar first. Does anybody know what flag
Windows uses to mark all forms who should get a minimize message? Any other
ideas?

Ralf


Peter Below (TeamB)

unread,
Jun 5, 2002, 2:21:34 PM6/5/02
to
In article <3cfdf70a$1_2@dnews>, Ralf Mimoun wrote:
> I don't know if this is the best group for my question. I have an
> application with many modal forms. Now, the user wants to minimize the
> application - no problem so far, a "procedure WMSysCommand(var aMessage:
> TMessage); message WM_SYSCOMMAND" like
>
> if (aMessage.WParam AND $FFF0) = SC_MINIMIZE then begin
> EnableWindow(Application.Handle, True);
> Application.Minimize;
> end
> else begin
> inherited;
> end;
>
> in every form does the trick - almost. Now, the whole application minimizes
> if I click on the "minimize" button in the caption bar. But if I start the
> application, open such a modal form and press "Win-M" (or the system key of
> your choice to minimize all windows), the form/application remains open.

That is because the Application window is disabled when you show a modal form.
This is actually a bug, it should not be disabled. The EnableWindow line in
your message handler fixes the problem but Win-M does not send the
WM_SYSCOMMAND message to your modal dialog, it sends it only to the top-level
windows in a process, and for a Delphi app that is the Application window.
Which is disabled and thus does not get the message...

Here is a method to solve this problem: prevent the Application window from
ever being disabled:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, stdctrls;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
function AppHook(var Message: TMessage): Boolean;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage( 'Hi' );
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Application.HookMainWindow( AppHook );
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
Application.UnhookMainWindow( AppHook );
end;

function TForm1.AppHook(var Message: TMessage): Boolean;
begin
result := false;
If message.Msg = WM_ENABLE Then
If not TWMEnable(message).enabled Then Begin
EnableWindow( application.handle, true );
result := true;
End;
end;

end.

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


0 new messages