Board index » cppbuilder » MainMenu in MDIChild-Form?

MainMenu in MDIChild-Form?


2007-04-16 04:48:13 AM
cppbuilder91
The Main-Form (FormStyle=fsMDIForm) has a MainMenu.
So does the Child-Form (FormStyle=fsMDIChild).
However, when the Child-Form is invoked the MainMenu of the Main-Form
is replaced by the MainMenu of the Child-Form.
I'm assuming that this is what it should be. But, is there any way to prevent that
and keep 2 separate MainMenus within the 2 Forms?
Harry
 
 

Re:MainMenu in MDIChild-Form?

"Hartmut Kloppert" < XXXX@XXXXX.COM >wrote in message
Quote
The Main-Form (FormStyle=fsMDIForm) has a MainMenu.
So does the Child-Form (FormStyle=fsMDIChild).

However, when the Child-Form is invoked the MainMenu of the Main-Form
is replaced by the MainMenu of the Child-Form.

I'm assuming that this is what it should be. But, is there any way to prevent that
and keep 2 separate MainMenus within the 2 Forms?

Harry

I forgot to say that I'm using BCB4.
 

Re:MainMenu in MDIChild-Form?

Hartmut Kloppert wrote:
Quote
>However, when the Child-Form is invoked the MainMenu of the Main-Form
>is replaced by the MainMenu of the Child-Form.
>
>I'm assuming that this is what it should be. But, is there any way to prevent that
>and keep 2 separate MainMenus within the 2 Forms?
>
>Harry
>
I forgot to say that I'm using BCB4.


Have a look at the GroupIndex property in the Help
you'll find what you need there.
Michel
 

{smallsort}

Re:MainMenu in MDIChild-Form?

Michel Corbin wrote:
Quote
Have a look at the GroupIndex property in the Help
you'll find what you need there.

I forgot to say GroupIndex is a property of TMenuItem
Michel
 

Re:MainMenu in MDIChild-Form?

"Michel Corbin" <"Michel Corbin">wrote in message news: XXXX@XXXXX.COM ...
Quote
Hartmut Kloppert wrote:
>>However, when the Child-Form is invoked the MainMenu of the Main-Form
>>is replaced by the MainMenu of the Child-Form.
>>
>>I'm assuming that this is what it should be. But, is there any way to prevent that
>>and keep 2 separate MainMenus within the 2 Forms?
>>
>>Harry
>>
>I forgot to say that I'm using BCB4.

Have a look at the GroupIndex property in the Help
you'll find what you need there.

Michel
Thanks Michel,
however, I do have an MDI-application. If I apply different Groupindexes to
the MenuItems of the MDI-Form and the MDI-Child it only controls, if the
Menuitems will be replaced or merged on the MainMenu. The MDI-Child
never keeps it's Menu-Items. Any idea?
Harry
 

Re:MainMenu in MDIChild-Form?

Hartmut Kloppert wrote:
Quote
.......................... If I apply different Groupindexes to
the MenuItems of the MDI-Form and the MDI-Child it only controls, if the
Menuitems will be replaced or merged on the MainMenu. The MDI-Child
never keeps it's Menu-Items. Any idea?

Harry

I don't think that's possible. If you want a form to keep its own main menu,
you have to make it a normal form. A MDI-Child form can have its own pop menu,
but that is not what you are looking for.
Michel
 

Re:MainMenu in MDIChild-Form?

"Michel Corbin" <"Michel Corbin">wrote in message news: XXXX@XXXXX.COM ...
Quote
Hartmut Kloppert wrote:

>.......................... If I apply different Groupindexes to
>the MenuItems of the MDI-Form and the MDI-Child it only controls, if the
>Menuitems will be replaced or merged on the MainMenu. The MDI-Child
>never keeps it's Menu-Items. Any idea?
>
>Harry
I don't think that's possible. If you want a form to keep its own main menu,
you have to make it a normal form. A MDI-Child form can have its own pop menu,
but that is not what you are looking for.

Michel


Yes, I think you are right. MDI-applications ALWAYS merge the MainMenus(AutoMerge=true)!
I'll go with Toolbar-Buttons instead. They can't be merged.
Harry
 

Re:MainMenu in MDIChild-Form?

"Hartmut Kloppert" < XXXX@XXXXX.COM >wrote:
Quote

[...] But, is there any way to prevent that and keep 2
separate MainMenus within the 2 Forms?
If you remove the main menu from the Child form's MainMenu
property (set it to NULL), you'll retain the Main Form's
MainMenu. Then, what we do is we merge the Child Form's
MainMenu into the Main Form's Main Menu.
If you insist on having 2 seperate menus, then you'll have to
fake it with a TToolBar with the buttons set to tbsDropDown
and assign a PopupMenu to each button. It looks just like a
main menu but IIRC, there are right click issues that need to
be dealt with by subclassing it's WindowProc. You might also
need to put the TToolBar on a TPanel but I don't recall.
~ JD
 

Re:MainMenu in MDIChild-Form?

"Hartmut Kloppert" < XXXX@XXXXX.COM >wrote:
Quote

I'll go with Toolbar-Buttons instead.
As I stated in my other post, you can have 2 main menus but
my other post is inaccurate because my recolection was part
SDI and part MDI.
With an MDI application, TToolButtons with a Style of
tbsDropDown will not drop down the PopupMenu so what
you need to do is add a TMainMenu to the MDIChild and
be sure to blank-out the Menu property for the MDIChild.
Then drop a TToolBar on the MDIChild, set it's Flat
property to true (if not, it doesn't HotTrack) and
assign The TMainMenu to the TToolBar's Menu property.
Note that if you make changes to the TMainMenu, you will
need to blank-out the TToolBar's Menu property (pressing
enter or changing fileds in the Object Inspector so that
unassign takes hold) and then reassign the TMainMenu.
The last thing to do is to assign an OnCustomDrawButton
event to the TToolBar. For example:
//-------------------------------------------------------------
void __fastcall TForm2::ToolBar1CustomDrawButton(TToolBar *Sender, TToolButton *Button, TCustomDrawState State, bool &DefaultDraw)
{
TToolBar *Bar = static_cast<TToolBar*>( Sender );
TRect R = Rect( Button->Left, Button->Top, Button->Left + Button->Width, Button->Top + Button->Height );
if( State.Contains(cdsHot) )
{
Bar->Canvas->Brush->Color = clHighlight;
Bar->Canvas->Font->Color = clHighlightText;
}
else
{
Bar->Canvas->Brush->Color = Bar->Color;
Bar->Canvas->Font->Color = Bar->Font->Color;
}
Bar->Canvas->FillRect( R );
::DrawText( Bar->Canvas->Handle, Button->Caption.c_str(), -1, &R, DT_SINGLELINE | DT_CENTER | DT_VCENTER );
DefaultDraw = false;
}
//-------------------------------------------------------------
However, the above code revealed a bug in the state of the
State parameter. When the menu has dropped down, the top
item is redrawn multiple times with different State settings
(causing a flicker) and in the final draw the State is simply
wrong. So ... I worked around that by determining the position
of the mouse myself:
TToolBar *Bar = static_cast<TToolBar*>( Sender );
TRect R = Rect( Button->Left, Button->Top, Button->Left + Button->Width, Button->Top + Button->Height );
TPoint P;
::GetCursorPos( &P );
P = Bar->ScreenToClient( P );
if( PtInRect(R,P) )
{
Bar->Canvas->Brush->Color = clHighlight;
Bar->Canvas->Font->Color = clHighlightText;
}
else
{
Bar->Canvas->Brush->Color = Bar->Color;
Bar->Canvas->Font->Color = Bar->Font->Color;
}
Bar->Canvas->FillRect( R );
::DrawText( Bar->Canvas->Handle, Button->Caption.c_str(), -1, &R, DT_SINGLELINE | DT_CENTER | DT_VCENTER );
DefaultDraw = false;
The above mimics a TMainMenu *almost* perfectly. The
difference is that when the menu is dropped down, the
first item is drawn as selected. If you want to fix that
as well, I'm thinking that that can be accomplished with
custom drawing the menu as well and using a similar
method to determine the mouse position instead of relying
on a 'State' parameter.
~ JD