Board index » cppbuilder » Tool bar menu & MDI

Tool bar menu & MDI

I have a menu that is created as tool bar buttons, exactly like the IDE. The
problem is that my app is an MDI app, so without the menu bar created when
assigning a menu to the form, a maximized child window does not display the
close/min/restore buttons. Is there something I can do to show these buttons
somewhere (like in Word), or do I have to ditch the tool bar menu and assign
the menu to the form?

--
==================
Matthew Ferreira
Xlunat...@yahoo.comX
- Remove first and last X for valid e-mail -

 

Re:Tool bar menu & MDI


Hi Matthew,
[snip]

Quote
> ...a maximized child window does not display the
> close/min/restore buttons.

Yeah, unfortunately, unless you use a standard menu, the child's title
bar buttons won't appear.  If you notice though, programs like Word
render their own title bar buttons for maximized child windows.  You too
can do the same.  Just use a triplet of TSpeedButtons on a Panel, like
so (cut and paste the following onto your Form designer)...

object MainPanel: TPanel
  Left = 0
  Top = 30
  Width = 769
  Height = 23
  Align = alTop
  BevelOuter = bvNone
  TabOrder = 2
  object ButtonsPanel: TPanel
    Left = 708
    Top = 0
    Width = 61
    Height = 23
    Align = alRight
    BevelOuter = bvNone
    TabOrder = 0
    Visible = False
    object MinimizeButton: TSpeedButton
      Left = 0
      Top = 2
      Width = 18
      Height = 18
      Flat = True
      Glyph.Data = {
        62000000424D62000000000000003E000000280000000A000000090000000100
        01000000000024000000C40E0000C40E0000020000000000000000000000FFFF
        FF00FFC00000C0C00000C0C00000FFC00000FFC00000FFC00000FFC00000FFC0
        0000FFC00000}
      OnClick = MinimizeButtonClick
    end
    object RestoreButton: TSpeedButton
      Left = 18
      Top = 2
      Width = 18
      Height = 18
      Flat = True
      Glyph.Data = {
        96010000424D960100000000000036000000280000000A0000000B0000000100
        18000000000060010000C40E0000C40E00000000000000000000FFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFF000000
        000000000000000000000000000000FFFFFFFFFFFFFFFFFF0000FFFFFF000000
        FFFFFFFFFFFFFFFFFFFFFFFF000000FFFFFFFFFFFFFFFFFF0000FFFFFF000000
        FFFFFFFFFFFFFFFFFFFFFFFF000000FFFFFFFFFFFFFFFFFF0000FFFFFF000000
        FFFFFFFFFFFFFFFFFFFFFFFF000000000000000000FFFFFF0000FFFFFF000000
        000000000000000000000000000000FFFFFF000000FFFFFF0000FFFFFF000000
        000000000000000000000000000000FFFFFF000000FFFFFF0000FFFFFFFFFFFF
        FFFFFF000000FFFFFFFFFFFFFFFFFFFFFFFF000000FFFFFF0000FFFFFFFFFFFF
        FFFFFF000000000000000000000000000000000000FFFFFF0000FFFFFFFFFFFF
        FFFFFF000000000000000000000000000000000000FFFFFF0000FFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000}
      OnClick = RestoreButtonClick
    end
    object CloseButton: TSpeedButton
      Left = 38
      Top = 2
      Width = 18
      Height = 18
      Flat = True
      Glyph.Data = {
        56010000424D560100000000000036000000280000000A000000090000000100
        18000000000020010000C40E0000C40E00000000000000000000FFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFF000000
        000000FFFFFFFFFFFFFFFFFFFFFFFF000000000000FFFFFF0000FFFFFFFFFFFF
        000000000000FFFFFFFFFFFF000000000000FFFFFFFFFFFF0000FFFFFFFFFFFF
        FFFFFF000000000000000000000000FFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
        FFFFFFFFFFFF000000000000FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
        FFFFFF000000000000000000000000FFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
        000000000000FFFFFFFFFFFF000000000000FFFFFFFFFFFF0000FFFFFF000000
        000000FFFFFFFFFFFFFFFFFFFFFFFF000000000000FFFFFF0000FFFFFFFFFFFF
        FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000}
      OnClick = CloseButtonClick
    end
  end
end

Now place your ToolBar menu onto this main Panel; make sure your
ToolBar's Align property is alNone and make sure it's Wrapable property
is false.  Now, all that's left is to implement a few event handlers...

//
// in MainForm header...
//
public:
   void __fastcall ShowTitleButtons(bool show);

//
// in MainForm source...
//
void __fastcall TMainForm::CloseButtonClick(TObject *Sender)
{
   if (ActiveMDIChild)
   {
      ActiveMDIChild->Close();
      ShowTitleButtons(false);
   }

Quote
}

void __fastcall TMainForm::RestoreButtonClick(TObject *Sender)
{
   if (ActiveMDIChild)
   {
      ActiveMDIChild->WindowState = wsNormal;
      ShowTitleButtons(false);
   }

Quote
}

void __fastcall TMainForm::MinimizeButtonClick(TObject *Sender)
{
   if (ActiveMDIChild)
   {
      ActiveMDIChild->WindowState = wsMinimized;
      ShowTitleButtons(false);
   }

Quote
}

void __fastcall TMainForm::ShowTitleButtons(bool show)
{
   ButtonsPanel->Visible = show;

Quote
}

//
// in MDIChild source...
//
// OnResize event handler...
void __fastcall TMDIChild::FormResize(TObject *Sender)
{
   MainForm->ShowTitleButtons(WindowState == wsMaximized);

Quote
}

Good luck,
--
Damon Chandler (TeamB)
- BCBCAQ <http://bcbcaq.freeservers.com>
- Graphics API Black Book <http://graphicsBB.itgo.com>

Other Threads