Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I show Tool tip for Multiline Edit box?

Posted on 2008-10-15
7
Medium Priority
?
1,538 Views
Last Modified: 2013-11-25
I have Multiline edit box. i need to show tool tip for the edit box. How can i set the tool tip text?
0
Comment
Question by:LearningCpp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 6

Expert Comment

by:tchamtieh
ID: 22719444
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22723407
Here is one possible solution:

1. Add a CToolTipCtrl http://msdn.microsoft.com/en-us/library/6b4cb3a5(VS.80).aspx member variable to you CDialog derived class:

CToolTipCtrl m_myToolTip;

2. Add the PreTranslateMessage method to your class:

afx_msg BOOL PreTranslateMessage(MSG * pMsg); // in the .h file

BOOL CMFCAppDlg::PreTranslateMessage(MSG * pMsg) // in the .cpp file
{
      m_myToolTip.RelayEvent(pMsg);

      return CDialog::PreTranslateMessage(pMsg);
}

3. Map you multi-line text box to a control variable and call it e.g. m_myMultiLineTextBox

4. Add the following code to the OnInit method of your class:

	if(m_myToolTip.Create(this)) {
		m_myToolTip.AddTool( &m_myMultiLineTextBox, _T("You are hovering over the text box!"));
		m_myToolTip.Activate(TRUE);
	}
	else {
		AfxMessageBox(_T("Unable to create the tool tip."));
	}

Open in new window

Output.png
0
 

Author Comment

by:LearningCpp
ID: 22730514
If multiline Edit box contains different strings on different line, then i want to display the contents of each line in tooltip.
Suppose Multiline edit box has:
Test1
Test2
Test3
Then i need to show all these data in tool tio and not the fixed string as you have shown.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:LearningCpp
ID: 22730855
I forgot to tell you that i have various controls on my UI. and i need to show tooltip for all the controls.
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22732095
You can add the tooltip for each control, see the following line in the OnInitDialog method:

m_myToolTip.AddTool(&m_myControlVariable, _T("Tooltip for the control"));
You can call this method several times passing to it your control mapped variable and its tooltip text.
As far as a tooltip for individual lines within a CEdit control is concerned I am not aware of a technique to do so as individual lines are not objects and furthermore change if the CEdit control is resized so it seems it would be necessary to write an algorithm to calculate the position of the mouse within the CEdit control, determine the line and based upon that show a tooltip; this would be rather complex. Perhaps you could switch to a list control and implement the tooltips for its individual items.
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22732921
Sorry, I might have misunderstood your question about dynamically setting the tooltip text, you can basically set the text value of the tooltip anytime like for example during an event such as on change then retrieve the value of your text box and set the tool tip to its text:

CString sToolTip;
m_TextBox.GetWindowTextW(sToolTip);
m_myToolTip.AddTool(&m_TextBox, sToolTip);
0
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 1000 total points
ID: 22732955
...and regarding the multiline ability for that you will have to extend and customize the tool tip class, here is one article regarding this enhancement:

http://www.codeproject.com/KB/miscctrl/tooltipex.aspx
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

610 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