Mega Code Archive

 
Categories / Delphi / Ide Indy
 

Manipulating Coolbars at runtime

Title: Manipulating Coolbars at runtime Question: How to send Coolbar messages to manipulate them ! Answer: Manipulating Coolbars is a bit of a nuisance, and not as easy as most other Delphi controls. Anyway, you have to send the coolbar messages to manipulate bands. (See function TCoolBar.UpdateItem in ComCtrls.pas.) Here is a very simple example. This code puts the first 3 bands onto the 1st row (each with width = 75) and any more bands onto new rows by themselves. (Add CommCtrl to your "uses" list.) procedure TForm1.Button1Click(Sender: TObject); var i: Integer; BandInfo: TReBarBandInfo; begin // Delete all the bands!! for i := 0 to Coolbar1.Bands.Count - 1 do Coolbar1.Perform(RB_DELETEBAND, 0, 0); // Reinsert the bands as we want them. for i := 0 to Coolbar1.Bands.Count - 1 do begin FillChar(BandInfo, SizeOf(TReBarBandInfo), 0); BandInfo.cbSize := SizeOf(TReBarBandInfo); BandInfo.fMask := RBBIM_SIZE or RBBIM_CHILD or RBBIM_CHILDSIZE or RBBIM_STYLE; Coolbar1.Perform(RB_GETBANDINFO, i, Integer(@BandInfo)); if (i 2) then BandInfo.fStyle := BandInfo.fStyle or RBBS_BREAK; BandInfo.hwndChild := Coolbar1.Bands[i].Control.Handle; BandInfo.cx := 75; BandInfo.cxMinChild := Coolbar1.Bands[i].MinWidth; BandInfo.cyMinChild := Coolbar1.Bands[i].MinHeight; Coolbar1.Perform(RB_INSERTBAND, i, Integer(@BandInfo)); end; end;