奇怪!为什么在对话框程序里加入工具栏无法实现工具栏的ToolTip功能??

moony_blue 2001-05-25 01:24:00
我在OnInitDialog()的相应代码是:
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MYTOOLBAR))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}

//......

...全文
223 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
302ycs 2001-08-08
  • 打赏
  • 举报
回复
if you want tooltips on your toolbar, you must handle the following messages ttn_needtexta and ttn_needtextw (for both ansi and unicode characters sets), in the following way :

1. add the message handlers declaration...

begin_message_map(cmydlg, cdialog)
...
on_notify_ex_range(ttn_needtextw, 0, 0xffff, ontooltiptext)
on_notify_ex_range(ttn_needtexta, 0, 0xffff, ontooltiptext)
end_message_map()

2. declare the function in your header file that way :

// generated message map functions
//{{afx_msg(cmydlg)
afx_msg bool ontooltiptext(uint, nmhdr* pnmhdr, lresult* presult);
//}}afx_msg

3. and finally code your ontooltiptext function that way (comes from mfc sample) :

bool cmydlg::ontooltiptext(uint, nmhdr* pnmhdr, lresult* presult)
{
assert(pnmhdr->code == ttn_needtexta || pnmhdr->code == ttn_needtextw);

// allow top level routing frame to handle the message
if (getroutingframe() != null)
return false;

// need to handle both ansi and unicode versions of the message
tooltiptexta* pttta = (tooltiptexta*)pnmhdr;
tooltiptextw* ptttw = (tooltiptextw*)pnmhdr;
tchar szfulltext[256];
cstring csttiptext;
cstring cststatustext;

uint nid = pnmhdr->idfrom;
if (pnmhdr->code == ttn_needtexta && (pttta->uflags & ttf_idishwnd) ||
pnmhdr->code == ttn_needtextw && (ptttw->uflags & ttf_idishwnd))
{
// idfrom is actually the hwnd of the tool
nid = ((uint)(word)::getdlgctrlid((hwnd)nid));
}

if (nid != 0) // will be zero on a separator
{
afxloadstring(nid, szfulltext);
// this is the command id, not the button index
afxextractsubstring(csttiptext, szfulltext, 1, '\n');
afxextractsubstring(cststatustext, szfulltext, 0, '\n');
}

// non-unicode strings only are shown in the tooltip window...
if (pnmhdr->code == ttn_needtexta)
lstrcpyn(pttta->sztext, csttiptext,
(sizeof(pttta->sztext)/sizeof(pttta->sztext[0])));
else
_mbstowcsz(ptttw->sztext, csttiptext,
(sizeof(ptttw->sztext)/sizeof(ptttw->sztext[0])));
*presult = 0;

// bring the tooltip window above other popup windows
::setwindowpos(pnmhdr->hwndfrom, hwnd_top, 0, 0, 0, 0,
swp_noactivate|swp_nosize|swp_nomove);


return true; // message was handled
}

now you have a toolbar with tooltips (the text shown in the tooltip box is defined the classic way, with the resource editor


remember to call EnableToolTip() in oninitdialog()

moony_blue 2001-05-28
  • 打赏
  • 举报
回复
难道就没人知道吗??
moony_blue 2001-05-26
  • 打赏
  • 举报
回复
up
moony_blue 2001-05-25
  • 打赏
  • 举报
回复
wo
moony_blue 2001-05-25
  • 打赏
  • 举报
回复
我推
moony_blue 2001-05-25
  • 打赏
  • 举报
回复
代码错在哪里呢?
seesi 2001-05-25
  • 打赏
  • 举报
回复
当然啦,你的ToolTip哪里定义了?
moony_blue 2001-05-25
  • 打赏
  • 举报
回复
代码错在哪里呢?

16,548

社区成员

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

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

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