mfc例子
1.头文件定义对象
CToolTipCtrl m_ToolTipCtrl; //提示控件
2.创建控件
//提示控件
m_ToolTipCtrl.Create(this);
m_ToolTipCtrl.Activate(TRUE);
m_ToolTipCtrl.AddTool(&m_bt1,TEXT("最小化"));
m_ToolTipCtrl.AddTool(&m_bt2,TEXT("最大化"));
m_ToolTipCtrl.AddTool(&m_bt3,TEXT("关闭游戏"));
3.消息解释
BOOL PreTranslateMessage(MSG* pMsg); //提示消息
if (m_ToolTipCtrl.m_hWnd!=NULL)
{
m_ToolTipCtrl.RelayEvent(pMsg);
}
return __super::PreTranslateMessage(pMsg);
win32例子
m_hwnd[0]=GetDlgItem(win.hwnd,IDC_CHECK1);
//创建提示工具栏
win.m_hTool=CreateWindow(TOOLTIPS_CLASS,NULL,WS_POPUP,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,win.hwnd,NULL,win.hInst,NULL);
assert(win.m_hTool);
//启用工具条提示
SendMessage(win.m_hTool,TTM_ACTIVATE,TRUE,0);
//设置提示窗口的信息
TOOLINFO tti;
memset(&tti, 0, sizeof(TOOLINFO));
tti.cbSize = sizeof(TOOLINFO);
tti.uFlags = TTF_IDISHWND | TTF_SUBCLASS ;
tti.hwnd = win.hwnd;
tti.uId = (UINT_PTR)m_hwnd[0]; //需要提示的控件句柄
tti.lpszText = TEXT("我是你的大皇冠"); //提示的内容
//新增一个提示
SendMessage(win.m_hTool,TTM_ADDTOOL,0,(LPARAM)(LPTOOLINFO)&tti);
tti.uId = (UINT_PTR)m_hwnd[1]; //需要提示的控件句柄
SendMessage(win.m_hTool,TTM_ADDTOOL,0,(LPARAM)(LPTOOLINFO)&tti);
SendMessage(win.m_hTool,TTM_SETDELAYTIME,0,200); //设置延时
SendMessage(win.m_hTool, TTM_SETTIPTEXTCOLOR,RGB(0,0,0),0); //设置提示文本颜色
SendMessage(win.m_hTool, TTM_SETTIPBKCOLOR, RGB(0,255,0),0); //设置提示框背景颜色
return ;
case WM_MOUSEMOVE:
{
//SendMessage(win.m_hTool,TTM_RELAYEVENT,0,(LPARAM)&uMsg);
//SendMessage(win.m_hTool,TTM_TRACKPOSITION,0,(LPARAM)MAKELPARAM(LOWORD(lParam)+50, HIWORD(lParam)+50));
}
break;