给对话框ToolBar加ToolTip

1,.h
afx_msg BOOL Ontooltiptext(UINT,   NMHDR*   pnmhdr,   LRESULT*   presult);

2,.cpp
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW,   0,   0xffff,   Ontooltiptext)  
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA,   0,   0xffff,   Ontooltiptext)

3,
BOOL   CXXXDlg::Ontooltiptext(UINT,   NMHDR* pnmhdr,   LRESULT* presult)  

 int   AFXAPI   AfxLoadString(UINT   nIDS,   LPTSTR   lpszBuf,   UINT   nMaxBuf   =   256);
 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_NOMOVE|SWP_NOSIZE);  


 return   TRUE;         //   message   was   handled  
}    

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值