Changing toolbar tooltips at runtime in VC6.0 SDI app

Posted on 2008-11-17
Last Modified: 2013-11-20
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.

Question by:clintonJ
    LVL 2

    Accepted Solution

    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

    LVL 2

    Expert Comment

    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.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    format the code in java 6 60
    no14 challenge 14 46
    Use of condition with 'serial' in ansible 2 25
    Problem to event 3 27
    Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now