Tooltips for ToolBar.
-
Hello everyone, I used the following code to implement the tooltip for a toolbar. But the tooltip won't be displayed when the toolbar window is not active. I know that I can set TTS_ALWAYSTIP to solve this problem. But I don't know how to set it. There is no CToolTipCtrl in my application. Thanks a lot in advance. BEGIN_MESSAGE_MAP(CMyView, CView) ... ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify) END_MESSAGE_MAP() void CMyView::OnInitialUpdate() { CView::OnInitialUpdate(); CEdit* pEdit = new CEdit; pEdit->Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, CRect(10, 10, 100, 100), this, 111); EnableToolTips(TRUE); // enable tool tips for view } //Notification handler BOOL CMyView::OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult) { // need to handle both ANSI and UNICODE versions of the message TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR; TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR; CString strTipText; 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 = ::GetDlgCtrlID((HWND)nID); } if (nID != 0) // will be zero on a separator strTipText.Format("Control ID = %d", nID); if (pNMHDR->code == TTN_NEEDTEXTA) lstrcpyn(pTTTA->szText, strTipText, sizeof(pTTTA->szText)); else _mbstowcsz(pTTTW->szText, strTipText, sizeof(pTTTW->szText)); *pResult = 0; return TRUE; // message was handled } Thanks Bin