ToolTips

barehawk 2002-08-27 04:18:03
如何在CView的派生类里面实现Tips功能,也就是说象VC的编辑环境那样,当鼠标移动到某个单次上时有提示信息,多谢各位,拜托!
...全文
48 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
barehawk 2002-08-28
  • 打赏
  • 举报
回复
to 啊毛
谢谢你!
han012 2002-08-27
  • 打赏
  • 举报
回复
1)在CView的派生类里定义一个CToolTipCtrl成员变量
2)在CView的派生类的OnCreate()函数中创建ToolTip窗口
int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;

//if(EnableToolTip())
{
// create tooltip window
m_tooltip.Create(this);

RECT rect;
GetClientRect(&rect);
m_tooltip.AddTool(this, LPSTR_TEXTCALLBACK, &rect, 1);
}
return 0;
}
3)在BOOL CMyView::PreTranslateMessage(MSG* pMsg) 中forward mouse message
{
// if(EnableToolTip())
{
switch(pMsg->message){
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
m_tooltip.RelayEvent(pMsg);
break;
}
}
return CView::PreTranslateMessage(pMsg);
}
4)在void CMyView::OnMouseMove(UINT nFlags, CPoint point)中进行
HitTest,tooltip窗口的显示/更新等操作,这一步比较复杂,要具体要求具体分析
5)完成tooltip的消息响应函数,针对消息TTN_NEEDTEXTW,TTN_NEEDTEXTA
BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
ON_WM_CREATE()
ON_WM_MOUSEMOVE()
ON_NOTIFY_EX(TTN_NEEDTEXTW,0,OnToolTipText)
ON_NOTIFY_EX(TTN_NEEDTEXT,0,OnToolTipText)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CMyView::OnToolTipText(UINT nID, NMHDR* pNMHDR, LRESULT* pResult)


关于Tooltip的使用请参见MSDN(有详细的例子):

The CToolTipCtrl class encapsulates the functionality of a “tool tip control,” a small pop-up window that displays a single line of text describing the purpose of a tool in an application. A “tool” is either a window, such as a child window or control, or an application-defined rectangular area within a window’s client area. A tool tip is hidden most of the time, appearing only when the user puts the cursor on a tool and leaves it there for approximately one-half second. The tool tip appears near the cursor and disappears when the user clicks a mouse button or moves the cursor off the tool.

CToolTipCtrl provides the functionality to control the initial time and duration of the tool tip, the margin widths surrounding the tool tip text, the width of the tool tip window itself, and the background and text color of the tool tip. A single tool tip control can provide information for more than one tool.

The CToolTipCtrl class provides the functionality of the Windows common tool tip control. This control (and therefore the CToolTipCtrl class) is available only to programs running under Windows 95 and Windows NT versions 3.51 and later.

For more information about enabling tool tips, seeTool Tips in Visual C++ Programmer’s Guide.

For more information on using CToolTipCtrl, seeControl Topics andUsing CToolTipCtrl in the Visual C++ Programmer’s Guide.

xglcm 2002-08-27
  • 打赏
  • 举报
回复
他那个是钩子吧
glhorse 2002-08-27
  • 打赏
  • 举报
回复
可能比较麻烦。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧