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

Question about MDI forms listed in main menu

66 views
Skip to first unread message

Alex Syntek

unread,
Oct 12, 2000, 3:00:00 AM10/12/00
to
Hello,

Maybe this is a stupid question but:

How can I add menu items to the Window main menu where I will list all the
currently opened forms in a MDI application ? Also I need to update this
list when a form is closed or new one is created.

Thanks for your help

Alex

Donovan J. Edye

unread,
Oct 12, 2000, 3:00:00 AM10/12/00
to
A,

Below find all you need to implement a Window menu. There is a small
gotcha if you are using D5 and the code follows below.

HTH's


-- Gotcha --

One thing that changed from Delphi 4 to Delphi 5 that bit us and broke
the magic where you get a list of the MDI children windows is the
AutoLineReduction option on the menus. If this is not maManual (or
maParent with the parent set to maManual) then the list doesn't get
added. Took some fiddling to find this out I can tell you!


-- The Code --

procedure Tfrm_App_Main.mniCascadeClick(Sender: TObject);
begin
Cascade;
end;

procedure Tfrm_App_Main.mniTileClick(Sender: TObject);
begin
Tile;
end;

procedure Tfrm_App_Main.mniArrangeIconsClick(Sender: TObject);
begin
ArrangeIcons;
end;

procedure Tfrm_App_Main.mniPrintWindowClick(Sender: TObject);
begin
if ActiveMDICHild <> nil
then if Confirm ('Print current window ?',mrYes) = mrYes
then ActiveMDIChild.Print;
end;

procedure Tfrm_App_Main.mniMinimizeWinClick(Sender: TObject);
begin
if ActiveMDIChild <> nil
then with ActiveMDIChild
do if biSystemMenu in BorderIcons
then WindowState := wsMinimized;
end;

procedure Tfrm_App_Main.mniMinimizeAllClick(Sender: TObject);
var
I: Integer;
begin
{ Must be done backwards through the MDIChildren array }
for I := MDIChildCount - 1 downto 0
do with MDIChildren[I]
do if biSystemMenu in BorderIcons
then WindowState := wsMinimized;
end;

procedure Tfrm_App_Main.mniCloseWindowClick(Sender: TObject);
begin
if ActiveMDIChild <> nil
then ActiveMDIChild.Close;
end;

procedure Tfrm_App_Main.mniCloseAllClick(Sender: TObject);
var
I: Integer;
begin
{ Close Active Forms first }
for I := MDIChildCount - 1 downto 0
do if MDIChildren[I].Enabled
then MDIChildren[I].Close;
Application.ProcessMessages;
{ Now Close the Rest }
for I := MDIChildCount - 1 downto 0
do MDIChildren[I].Close;
end;

procedure Tfrm_App_Main.UpdateMenuItems(Sender: TObject);
var
Ok : Boolean;
begin
Ok := MDIChildCount > 0;
mniCascade.Enabled := Ok;
mniTile.Enabled := Ok;
mniArrangeIcons.Enabled := Ok;
mniMinimizeWindow.Enabled := Ok;
mniMinimizeAll.Enabled := Ok;
mniCloseWindow.Enabled := Ok;
mniCloseAll.Enabled := Ok;
end;

Above triggered thusly...

Screen.OnActiveFormChange := UpdateMenuItems;

And set the MainForm.WindowMenu to point to the menu you want the open
forms
to appear in.

On Thu, 12 Oct 2000 14:45:19 -0700, "Alex Syntek" <mp...@yahoo.com.mx>
wrote:

--Donovan

Donovan J. Edye [www.edye.wattle.id.au/hobbies/prog/delphi/]
Namadgi Systems, Delphi Developer
Web: www.namsys.com.au
E-Mail: don...@namsys.com.au
TVisualBasic := Class(None);

Bart Loosvelt

unread,
Oct 13, 2000, 3:00:00 AM10/13/00
to
>How can I add menu items to the Window main menu where I will list all the
>currently opened forms in a MDI application ? Also I need to update this
>list when a form is closed or new one is created.

When you design your menu, create one menu 'title' (not a menu item,
but the thing directly visible in the menu bar) with its caption set
to 'Window'. Normally Delphi will call this TMenuItem Window1. Now
select 'Window1' in de Form's WindowMenu property. Delphi will take
care of building the list of open windows as you open/close MDI
children. You can use donovan's functions for implementing the
standard MDI actions ('cut', 'copy', 'cascade', 'align vertically',
'next window' etc.) but you can also use a TActionList for that. More
info in the Online Help.

Best regards,
Bart

0 new messages