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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

First add the following two lines to the message map of CMainFrame:

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
	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);
		_mbstowcsz(pTTTW->szText, strTipText, _countof(pTTTW->szText));
	if (pNMHDR->code == TTN_NEEDTEXTA)
		_wcstombsz(pTTTA->szText, strTipText, _countof(pTTTA->szText));
		Checked::wcsncpy_s(pTTTW->szText, _countof(pTTTW->szText), strTipText, _TRUNCATE);
	*pResult = 0;
	// bring the tooltip window above other popup windows
	::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,
	return TRUE;    // message was handled}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.