Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 818
  • Last Modified:

Changing toolbar tooltips at runtime in VC6.0 SDI app

I have a VC60 SDI app.  I have a tool bar with several buttons on it (IDR_MAINFRAME).  
I know how to set the tool tips for these buttons during design time.  But I want to be able to change the tool tips, when necessary, during run-time.  

Any help is greatly appreciated.

0
clintonJ
Asked:
clintonJ
  • 2
1 Solution
 
VolkerBeckCommented:
First add the following two lines to the message map of CMainFrame:
    ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
    ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)

Additionally add the code of the attached Code Snipped. This is mainly a copy of MFCs  CFrameWnd::OnToolTipText. In the line
strTipText="ThisIsATest";   //set text depending on nID here
you can add the code for defining any tool tip depending on nID at run time.
The code below is based on MFC 8.0, so maybe you need to adjust it for MFC 4.2. But you can also copy CFrameWnd::OnToolTipText from there and modify it four your purpose.
BOOL CMainFrame::OnToolTipText(UINT, 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_PTR 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="ThisIsATest";   //set text depending on nID here
	}
#ifndef _UNICODE
	if (pNMHDR->code == TTN_NEEDTEXTA)
		Checked::strncpy_s(pTTTA->szText, _countof(pTTTA->szText), strTipText, _TRUNCATE);
	else
		_mbstowcsz(pTTTW->szText, strTipText, _countof(pTTTW->szText));
#else
	if (pNMHDR->code == TTN_NEEDTEXTA)
		_wcstombsz(pTTTA->szText, strTipText, _countof(pTTTA->szText));
	else
		Checked::wcsncpy_s(pTTTW->szText, _countof(pTTTW->szText), strTipText, _TRUNCATE);
#endif
	*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|SWP_NOOWNERZORDER);
 
	return TRUE;    // message was handled}
}

Open in new window

0
 
VolkerBeckCommented:
The MFC 8.0 code provided by me above will definitely not work in VC6.0 (e.g. wcsncpy_s doesn't exist there). So just copy the original CFrameWnd::OnToolTipText of your VC6 (search in the MFC directory of your VC6 installation) and modify it for CMainFrame::OnToolTipText the way shown above.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now