如何在VC的API编程中调用函数来使用Toolbar

用什么函数,怎么调用... 用什么函数,怎么调用 展开
 我来答
ChikaIto
2008-11-17 · TA获得超过326个赞
知道小有建树答主
回答量:205
采纳率:0%
帮助的人:0
展开全部
凡例:

HWND hToolBar; // Toolbar句柄

// Toolbar的Button数组
TBBUTTON tlbBtns[] =
{
{ 0, ID_FOPEN, TBSTATE_ENABLED, BTNS_BUTTON, 0, 0 },
{ 1, ID_FCLOSE, TBSTATE_INDETERMINATE, BTNS_BUTTON, 0, 0 },
{ 2, ID_FSAVE, TBSTATE_INDETERMINATE, BTNS_BUTTON, 0, 0 },
{ 0, 0, TBSTATE_ENABLED, BTNS_SEP, 0, 0 }, // 分割条
{ 3, ID_FABOUT, TBSTATE_ENABLED, BTNS_BUTTON, 0, 0 }
};

hToolBar= CreateToolbarEx(hWndParent,
TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | WS_CHILD | WS_VISIBLE,
IDR_TOOLBAR, 4, hInstance, IDR_TOOLBAR,
(LPCTBBUTTON)&tlbBtns, 5, 0, 0, 16, 16, sizeof(TBBUTTON)); // 创建Toolbar,IDR_TOOLBAR是资源文件中Toolbar的ID

// 下面的代码用于创建并添加ImageList到Toolbar,一般情况下按钮上的图片会不好看
HIMAGELIST hImgLst = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 4, 4);
HBITMAP hFOpen = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_FOPEN));
HBITMAP hFClos = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_FCLOSE));
HBITMAP hFSave = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_FSAVE));
HBITMAP hFAbut = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_FABOUT));

ImageList_AddMasked(hImgLst, hFOpen, RGB(255, 0, 255));
ImageList_AddMasked(hImgLst, hFClos, RGB(255, 0, 255));
ImageList_AddMasked(hImgLst, hFSave, RGB(255, 0, 255));
ImageList_AddMasked(hImgLst, hFAbut, RGB(255, 0, 255));
DeleteObject(hFOpen);
DeleteObject(hFClos);
DeleteObject(hFSave);
DeleteObject(hFAbut);
SendMessage(hWndTlbOptn, TB_SETIMAGELIST, 0, (long)hImgLst); // 按钮可用时的ImageList

hImgLst = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 4, 4);

hFOpen = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_FOPEND));
hFClos = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_FCLOSED));
hFSave = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_FSAVED));
hFAbut = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_FABOUTD));

ImageList_AddMasked(hImgLst, hFOpen, RGB(255, 0, 255));
ImageList_AddMasked(hImgLst, hFClos, RGB(255, 0, 255));
ImageList_AddMasked(hImgLst, hFSave, RGB(255, 0, 255));
ImageList_AddMasked(hImgLst, hFAbut, RGB(255, 0, 255));
DeleteObject(hFOpen);
DeleteObject(hFClos);
DeleteObject(hFSave);
DeleteObject(hFAbut);
SendMessage(hWndTlbOptn, TB_SETDISABLEDIMAGELIST, 0, (LPARAM)hImgLst); // 按钮不可用时的ImageList
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式