ТулБар со скрывающимися кнопками
Например как в TheBat:
Окно раздвинуто и не закрывает иконки
Окно сдвинуто, иконки закрыты
Скрытые иконки открываются стрелочками
Не знаю есть ли в си билдер, но для C# нужно свой-во CanOverflow = true сделать, а так копайте в строну winapi TBSTYLE_EX_DRAWDDARROWS и BTNS_DROPDOWN , а лучше не выносить себе мозг и писать такие вещи на с#
Код:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//
ToolBar1->HandleNeeded();
DWORD ExStyle = ToolBar1->Perform(TB_GETEXTENDEDSTYLE, 0, 0);
ExStyle |= TBSTYLE_EX_HIDECLIPPEDBUTTONS;
ToolBar1->Perform(TB_SETEXTENDEDSTYLE, 0, ExStyle);
int nCount = (int)::SendMessage(CoolBar1->Handle, RB_GETBANDCOUNT, 0, 0L);
TToolBar* tb;
for(int i = 0; i < nCount; i++)
{
REBARBANDINFO rbbi;
rbbi.cbSize = sizeof(REBARBANDINFO);
BOOL bRet = (BOOL)::SendMessage(CoolBar1->Handle, RB_GETBANDINFO, i, (LPARAM)&rbbi);
if(bRet && ((rbbi.hwndChild == ToolBar1->Handle) || (rbbi.hwndChild == ToolBar2->Handle)))
{
rbbi.fMask = RBBIM_STYLE| RBBIM_IDEALSIZE;
rbbi.fStyle |= RBBS_USECHEVRON;
rbbi.fStyle &= ~RBBS_NOGRIPPER;
rbbi.fStyle = RBBS_USECHEVRON | RBBS_HIDETITLE | RBBS_FIXEDBMP;
tb = (TToolBar*)CoolBar1->Bands->Items[i]->Control;
rbbi.cxIdeal = tb->Buttons[tb->ButtonCount-1]->Left + tb->Buttons[tb->ButtonCount-1]->Width + 5;
::SendMessage(CoolBar1->Handle, RB_SETBANDINFO, i, (LPARAM)&rbbi);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WMNotify(TMessage& Message)
{
//TODO: Add your source code here
LPNMHDR lpnmhdr;
LPNMREBARCHEVRON lpnmCVN;
TToolBar* tb;
TToolButton* tbtn;
int i;
int j;
TRect R;
TPoint P;
TMenuItem* mi;
TCoolBand* clb;
lpnmhdr = (LPNMHDR)Message.LParam;
if (lpnmhdr->code == RBN_CHEVRONPUSHED)
{
lpnmCVN = (LPNMREBARCHEVRON)Message.LParam;
int uBand = lpnmCVN->uBand;
tb = (TToolBar*)CoolBar1->Bands->Items[uBand]->Control;
R = tb->ClientRect;
//find first invisible button in toolbar
j = 0;
for (i = 0; i < tb->ButtonCount; i++)
{
tbtn = tb->Buttons[i];
if ((tbtn->Left + tbtn->Width) > R.Right)
{
j = i;
break;
}
}
if (j)
{
//{delete all existing items}
for (i = PopupMenuForToolbar->Items->Count-1; i >= 0; i--)
{
//mi = PopupMenuForToolbar->Items->Items[i];
PopupMenuForToolbar->Items->Delete(i);
}
//{add all invisible buttons as menu items}
for (i = j; i < tb->ButtonCount; i++)
{
mi = new TMenuItem(this);
tbtn = tb->Buttons[i-1];
if (tbtn->Style == tbsSeparator)
mi->Caption = "-";
else
{
mi->Caption = tbtn->Caption;
mi->Hint = tbtn->Hint;
mi->Tag = tbtn->Tag;
mi->OnClick = OnClick;//tbtn->OnClick;
}
PopupMenuForToolbar->Items->Add(mi);
}
// show popup menu
P = CoolBar1->ClientToScreen(TPoint(lpnmCVN->rc.left, lpnmCVN->rc.bottom));
PopupMenuForToolbar->Popup(P.x, P.y);
}
}
else TForm::Dispatch(&Message);
}
void __fastcall TForm1::FormResize(TObject *Sender)
{
REBARBANDINFO rbi;
rbi.cbSize = sizeof(REBARBANDINFO);
rbi.fMask = RBBIM_STYLE | RBBIM_IDEALSIZE;
for (int i = 0; i < CoolBar1->Bands->Count; i++)
{
TToolBar* tb = dynamic_cast<TToolBar*>(CoolBar1->Bands->Items[i]->Control);
if (!tb) continue;
::SendMessage(CoolBar1->Handle, RB_GETBANDINFO, i, (LPARAM)&rbi);
rbi.fStyle = rbi.fStyle | RBBS_USECHEVRON;
rbi.fStyle &= ~RBBS_NOGRIPPER;
rbi.cxIdeal = tb->Buttons[tb->ButtonCount-1]->Left + tb->Buttons[tb->ButtonCount-1]->Width + 5;
::SendMessage(CoolBar1->Handle, RB_SETBANDINFO, i, (LPARAM)&rbi);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton7Click(TObject *Sender)
{
TToolButton* tbtn = dynamic_cast<TToolButton*>(Sender);
if(!tbtn) return;
ShowMessage(tbtn->Caption);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnClick(TObject *Sender)
{
TMenuItem* mi = dynamic_cast<TMenuItem*>(Sender);
if(!mi) return;
ShowMessage(mi->Caption);
}
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//
ToolBar1->HandleNeeded();
DWORD ExStyle = ToolBar1->Perform(TB_GETEXTENDEDSTYLE, 0, 0);
ExStyle |= TBSTYLE_EX_HIDECLIPPEDBUTTONS;
ToolBar1->Perform(TB_SETEXTENDEDSTYLE, 0, ExStyle);
int nCount = (int)::SendMessage(CoolBar1->Handle, RB_GETBANDCOUNT, 0, 0L);
TToolBar* tb;
for(int i = 0; i < nCount; i++)
{
REBARBANDINFO rbbi;
rbbi.cbSize = sizeof(REBARBANDINFO);
BOOL bRet = (BOOL)::SendMessage(CoolBar1->Handle, RB_GETBANDINFO, i, (LPARAM)&rbbi);
if(bRet && ((rbbi.hwndChild == ToolBar1->Handle) || (rbbi.hwndChild == ToolBar2->Handle)))
{
rbbi.fMask = RBBIM_STYLE| RBBIM_IDEALSIZE;
rbbi.fStyle |= RBBS_USECHEVRON;
rbbi.fStyle &= ~RBBS_NOGRIPPER;
rbbi.fStyle = RBBS_USECHEVRON | RBBS_HIDETITLE | RBBS_FIXEDBMP;
tb = (TToolBar*)CoolBar1->Bands->Items[i]->Control;
rbbi.cxIdeal = tb->Buttons[tb->ButtonCount-1]->Left + tb->Buttons[tb->ButtonCount-1]->Width + 5;
::SendMessage(CoolBar1->Handle, RB_SETBANDINFO, i, (LPARAM)&rbbi);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WMNotify(TMessage& Message)
{
//TODO: Add your source code here
LPNMHDR lpnmhdr;
LPNMREBARCHEVRON lpnmCVN;
TToolBar* tb;
TToolButton* tbtn;
int i;
int j;
TRect R;
TPoint P;
TMenuItem* mi;
TCoolBand* clb;
lpnmhdr = (LPNMHDR)Message.LParam;
if (lpnmhdr->code == RBN_CHEVRONPUSHED)
{
lpnmCVN = (LPNMREBARCHEVRON)Message.LParam;
int uBand = lpnmCVN->uBand;
tb = (TToolBar*)CoolBar1->Bands->Items[uBand]->Control;
R = tb->ClientRect;
//find first invisible button in toolbar
j = 0;
for (i = 0; i < tb->ButtonCount; i++)
{
tbtn = tb->Buttons[i];
if ((tbtn->Left + tbtn->Width) > R.Right)
{
j = i;
break;
}
}
if (j)
{
//{delete all existing items}
for (i = PopupMenuForToolbar->Items->Count-1; i >= 0; i--)
{
//mi = PopupMenuForToolbar->Items->Items[i];
PopupMenuForToolbar->Items->Delete(i);
}
//{add all invisible buttons as menu items}
for (i = j; i < tb->ButtonCount; i++)
{
mi = new TMenuItem(this);
tbtn = tb->Buttons[i-1];
if (tbtn->Style == tbsSeparator)
mi->Caption = "-";
else
{
mi->Caption = tbtn->Caption;
mi->Hint = tbtn->Hint;
mi->Tag = tbtn->Tag;
mi->OnClick = OnClick;//tbtn->OnClick;
}
PopupMenuForToolbar->Items->Add(mi);
}
// show popup menu
P = CoolBar1->ClientToScreen(TPoint(lpnmCVN->rc.left, lpnmCVN->rc.bottom));
PopupMenuForToolbar->Popup(P.x, P.y);
}
}
else TForm::Dispatch(&Message);
}
void __fastcall TForm1::FormResize(TObject *Sender)
{
REBARBANDINFO rbi;
rbi.cbSize = sizeof(REBARBANDINFO);
rbi.fMask = RBBIM_STYLE | RBBIM_IDEALSIZE;
for (int i = 0; i < CoolBar1->Bands->Count; i++)
{
TToolBar* tb = dynamic_cast<TToolBar*>(CoolBar1->Bands->Items[i]->Control);
if (!tb) continue;
::SendMessage(CoolBar1->Handle, RB_GETBANDINFO, i, (LPARAM)&rbi);
rbi.fStyle = rbi.fStyle | RBBS_USECHEVRON;
rbi.fStyle &= ~RBBS_NOGRIPPER;
rbi.cxIdeal = tb->Buttons[tb->ButtonCount-1]->Left + tb->Buttons[tb->ButtonCount-1]->Width + 5;
::SendMessage(CoolBar1->Handle, RB_SETBANDINFO, i, (LPARAM)&rbi);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton7Click(TObject *Sender)
{
TToolButton* tbtn = dynamic_cast<TToolButton*>(Sender);
if(!tbtn) return;
ShowMessage(tbtn->Caption);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnClick(TObject *Sender)
{
TMenuItem* mi = dynamic_cast<TMenuItem*>(Sender);
if(!mi) return;
ShowMessage(mi->Caption);
}
//---------------------------------------------------------------------------