Board index » delphi » want minimize form cause app to minimize

want minimize form cause app to minimize

I want my program to behave so that if the user clicks in the upper right
corner to minimize a child form, it minimizes the whole app to the task bar.
As someone suggested, I added this private declaration:

Procedure tThisForm.WMSysCommand(Var msg: TWmSysCommand);
Begin
  Case (msg.cmdtype and $FFF0) of
    SC_MINIMIZE: Begin
        EnableWindow( Application.handle, true);
        Application.Minimize;
        msg.result := 0;
      End;
  Else
    inherited;
  End;
End;

When I run it in the D6 IDE, it does exactly what I want it to do.  But when
it is run as a stand-alone, it minimizes the form to a little area above the
task bar and the main form of the application is not minimized.  I'm using
application.FormCreate to create the other forms as needed, if that matters.

How can I get it to work as a stand-alone EXE?
TIA

 

Re:want minimize form cause app to minimize


Quote
In article <3cf39af5$1_1@dnews>, Jud McCranie wrote:
> How can I get it to work as a stand-alone EXE?

It should work whether you run the program inside or outside the IDE.
Perhaps you have two versions of the EXE around?

--
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

Re:want minimize form cause app to minimize


Quote
> It should work whether you run the program inside or outside the IDE.
> Perhaps you have two versions of the EXE around?

I checked for that.  I have some more info, though.

It works as desired if I:
  run it from the IDE, or
  use the explorer to run it from the folder where it is generated, or
  I find it with Search (any folder) and run it from there

It does not work correctly if:
  I run a copy of it that is in another folder (explorer or command line)
  I run it in the original folder by a shortcut or command line

Weird, isn't it?

I have double checked to make sure that the EXE file is the same.  It works
(IDE or Explorer) if it is in the original folder.  Copy it to another
folder and it doesn't work.  Copy it back to the original folder and it
works (IDE or explorer only).  Everything else is exactly the same.

At present, I have the thing in only one of the forms (testing).  I need it
in all forms I want to act that way, right?

Re:want minimize form cause app to minimize


Dear Jud
I believe I had the exact same problem - I solved it by a code snippet found
on www.delphicenter.ch that changes the main form at runtime:

First I put in this procedure in the (first) MainForm:

procedure Form1.SetAsMainForm(aForm:TForm);
var
  P:Pointer;
begin
  P := @Application.Mainform;
  Pointer(P^) := aForm;
end;

then on the initialization section on the second form i put:

Form1.SetAsMainForm(Form2)

and in the finalization section of the second form:

Form1.SetAsMainForm(Form1)

this works perfectly for me.

much love, Stig Andersen.

"Jud McCranie" <jud.mccra...@mindspring.com> skrev i en meddelelse
news:3cf39af5$1_1@dnews...

Quote
> I want my program to behave so that if the user clicks in the upper right
> corner to minimize a child form, it minimizes the whole app to the task
bar.
> As someone suggested, I added this private declaration:

> Procedure tThisForm.WMSysCommand(Var msg: TWmSysCommand);
> Begin
>   Case (msg.cmdtype and $FFF0) of
>     SC_MINIMIZE: Begin
>         EnableWindow( Application.handle, true);
>         Application.Minimize;
>         msg.result := 0;
>       End;
>   Else
>     inherited;
>   End;
> End;

> When I run it in the D6 IDE, it does exactly what I want it to do.  But
when
> it is run as a stand-alone, it minimizes the form to a little area above
the
> task bar and the main form of the application is not minimized.  I'm using
> application.FormCreate to create the other forms as needed, if that
matters.

> How can I get it to work as a stand-alone EXE?
> TIA

Re:want minimize form cause app to minimize


Quote
> I believe I had the exact same problem - I solved it by a code snippet
found
> on www.delphicenter.ch that changes the main form at runtime:

Thanks, I'll look at that.  Since my last message, I made a small test
program, main form, one child form, one button on the main form to call the
other form.  Nothing else (not even the application.minimize stuff).

Results for it are strange (the same as before) -

if it is called from the IDE or from explorer in the folder where it is
created - it minimizes like I want it to (even w/o app.minimize).

If I make a shortcut to it in that folder and use it, it doesn't minimize
the main form.  Similarly, if I copy the EXE to another folder, it doesn't
minimize the main form - called either in explorer or with a shortcut.

If I search for the EXE and run it from there - it DOES minimize the main
form, from EITHER folder.

Recap, for both the real app and the test:

                                        EXE in
                         orig folder    different folder

IDE                       Yes             n/a
explorer                 yes             no
desktop shortcut    no              no
search                   yes              yes

yes = minimize child form minimizes the main form.

This is on my computer.  My client calls it from a desktop shortcut on his
Win2000, and it doesn't work for him.

Delphi 6 pro, update pack 2.  Windows WP home, all updates.

Does anyone know why it is like this?

Re:want minimize form cause app to minimize


Quote
> this works perfectly for me.

For me it worked the same way as the other method, which is the same as
nothing at all.  If it is in the IDE or called from the explorer while in
the original folder, it works.  If it is in a different folder or called by
a desktop shortcut it doesn't work.

Re:want minimize form cause app to minimize


Quote
> I want my program to behave so that if the user clicks in the upper right
> corner to minimize a child form, it minimizes the whole app to the task

bar.

Correction:  In the cases I thought it was working, what was actually
happening was that when the second form was minimized, the main form
disappeared behind a window that was behind the main form.  In other words,
it put the main app form behind the window that it had been on top of.

New info: when I add the following to the unit for the second form, no code
is generated!

What could be the problem?

Procedure tForm2.WMSysCommand(Var msg: TWmSysCommand);
Begin
  Case (msg.cmdtype and $FFF0) of
    SC_MINIMIZE:
    Begin
      EnableWindow( Application.handle, true);
      Application.Minimize;
      msg.result := 0;
    End;
  Else
    inherited;
  End;
End;

Re:want minimize form cause app to minimize


Quote
> I want my program to behave so that if the user clicks in the upper right
> corner to minimize a child form, it minimizes the whole app to the task

bar.

Just after I wrote another message, I went to the Delphi pool,
http://www.lmc-mediaagentur.de/dpool.htm
user interface, tForm, tip 0017, and it has
  message WM_SYSCOMMAND;
after the proc declaration, and NOW IT WORKS!

Sorry for the wild goose chase.

Re:want minimize form cause app to minimize


Quote
In article <3cf45636$1_2@dnews>, Jud McCranie wrote:
> Sorry for the wild goose chase.

Oh, it was you doing all the chasing. At least you got one <g>.

--
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

Re:want minimize form cause app to minimize


Quote
> Oh, it was you doing all the chasing. At least you got one <g>.

Yes, the IDE, the window for that folder, and the search window were all
maximized.  When I minimized the secondary form, the main from which had
been on top of those windows went behind, and I thought that the main form
had been minimized too.

Other Threads