TBBUTTON tbButtons[numButtons] =
{
{ MAKELONG(STD_FILENEW, ImageListID), IDM_NEW, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"New" },
{ MAKELONG(STD_FILEOPEN, ImageListID), IDM_OPEN, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Open"},
{ MAKELONG(STD_FILESAVE, ImageListID), IDM_SAVE, 0, buttonStyles, {0}, 0, (INT_PTR)L"Save"}
};STD_FILEOPEN是 windows自定义的 id, 和imagelistid组合后 是什么意思呢?难道可以随意组合嘛? 我觉得 随意组合后的结果,还是一个正确的位图id嘛?怕不是吧。
怎么可以随意组合呢?
{
{ MAKELONG(STD_FILENEW, ImageListID), IDM_NEW, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"New" },
{ MAKELONG(STD_FILEOPEN, ImageListID), IDM_OPEN, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Open"},
{ MAKELONG(STD_FILESAVE, ImageListID), IDM_SAVE, 0, buttonStyles, {0}, 0, (INT_PTR)L"Save"}
};STD_FILEOPEN是 windows自定义的 id, 和imagelistid组合后 是什么意思呢?难道可以随意组合嘛? 我觉得 随意组合后的结果,还是一个正确的位图id嘛?怕不是吧。
怎么可以随意组合呢?
const int ImageListID = 0;看这里!!! 我随意修改了一下: TBBUTTON tbButtons[numButtons] =
{
{ 10000, IDM_NEW, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"New" },
{ MAKELONG(STD_FILEOPEN, ImageListID), IDM_OPEN, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Open"},
{ MAKELONG(STD_FILESAVE, ImageListID), IDM_SAVE, 0, buttonStyles, {0}, 0, (INT_PTR)L"Save"}
};结果发现,第一个button的图标不见了可见是不能够随意修改的,那么tbbutton的第一个字段到底该如何赋值呢?遵循什么规则呢?
#define STD_COPY 1
#define STD_PASTE 2
#define STD_UNDO 3
#define STD_REDOW 4
#define STD_DELETE 5
#define STD_FILENEW 6
#define STD_FILEOPEN 7
#define STD_FILESAVE 8
#define STD_PRINTPRE 9
#define STD_PROPERTIES 10
#define STD_HELP 11
#define STD_FIND 12
#define STD_REPLACE 13
#define STD_PRINT 14如果:const int ImageListID = 0;
MAKELONG(STD_FILEOPEN, ImageListID) 后 还是 STD_FILEOPEN
不 需要 这么 搞的。你要 试试的话,可以改 高字:
const int ImageListID = 1;
MAKELONG(STD_FILEOPEN,ImageListID)
这个 1 可能 自绘时 会 用到。
可以试试这个完成源码,粘贴就可以用了, 来自msdn调用函数放在wm_create即可
HIMAGELIST g_hImageList = NULL;HWND CreateSimpleToolbar(HWND hWndParent)
{
// Declare and initialize local constants.
const int ImageListID = 0;
const int numButtons = 3;
const int bitmapSize = 16; const DWORD buttonStyles = BTNS_AUTOSIZE; // Create the toolbar.
HWND hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
WS_CHILD | TBSTYLE_WRAPABLE, 0, 0, 0, 0,
hWndParent, NULL, hInst, NULL); if (hWndToolbar == NULL)
return NULL; // Create the image list.
g_hImageList = ImageList_Create(bitmapSize, bitmapSize, // Dimensions of individual bitmaps.
ILC_COLOR16 | ILC_MASK, // Ensures transparent background.
numButtons, 0); // Set the image list.
SendMessage(hWndToolbar, TB_SETIMAGELIST,
(WPARAM)ImageListID,
(LPARAM)g_hImageList); // Load the button images.
SendMessage(hWndToolbar, TB_LOADIMAGES,
(WPARAM)IDB_STD_SMALL_COLOR,
(LPARAM)HINST_COMMCTRL); // Initialize button info.
// IDM_NEW, IDM_OPEN, and IDM_SAVE are application-defined command constants. TBBUTTON tbButtons[numButtons] =
{
{ MAKELONG(STD_FILENEW, ImageListID), IDM_NEW, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"New" },
{ MAKELONG(STD_FILEOPEN, ImageListID), IDM_OPEN, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Open"},
{ MAKELONG(STD_FILESAVE, ImageListID), IDM_SAVE, 0, buttonStyles, {0}, 0, (INT_PTR)L"Save"}
}; // Add buttons.
SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
SendMessage(hWndToolbar, TB_ADDBUTTONS, (WPARAM)numButtons, (LPARAM)&tbButtons); // Resize the toolbar, and then show it.
SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);
ShowWindow(hWndToolbar, TRUE); return hWndToolbar;
}const int ImageListID = 0;// 换成1后,toolbar上的3个按钮的图标不见了。奇怪难道只能是0吗?msdn对toolbar的数据结构TBBUTTON 的这个字段的解释到底是啥意思啊?比如 我想换成自定义的icon。
肯定要填我自己的icon的id,但是又不能乱填写.
Creates a LONG value by concatenating the specified values.wLow
The low-order word of the new value.
wHigh
The high-order word of the new value.
TBBUTTON tbButtons[numButtons] =
{
{ IDI_ICON1, IDM_NEW, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"New" },
{ MAKELONG(STD_FILEOPEN, ImageListID), IDM_OPEN, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Open"},
{ MAKELONG(STD_FILESAVE, ImageListID), IDM_SAVE, 0, buttonStyles, {0}, 0, (INT_PTR)L"Save"}
};看第一个 参数用的是icon, 16*16,原因是:// Create the image list.
g_hImageList = ImageList_Create(bitmapSize, bitmapSize, // Dimensions of individual bitmaps.
ILC_COLOR16 | ILC_MASK, // Ensures transparent background.
numButtons, 0); 里面要求16*16的
不是需要makelong转换一下么?
IDI_ICON1的值130 和 谁makelong?
如果和imaglist的id makelong的话,那么是多余的,
因为其值是0.
最终可以显示的,是 采用系统自己的图标,比如 打开文件的那种图标,一直想改成自定义的图标,所以肯定的修改id啊(图标的id)结果看不到自定义的了
getlasterror又不管用谢谢你额了啊有经验的帮忙看看
直接 给 一个 IDI_XXX 就行了
TBBUTTON tbButtons[numButtons] =
{
{ IDI_ICON1, IDM_NEW, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"New" },
{ MAKELONG(STD_FILEOPEN, ImageListID), IDM_OPEN, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Open"},
{ MAKELONG(STD_FILESAVE, ImageListID), IDM_SAVE, 0, buttonStyles, {0}, 0, (INT_PTR)L"Save"}
};
10楼,你看,确实不行,是否是位图或者图标有要求,我的格式不对所致 16*16 , 位深度为32
代码在20,就不贴了
没有看到icon啊代码在20楼,就不贴了谁帮忙试试
我2台机子都不成功,不可以看到图标
CMyToolBar:: ONCreate
{
BOOL bl=m_ImageList.Create(IDB_BITMAP1,16,10,ILC_COLOR4 | ILC_MASK);
if(bl)
{
CToolBarCtrl &tbc=GetToolBarCtrl();
tbc.SetImageList(m_ImageList);
}
......
}IDB_BITMAP1 在资源中 插入 一个 bmp, 上 面 放 几个 16,15,的 图(可以从 toolbar 复制)这样 就可以 显示 你的 icon 了。