这几天弄这个鼠标提示,在网上查了许多都不得行,今天终于弄出来了,现分享下
//工具栏显示提示信息
//创建工具栏 //1,添加工具资源 //2.创建工具栏 HWND hToolBar = ::CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_VISIBLE | WS_CHILD | WS_BORDER | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | TBSTYLE_TOOLTIPS,//要显示鼠标提示信息就要用TBSTYLE_TOOLTIPS风格 0, 0, 0, 0, m_hWnd, (HMENU)IDR_TOOLBAR2, GetModuleHandle(NULL), 0); //3.创建图像列表 HIMAGELIST hImageList = ImageList_Create(20, 20, ILC_COLOR32 | ILC_MASK, 5, 1); //如果不能用ImageList_Create就要在头文件中添加 /*#include <CommCtrl.h> #ifndef _COMCTL32_LIB #define _COMCTL32_LIB #pragma comment(lib,"comctl32.lib") #endif */ //4.加载工具栏位图资源ID HBITMAP hBitMap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_TOOLBAR2)); //5.把位图添加到图像列表中 ImageList_Add(hImageList, hBitMap, 0); //6.设置工具栏的图像列表 SendMessage(hToolBar, TB_SETIMAGELIST, 0, (LPARAM)hImageList); //7.添加相对应的按钮类型 TBBUTTON btn1 = { 0 }; btn1.iBitmap = 0; //图像索引 btn1.fsState = TBSTATE_ENABLED; btn1.fsStyle = TBSTYLE_BUTTON; //按钮样式 btn1.idCommand = IDM_ADD; //按钮ID btn1.iString = (INT_PTR)TEXT("添加");//显示文本信息 TBBUTTON btn2 = { 0 }; btn2.iBitmap = 1; //图像索引 btn2.fsState = TBSTATE_ENABLED; btn2.fsStyle = TBSTYLE_BUTTON; //按钮样式 btn2.idCommand = IDM_EDIT; //按钮ID btn2.iString = (INT_PTR)TEXT("修改");//显示文本信息 TBBUTTON btn3 = { 0 }; btn3.iBitmap = 2; //图像索引 btn3.fsState = TBSTATE_ENABLED; btn3.fsStyle = TBSTYLE_BUTTON; //按钮样式 btn3.idCommand = IDM_DEL; //按钮ID btn3.iString = (INT_PTR)TEXT("删除");//显示文本信息 TBBUTTON btn4 = { 0 }; btn4.iBitmap =3; //图像索引 btn4.fsState = TBSTATE_ENABLED; btn4.fsStyle = TBSTYLE_BUTTON; //按钮样式 btn4.idCommand = IDM_FIND; //按钮ID btn4.iString = (INT_PTR)TEXT("查询");//显示文本信息 TBBUTTON btn5 = { 0 }; btn5.iBitmap = 4; //图像索引 btn5.fsState = TBSTATE_ENABLED; btn5.fsStyle = TBSTYLE_BUTTON; //按钮样式 btn5.idCommand = IDM_HELP; //按钮ID btn5.iString = (INT_PTR)TEXT("帮助");//显示文本信息 //8.把按钮组成数组 TBBUTTON btnArray[] = { btn1,btn2,btn3,btn4,btn5 }; //9.把数组添加到工具栏中 SendMessage(hToolBar, TB_ADDBUTTONS, 5, (LPARAM)btnArray); //10.如果要在鼠标悬停时显示文本,就要隐藏文本 // 把WPARAM值设为0,就会隐藏文本,默认是要显示 SendMessage(hToolBar, TB_SETMAXTEXTROWS, 0, 0); //11.自动调整大小 SendMessage(hToolBar, TB_AUTOSIZE, 0, 0);
//如果不能用ImageList_Create就要在头文件中添加
/#include <CommCtrl.h>
#ifndef _COMCTL32_LIB
#define _COMCTL32_LIB
#pragma comment(lib,"comctl32.lib")
#endif
效果图: