如何在ToolBar中添加bmp图片???

Seeso 2003-06-16 10:45:24
ImageList1: TImageList;(为Delphi可视化控件)

用下面的函数创建一个ToolBar
CreateToolBarEx(aparent,WS_CHILD or TBSTYLE_TOOLTIPS or CCS_ADJUSTABLE,1000,3,0,IDB_STD_SMALL_COLOR,0,0,16,16,16,16,SizeOf(TTBBUTTON));

tbb:array[0..2] of TTBBUTTON;
tbb[0].fsState := TBSTATE_ENABLED;
tbb[0].fsStyle := TBSTYLE_BUTTON;
tbb[0].dwData := 0;
tbb[0].iString :=0;
tbb[0].iBitmap:=0;
tbb[0].idCommand:=0;

tbb[1].fsState := TBSTATE_ENABLED;
tbb[1].fsStyle := TBSTYLE_CHECK ;
tbb[1].dwData := 0;
tbb[1].iString := 1;
tbb[1].iBitmap:=1;
tbb[1].idCommand:=1;

tbb[2].fsState := TBSTATE_ENABLED;
tbb[2].fsStyle :=TBSTYLE_BUTTON;
tbb[2].dwData := 0;
tbb[2].iString := 2;
tbb[2].iBitmap:=2;
tbb[2].idCommand:=2;

SendMessage(handle, TB_ADDBUTTONS,3,integer(@tbb));

双击ImageList1载入一组位图后,发送TB_ADDBITMAP消息后
SendMessage(handle, TB_ADDBITMAP,3,Integer(@ImageList1))

<br><hr>
请问各位:为何没有图片显示出来???(3个按钮可以正常显示)


...全文
285 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Seeso 2003-06-16
  • 打赏
  • 举报
回复
谢谢DelphiBoy2003的回答!
我是想自己做一个封装ToolBar各种消息的简装版ToolBar,必须用API函数来实现!
Thank you all the same!
DelphiBoy2003 2003-06-16
  • 打赏
  • 举报
回复
用ToolBar显示BMP图片需要这么麻烦吗,直接放一个ToolBar,放一个ImageList,然后把BMP图片加载到ImageList中去,然后指定ToolBar的Images属性为ImageList,然后你创建的每一个ToolButton都可以自己指定一个ImageList中图片的索引了!
Seeso 2003-06-16
  • 打赏
  • 举报
回复
谢谢 outer2000(天外流星)
你的程序完全正确,得100分
blueshu 2003-06-16
  • 打赏
  • 举报
回复
学习
outer2000 2003-06-16
  • 打赏
  • 举报
回复
1,这个消息TB_ADDBITMAP的第二个参数不能用TIMAGELIST来传递,因为IMAGLIST不是消息中规定的结构,WIN32中这个参数定义为;
TB_ADDBITMAP message adds one or more images to the list of button images available for a toolbar.

TB_ADDBITMAP
wParam = (WPARAM) nButtons;
lParam = (LPARAM) (LPTBADDBITMAP) lptbab; ////这里,看看


Parameters

nButtons

Number of button images in the bitmap.

lptbab

Pointer to a TBADDBITMAP structure that contains the identifier of a bitmap resource and the handle to the module instance with the executable file that contains the bitmap resource.
outer2000 2003-06-16
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,CommCtrl, ImgList;

type
TForm1 = class(TForm)
Button1: TButton;
ImageList1: TImageList;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
tbb:array[0..2] of TTBBUTTON;
dd:thandle;
mm:TBADDBITMAP;
d:Tbitmap;
begin
d:=tbitmap.Create ;
d.LoadFromFile('c:\a.bmp');
mm.hInst :=0;
mm.nID:=d.Handle;
tbb[0].fsState := TBSTATE_ENABLED;
tbb[0].fsStyle := TBSTYLE_BUTTON;
tbb[0].dwData := 0;
tbb[0].iString :=0;
tbb[0].iBitmap:=0;
tbb[0].idCommand:=0;

tbb[1].fsState := TBSTATE_ENABLED;
tbb[1].fsStyle := TBSTYLE_CHECK ;
tbb[1].dwData := 0;
tbb[1].iString := 1;
tbb[1].iBitmap:=1;
tbb[1].idCommand:=1;

tbb[2].fsState := TBSTATE_ENABLED;
tbb[2].fsStyle :=TBSTYLE_BUTTON;
tbb[2].dwData := 0;
tbb[2].iString := 2;
tbb[2].iBitmap:=2;
tbb[2].idCommand:=2;
dd:= CreateToolBarEx(form1.Handle,WS_CHILD ,1000,3,0,IDB_STD_SMALL_COLOR,@tbb[0],3,16,16,16,16,SizeOf(TTBBUTTON));
showwindow(dd,sw_show);
SendMessage(dd, TB_ADDBITMAP,3,integer(@mm))
end;
end.

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧