System images for Toolbar buttons
Select messages from
# through # FAQ
[/[Print]\]

DELPHI AREA -> DELPHI AREA's Products

#1: System images for Toolbar buttons Author: Ian HinsonLocation: Melbourne, Australia PostPosted: 20/06/04 13:26
    —
Here's a tip many Delphi programmers may find useful:
How to get more "free" (and very useful) toolbar buttons from Windows.

1) Create a toolbar and add 15 or more buttons to it. Your form will look like this.



2) Add one line of code to the FormCreate event.

3) Run the program and the toolbar will look like this !!



The code that does this is:
procedure TForm1.FormCreate(Sender: TObject);
const
tbbitmap1: TTBAddBitmap = (hInst: HINST_COMMCTRL; nID: IDB_STD_SMALL_COLOR);
begin
SendMessage(ToolBar1.Handle, TB_ADDBITMAP, 15, integer(@tbbitmap1));
end;

All the icons that can be obtained using this technique are shown in the sample toolbar above because, each time you added a new toolbutton, Delphi incremented the ImageIndex automatically, and there are only 15 buttons in this CommCtrl set of icons.

The surprising thing is that the ImageIndex does matter (even though there is no TImageList on the form!)
Eg: If you put one button on the toolbar and set its ImageIndex to 7, then the OpenFile icon appears on it.

I'm writing this here because I initially thought these would be the images that TSysImageList provided.

Idea It would be neat to have a TImageList that supplies this particular set of images.

Ian.

#2:  Author: KambizLocation: Tehran, Iran PostPosted: 20/06/04 22:28
    —
Thanks Ian for this nice trick.

I added a new property (IconSet) to TSysImageList for this purpose. The update is available to download.

Greetings,
Kambiz

#3:  Author: Ian HinsonLocation: Melbourne, Australia PostPosted: 21/06/04 13:57
    —
Your enhancement (v1.50) to incorporate this into TSysImageList is ingenius !
This is now definitely a component that every Delphi programmer MUST HAVE.

Thanks,
Ian.



DELPHI AREA -> DELPHI AREA's Products


output generated using printer-friendly topic mod. All times are GMT

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group