This example illustrates how you can create a list of MDI child windows with the help of TdxBarListItem. When creating a child window, its caption is added to the item list. Upon selecting a window from the list, the dxBarListWindowsClick procedure (the OnClick event handler) is called. The OnGetData event handler is used to mark the current active child window within the list. To display check marks within the list, set the TdxBarListItem.ShowCheck property to True.
unit Unit1;
interface
uses
Classes, Forms, dxBar;
type
TMainForm = class(TForm)
dxBarManager: TdxBarManager;
dxBarButtonNewWindow: TdxBarButton;
dxBarButtonArrangeAll: TdxBarButton;
dxBarButtonNextWindow: TdxBarButton;
dxBarButtonPreviousWindow: TdxBarButton;
dxBarListWindows: TdxBarListItem;
dxBarSubItemWindow: TdxBarSubItem;
procedure dxBarButtonNewWindowClick(Sender: TObject);
procedure dxBarButtonArrangeAllClick(Sender: TObject);
procedure dxBarButtonNextWindowClick(Sender: TObject);
procedure dxBarButtonPreviousWindowClick(Sender: TObject);
procedure dxBarListWindowsGetData(Sender: TObject);
procedure dxBarListWindowsClick(Sender: TObject);
public
CreatedMDICount: Integer;
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
uses
Unit2;
// Creates a new child form
procedure TMainForm.dxBarButtonNewWindowClick(Sender: TObject);
begin
TChildForm.Create(Application);
end;
procedure TMainForm.dxBarButtonArrangeAllClick(Sender: TObject);
begin
Tile;
end;
procedure TMainForm.dxBarButtonNextWindowClick(Sender: TObject);
begin
Next;
end;
procedure TMainForm.dxBarButtonPreviousWindowClick(Sender: TObject);
begin
Previous;
end;
// The OnGetData event handler of TdxBarListItem
procedure TMainForm.dxBarListWindowsGetData(Sender: TObject);
begin
with dxBarListWindows do
ItemIndex := Items.IndexOfObject(ActiveMDIChild);
end;
// The OnClick event handler of TdxBarListItem
procedure TMainForm.dxBarListWindowsClick(Sender: TObject);
begin
with dxBarListWindows do
TCustomForm(Items.Objects[ItemIndex]).Show;
end;
end.
// The child form unit
unit Unit2;
interface
uses
Classes, Forms;
type
TChildForm = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
end;
implementation
{$R *.DFM}
uses
SysUtils, Unit1;
// Adds a child window to the child window list
procedure TChildForm.FormCreate(Sender: TObject);
begin
Inc(MainForm.CreatedMDICount);
Caption := 'Document' + IntToStr(MainForm.CreatedMDICount);
MainForm.dxBarListWindows.Items.AddObject(Caption, Self);
end;
// Removes a child window from the child window list
procedure TChildForm.FormDestroy(Sender: TObject);
begin
with MainForm.dxBarListWindows.Items do
Delete(IndexOfObject(Self));
end;
procedure TChildForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
end.
// ...
Unit1.h
#ifndef Unit1H
#define Unit1H
//-------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "dxBar.hpp"
#include "dxBarExtItems.hpp"
#include "cxClasses.hpp"
#include "Unit2.h"
//-------------------------------------------------------
class TMainForm: public TForm
{
__published: // IDE-managed Components
TdxBarManager *dxBarManager;
TdxBar *dxBarManagerBar1;
TdxBarSubItem *dxBarSubItemWindow;
TdxBarListItem *dxBarListWindows;
TdxBarButton *dxBarButtonNewWindow;
TdxBarButton *dxBarButtonArrangeAll;
TdxBarButton *dxBarButtonNextWindow;
TdxBarButton *dxBarButtonPreviousWindow;
void __fastcall dxBarButtonArrangeAllClick(TObject *Sender);
void __fastcall dxBarButtonNewWindowClick(TObject *Sender);
void __fastcall dxBarButtonNextWindowClick(TObject *Sender);
void __fastcall dxBarButtonPreviousWindowClick(TObject *Sender);
void __fastcall dxBarListWindowsGetData(TObject *Sender);
void __fastcall dxBarListWindowsClick(TObject *Sender);
private: // User declarations
public: // User declarations
int CreatedMDICount;
__fastcall TMainForm(TComponent* Owner);
};
//-------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//-------------------------------------------------------
#endif
// ...
// C++ Builder
// ...
Unit1.cpp
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//-------------------------------------------------------
#pragma package(smart_init)
#pragma link "dxBar"
#pragma link "dxBarExtItems"
#pragma resource "*.dfm"
TMainForm *MainForm;
//-------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner) : TForm(Owner)
{
}
//-------------------------------------------------------
void __fastcall TMainForm::dxBarButtonArrangeAllClick(TObject *Sender)
{
Tile();
}
// Creates a new child form
void __fastcall TMainForm::dxBarButtonNewWindowClick(TObject *Sender)
{
new TChildForm(Application);
}
void __fastcall TMainForm::dxBarButtonNextWindowClick(TObject *Sender)
{
Next();
}
//-------------------------------------------------------
void __fastcall TMainForm::dxBarButtonPreviousWindowClick(TObject *Sender)
{
Previous();
}
// The OnGetData event handler of TdxBarListItem
void __fastcall TMainForm::dxBarListWindowsGetData(TObject *Sender)
{
dxBarListWindows->ItemIndex = dxBarListWindows->Items->IndexOfObject(ActiveMDIChild);
}
// The OnClick event handler of TdxBarListItem
void __fastcall TMainForm::dxBarListWindowsClick(TObject *Sender)
{
((TCustomForm *) dxBarListWindows->Items->Objects[dxBarListWindows->ItemIndex])->Show();
}
//-------------------------------------------------------
// The child form unit
// C++ Builder
// ...
Unit2.h
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "Unit1.h"
//------------------------------------------------------
class TChildForm : public TForm
{
__published: // IDE-managed Components
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall FormDestroy(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TChildForm(TComponent* Owner);
};
//-------------------------------------------------------
extern PACKAGE TChildForm *ChildForm;
//-------------------------------------------------------
#endif
// C++ Builder
// ...
Unit 2.cpp
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
//-------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TChildForm *ChildForm;
//-------------------------------------------------------
__fastcall TChildForm::TChildForm(TComponent* Owner) : TForm(Owner)
{
}
// Adds a child window to the child window list
void __fastcall TChildForm::FormCreate(TObject *Sender)
{
MainForm->CreatedMDICount ++;
Caption = "Document" + IntToStr(MainForm->CreatedMDICount);
MainForm->dxBarListWindows->Items->AddObject(Caption, this);
}
// Removes a child window from the child window list
void __fastcall TChildForm::FormDestroy(TObject *Sender)
{
MainForm->dxBarListWindows->Items->Delete(
MainForm->dxBarListWindows->Items->IndexOfObject(this));
}
//--------------------------------------------------------
void __fastcall TChildForm::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = caFree;
}