我木有现成的,但是推荐你到codeproject上搜搜,应该不少。
解决方案 »
- 如何判断俩个CString变量是否相等
- 组框里的tab显示
- Unhandled exception in **.exe (MFC42D.DLL):0X00000005:Access Violation 错误 急急!!!!!!
- 初学用VC开发client/server软件
- 如何搜索到MFC DLL中的资源?!
- 各位大虾。小弟很郁闷啊,有空看看这个
- 我就这182分了,问一个曲面重构的问题,只要提供思路就行
- DLL编译警告和解决方法。
- 一直没有相通的一个问题!
- mfc tab control怎么用的?
- 我下载疑难总汇的 例子怎么编译不过去~~~~~
- 动态创建了一个图片控件,怎么在控件中显示我打开的图片
这个是不是你要得?
多谢你提供,真不是很巧的是文章里的那个函数 和我说的一样,呵呵这个函数是自定义的,你却用其当搜索关键字眼 这个函数是msdn提供的一个例子里的自定义的
BTNS_AUTOSIZE
include commctrl.h里,顺便加上其相应的库:
comctl32.lib还有请在合适的的地方加上 initcommoncontrols始化公共控件库
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_COLOR32 | ILC_MASK, // Ensures transparent background.
numButtons, 0); // 注意这个ILC_COLOR32参数,现在的图一般是32位的 int i1 = ImageList_AddIcon(g_hImageList, LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1))); // ImageList_ReplaceIcon
// 下面自己加
// 可以加ImageList_LoadBitmap位图
// ImageList_LoadImage // Set the image list.
SendMessage(hWndToolbar, TB_SETIMAGELIST,
(WPARAM)ImageListID,
(LPARAM)g_hImageList); // 这个不要了,加载的是Toolbar自带的图标
// 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), 0, 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(i1, ImageListID), 0, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Open"},
{ MAKELONG(i1, ImageListID), 0, 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;
}
++ 图标没有关联到imagelist中导致的。在TB_SETIMAGELSIT之前必须创建icon,否则就是系统自带的了.TBUTTON的第0个字段的意思是index in imagelist
iBitmap
Type: int
Zero-based index of the button image. Set this member to I_IMAGECALLBACK, and the toolbar will send the TBN_GETDISPINFO notification code to retrieve the image index when it is needed.当没有添加自定义的图标的时候, 这个值就是系统的一些常数
http://msdn.microsoft.com/en-us/library/windows/desktop/bb787433(v=vs.85).aspx
#define IDB_STD_SMALL_COLOR 0
#define IDB_STD_LARGE_COLOR 1
#define IDB_VIEW_SMALL_COLOR 4
#define IDB_VIEW_LARGE_COLOR 5
上面 是 资源的 instance
每个 都是不同的, 表示 资源在 不同的 instance 里
HINST_COMMCTRL 在 从comctrl32.dll 中。
而:
// Load the button images.
SendMessage(hWndToolbar, TB_LOADIMAGES,
(WPARAM)IDB_STD_SMALL_COLOR,
(LPARAM)HINST_COMMCTRL);
只有一个,那个在 你的exe中的(就是 你 exe 的 instance 里)
{ IDI_ICON1, IDM_NEW, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"New" },
却没装入!
是的, 没有装上本想结贴,但是你的回答有些不对,所以只好纠正lParam
Instance handle. This parameter must be set to HINST_COMMCTRL
说明这个消息的lparam只能是这个参数,其他不行的。而wparma则是标记了系统已经定义好的button image list.
也就说,有不同的imagelist,选一个而已,然后在tbbuttons这个结构体里设计好索引即可到这些imagelist里寻找图标不对,请跟正, 如果没有异议, 该结贴散分了
使用 AddBitmap 函数。 可以 装载 不同 instance 里 的 bmp。
在 帮助文件 里 搜索 “CreateTheToolBar”。看看 它 是 怎么 装载 IDB_STD_SMALL_COLOR 和 IDB_VIEW_SMALL_COLOR 的。
这段代码 都用 HINST_COMMCTRL, 但 TBADDBITMAP 一个是 IDB_STD_SMALL_COLOR
另一个 是 IDB_VIEW_SMALL_COLOR。
要 装载 app 的
TBADDBITMAP 结构要 输入
hInst 和
IDB_APPTB // 你的 exe 定义的 bmp 。
你的 IDI_ICON1 是 IDB_APPTB 中的 索引
如果 IDB_APPTB 图标就一个 那就是 0.
TBBUTTON tbButtons [] =
{
{STD_FILENEW, IDM_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{STD_FILEOPEN, IDM_OPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{STD_FILESAVE, IDM_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, 0},
{VIEW_LARGEICONS, IDM_LARGEICON, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{VIEW_SMALLICONS, IDM_SMALLICON, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{VIEW_LIST, IDM_LISTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{VIEW_DETAILS, IDM_REPORTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
};
//
HWND CreateTheToolbar (HWND hWndParent)
{
HWND hWndToolbar;
TBADDBITMAP tb;
int index, stdidx;hWndToolbar = CreateToolbarEx (hWndParent,
WS_CHILD | WS_BORDER | WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS,
ID_TOOLBAR, 11, (HINSTANCE)HINST_COMMCTRL, IDB_STD_SMALL_COLOR,
(LPCTBBUTTON)&tbButtons, 4, 0, 0, 100, 30, sizeof (TBBUTTON));// Add the system-defined view bitmaps.
// The hInst == HINST_COMMCTRL
// The nID == IDB_VIEW_SMALL_COLOR
tb.hInst = HINST_COMMCTRL;
tb.nID = IDB_VIEW_SMALL_COLOR;
stdidx = SendMessage (hWndToolbar, TB_ADDBITMAP, 12, (LPARAM)&tb);// Update the indexes to the bitmaps.
for (index = 4; index < NUM_BUTTONS; index++)
tbButtons[index].iBitmap += stdidx;// Add the view buttons.
SendMessage (hWndToolbar, TB_ADDBUTTONS, 4, (LONG) &tbButtons[4]);return hWndToolbar;
}
tb.nID = IDB_YOUR_TOOLBAR;
就可以把你 图标 加上去。
说白了tb_addbitmap的消息的相关使用操作起来繁琐的很。
多谢
主要问题在于 只能 ADD 不能 insert
add 加在后面,又不能 移动。