System images for Toolbar buttons

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

System images for Toolbar buttons

Postby Ian Hinson » June 20th, 2004, 1:26 pm

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.

Image

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

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

Image

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.
Ian Hinson
Active Member
Active Member
 
Posts: 9
Joined: June 20th, 2004, 12:31 pm
Location: Melbourne, Australia

Postby Kambiz » June 20th, 2004, 10:28 pm

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
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby Ian Hinson » June 21st, 2004, 1:57 pm

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.
Ian Hinson
Active Member
Active Member
 
Posts: 9
Joined: June 20th, 2004, 12:31 pm
Location: Melbourne, Australia


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 4 guests

cron