Board index » cppbuilder » MainMenu in MDIChild-Form?
Hartmut Kloppert
CBuilder Developer |
Hartmut Kloppert
CBuilder Developer |
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 |
Hartmut Kloppert
CBuilder Developer |
2007-04-16 04:54:56 AM
Re:MainMenu in MDIChild-Form?
"Hartmut Kloppert" < XXXX@XXXXX.COM >wrote in message
QuoteThe Main-Form (FormStyle=fsMDIForm) has a MainMenu. |
Michel Corbin
CBuilder Developer |
2007-04-16 05:50:06 AM
Re:MainMenu in MDIChild-Form?
Hartmut Kloppert wrote:
Quote>However, when the Child-Form is invoked the MainMenu of the Main-Form Michel {smallsort} |
Michel Corbin
CBuilder Developer |
2007-04-17 12:18:10 AM
Re:MainMenu in MDIChild-Form?
Michel Corbin wrote:
QuoteHave a look at the GroupIndex property in the Help |
Hartmut Kloppert
CBuilder Developer |
2007-04-17 03:08:21 AM
Re:MainMenu in MDIChild-Form?
"Michel Corbin" <"Michel Corbin">wrote in message news: XXXX@XXXXX.COM ...
QuoteHartmut Kloppert wrote: 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 |
Michel Corbin
CBuilder Developer |
2007-04-17 04:51:58 AM
Re:MainMenu in MDIChild-Form?
Hartmut Kloppert wrote:
Quote.......................... If I apply different Groupindexes to but that is not what you are looking for. Michel |
Hartmut Kloppert
CBuilder Developer |
2007-04-17 11:59:09 PM
Re:MainMenu in MDIChild-Form?
"Michel Corbin" <"Michel Corbin">wrote in message news: XXXX@XXXXX.COM ...
QuoteHartmut Kloppert wrote: Harry |
JD
CBuilder Developer |
2007-04-18 03:47:53 AM
Re:MainMenu in MDIChild-Form?
"Hartmut Kloppert" < XXXX@XXXXX.COM >wrote:
Quote
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 |
JD
CBuilder Developer |
2007-04-18 04:55:46 PM
Re:MainMenu in MDIChild-Form?
"Hartmut Kloppert" < XXXX@XXXXX.COM >wrote:
Quote
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 |