C++语言 为工具栏设置工具提示功能
BOOL CToolTipDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here //创建图像列表 m_ImageList.Create(32,32,ILC_COLOR24|ILC_MASK,1,1); //向图像列表中添加图标 m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1)); m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON2)); m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON3)); m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON4)); m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON5)); m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON6)); m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON7)); m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON8)); UINT array[11]; for(int i=0;i<11;i++) { if(i==3 || i==7 || i==9) array[i] = ID_SEPARATOR; //第4、8、10个按钮为分隔条 #define ID_SEPARATOR 0 else array[i] = i+1001; } m_ToolBar.Create(this); m_ToolBar.SetButtons(array,11); m_ToolBar.SetButtonText(0,"新建"); m_ToolBar.SetButtonText(1,"打开"); m_ToolBar.SetButtonText(2,"保存"); m_ToolBar.SetButtonText(4,"剪切"); m_ToolBar.SetButtonText(5,"复制"); m_ToolBar.SetButtonText(6,"粘贴"); m_ToolBar.SetButtonText(8,"打印"); m_ToolBar.SetButtonText(10,"帮助"); //关联图像列表 m_ToolBar.GetToolBarCtrl().SetImageList(&m_ImageList); m_ToolBar.SetSizes(CSize(40,50),CSize(32,32)); //设置按钮和图标的大小 m_ToolBar.EnableToolTips(TRUE); RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0); //AFX_IDW_CONTROLBAR_FIRST 在msdn中没有详细说明 用就可以了
return TRUE; // return TRUE unless you set the focus to a control }
创建一个基于对话框的应用程序, 将对话框的Caption属性修改为"设置工具栏按钮提示".
选择工作区窗口中的RecourceView选项卡,导入8个图标资源.
在对话框头文件中声明变量,代码如下:
CToolBar m_ToolBar;
CImageList m_ImageList;
CString m_TipText;
学习笔记转摘于:
丝酷网 http://www.pythonschool.com/