求一个给工具栏贴上自己的图标的demo
求一个给工具栏贴上自己的图标的demo. 条件,用以下函数CreateSimpleToolbar实现.\
说明:这个函数是msdn上的, 给工具栏上添加3个图标,这些图标均是windows预定义的。
代码是对的, 毫无问题,但是我希望在这个基础上贴自己的图标,非系统的, 搞了很久了,一直不成功。
亲们,自己可以验证代码,没有验证过的别乱回帖,谢谢。
注意出现有汉字的那行代码,我在那里做了个小小的改动.
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, g_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" },
// 我想修改按钮“New"这里的图标,所以代码为: { IDI_ICON1, 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;
}
修改图标不成功。 不知道什么原因!
后来又发现一个问题,用mfc 创建工具栏,贴上自己的图标的时候,也会出现有的图标也看不到,
于是我猜测:图标大小及位深度和代码无法一一对应导致的。
所以,希望成功贴上自己图标的人,提供你的代码和你的icon,多谢。
我邮箱:
combobox2013@163.com
说明:这个函数是msdn上的, 给工具栏上添加3个图标,这些图标均是windows预定义的。
代码是对的, 毫无问题,但是我希望在这个基础上贴自己的图标,非系统的, 搞了很久了,一直不成功。
亲们,自己可以验证代码,没有验证过的别乱回帖,谢谢。
注意出现有汉字的那行代码,我在那里做了个小小的改动.
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, g_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" },
// 我想修改按钮“New"这里的图标,所以代码为: { IDI_ICON1, 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;
}
修改图标不成功。 不知道什么原因!
后来又发现一个问题,用mfc 创建工具栏,贴上自己的图标的时候,也会出现有的图标也看不到,
于是我猜测:图标大小及位深度和代码无法一一对应导致的。
所以,希望成功贴上自己图标的人,提供你的代码和你的icon,多谢。
我邮箱:
combobox2013@163.com
...全文
相关推荐
工具栏的背景和图标的透明demo问题
目标: 1. 在工具栏上贴个背景图片 2. 工具栏上的各图标透明。这些图标是动态加载的BMP图片,请不要使用加载到工程中的图片,因为我需要在必要的时候动态改变这些图片。另外,最好不要使用icon,我现在的架构基本上只支持bmp图片,如果要改成icon的话,可能要花费些时间才行 我现在已经有一个正规的工程,可以贴背景图片上去,但是图标无法透明。现在新做了一个工程(专门用来调试的),只是派生了工具栏,并加载了一个图标。现在连背景都画不出来了。 请各位协助达到上面的两个目标。先看一下问题1是咋回事,然后再说一下目标2该如何实现。 关于目标2,现在的工程中,如果我不派生工具栏的话,图像应该已经是透明的了,但我一加工具栏就不透明了。 涉及到的关键内容有: CToolbar(工具栏)、图标、背景图片、透明
真彩工具栏,超漂亮,可用于美化界面。付实例DEMO-color toolbar ,good
真彩工具栏,超漂亮,可用于美化界面。付实例DEMO-color toolbar ,good
arxMenubarDemo,arx带mfc工具栏,弹出式下拉菜单以及图标按钮,跟随鼠标自动弹出菜单,源自网络
arxMenubarDemo,arx带mfc工具栏,弹出式下拉菜单以及图标按钮,跟随鼠标自动弹出菜单,源自网络
ExtJs 1714 个图标 Demo
包含 css文件 icon图标文件 一个Demo html 1714个图标,有需要可下载.
新浪微博Android版底部工具栏的Demo
新浪微博Android版底部工具栏的Demo 对应博客 http://blog.csdn.net/michael__li/article/details/6945016


