Question

Mixed tooltips using AddTool (GetDlgItem (IDC_THIS), IDC_THIS) and AddTool (this, LPSTR_TEXTCALLBACK) how to.

Asked by: SteH

Wxp Pro SP1 VC++6.0 SP5

I have a dialog based app in which i display tooltips for various controls. Basics are done by the app wizard (activation, PreTranslateMessage, ... ?) and in the OnInitDialog I add the tooltips successfully using two methods:

AddTool (GetDlgItem (IDC_THIS), IDC_THIS); // control ID and string resource ID are identical numbers.
or for static controls
AddTool (this, csText, cr, IDC_THIS); // csText is a CString with the tooltip text and cr the CRect of the static control.

To allow changing tooltips for buttons which can be disabled as well I tried to add a third method:

AddTool (this); // or AddTool (this, LPSTR_TEXTCALLBACK, cr, IDC_THIS)
and added a handler for TTN_NEEDTEXT message. But this handler is never called. Why? Do I either need to supply text for all controls in this handler or supply the text in the AddTool call for all controls?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-08-19 at 02:52:05ID21099478
Tags

addtool

,

tooltip

Topic

Windows MFC Programming

Participating Experts
1
Points
500
Comments
25

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. GetDlgItem() casting. RONSLOW.....
    I have been reading through the entire Attn: RONSLOW... thread, and I have used this "bad" programming techninque, due to not knowing better, as you call it. What problems can come out of it? I have received input from some users that the program crashes for them, a...
  2. CString Conversion
    I have a dialog box that takes in users inputs. Those inputs are numbers that will be used in the COleDateTime() arguments. To get the values from the text boxes I use: int i = m_Month.GetLineCount(); CString buff, msg; m_Month.GetLine(i, buff.GetBuffer (m_Month.LineLe...
  3. GetDlgItem and handles
    My main class in inherited from CPropertySheet. I make four tabs by using: CPropertyPage::Construct(int ResourceId); then CPropertySheet::AddPage(CPropertyPage *page); On these page I have CButton class(check boxes) created using the resource editor. This is what I am...
  4. CRect and dialog control Create member fn's
    A lot of the MFC control classes require a CRect in their Create function. For example , I create a lsit box in a dialog (IDC_LISTBOX). To create a CListBox one of the parameters in the Create function is a CRect. How can I get the size of the rect for the Create function?...
  5. OnInitDialog( ) function VC++
    This is my first time using VC++: I'm trying to follow a database tutorial from a book and it isn't clear or it leaves out how to accomplish this simple task of adding names of database tables to a list box. I want to add the following code: m_TableList.AddString(&quo...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: SteHPosted on 2004-08-19 at 03:04:39ID: 11839618

I just used spy++ to look at tooltip messages and found none. mouse move messages are reported extensivly.

 

by: AndyAinscowPosted on 2004-08-19 at 04:29:40ID: 11840067

I have this

in OnInitDialog

            // Create the ToolTip control.
            m_tooltip.Create(this, TTS_NOPREFIX);
            m_tooltip.SetMaxTipWidth(600);      //allow it to be very wide
            m_tooltip.SetDelayTime(TTDT_AUTOPOP, 10000);      //display for 10 seconds (stop flashing)
            m_tooltip.Activate(TRUE);

            m_tooltip.AddTool(GetDlgItem(IDC_LIST1), LPSTR_TEXTCALLBACK);

and in PreTranslateMEssage
      {
            // Let the ToolTip process this message.
            m_tooltip.RelayEvent(pMsg);
      }
    if(pMsg->message == WM_MOUSEMOVE)
      {
            m_tooltip.Update();   //different text for different locations on the control
      }

and this to fill the tip
message map
      ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )

function
BOOL CSortDlg::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
{
    TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
    UINT nID =pNMHDR->idFrom;
      static TCHAR szMessage[256];
      static CPoint point;
      static UINT nIndex;
      static BOOL bOutside;

    if (pTTT->uFlags & TTF_IDISHWND)
    {
            if(::GetDlgCtrlID((HWND)nID) == IDC_LIST1)
            {
                  //We are on the list - are we on a line of text?
                  VERIFY(GetCursorPos(&point));
                  m_lstSort.ScreenToClient(&point);
                  nIndex = m_lstSort.ItemFromPoint(point, bOutside);

                  if(!bOutside)
                  {
                        m_lstSort.GetText(nIndex, szMessage);

                        pTTT->lpszText = szMessage;
                        return true;
                  }
            }
    }
    return false;
}

 

by: SteHPosted on 2004-08-19 at 04:57:18ID: 11840237

         m_tooltip.AddTool(GetDlgItem(IDC_LIST1), LPSTR_TEXTCALLBACK);
instead of
          m_tooltip.AddTool (this); // or AddTool (this, LPSTR_TEXTCALLBACK, cr, IDC_THIS)
make it work for enabled control. I used the other version hoping that I can that way circumvent the disabled button/control. It seems that I need to convince the disabled button to display tooltips instead.

 

by: AndyAinscowPosted on 2004-08-19 at 05:15:43ID: 11840338

Sorry - I hadn't read your requirement completely.  It seems that a disabled control doesn't have a tooltip.
This may not work.  Display a tooltip based on a rectangular area in the dialog the control is on.  (Show/Hide by code - update and pop functions).
I'll have to look it up here, I seem to recall reading about this some time ago

 

by: AndyAinscowPosted on 2004-08-19 at 05:19:41ID: 11840362

BOOL AddTool( CWnd* pWnd, LPCTSTR lpszText = LPSTR_TEXTCALLBACK, LPCRECT lpRectTool = NULL, UINT nIDTool = 0 );

Return Value

Nonzero if successful; otherwise 0.

Parameters

pWnd

Pointer to the window that contains the tool.

nIDText

ID of the string resource that contains the text for the tool.

lpRectTool

Pointer to aRECT structure containing coordinates of the tool’s bounding rectangle. The coordinates are relative to the upper-left corner of the client area of the window identified by pWnd.



this seems to imply using the dialog itself and supplying a rect ought to work

 

by: AndyAinscowPosted on 2004-08-19 at 05:26:50ID: 11840435

instead of
m_tooltip.Create(this, TTS_NOPREFIX);

try
m_tooltip.Create(this, TTS_NOPREFIX | TTS_ALLWAYSTIP);

 

by: SteHPosted on 2004-08-19 at 05:33:04ID: 11840479

Now I tried using:
          m_tooltip.Create(this, TTS_ALWAYSTIP);
          m_tooltip.SetDelayTime(TTDT_AUTOPOP, 10000);     //display for 10 seconds (stop flashing)
and if I activate the tooltip with another not disabled control I can see the message flashing. Sometimes for a time long enough to read the text because I know what its content is. But not really nice.

At least now I know that the TTN_NEEDTEXT handler is called.
Problems I was facing is that for static controls only the way you described in the last posting works and for controls like buttons it doesn't seem to work. Is this just me? Or is it a feature of MFC.

New test with TTS_ALWAYSTIP in call and two buttons added like
        CRect cr;
        c_cbMeasureChip.GetWindowRect (cr);
        ScreenToClient (cr);
        ftooltip.AddTool (this, LPSTR_TEXTCALLBACK, cr, IDC_BT_MEASURE_CHIP);
        ftooltip.AddTool (GetDlgItem(IDC_BT_TEST_CHIP), LPSTR_TEXTCALLBACK);

For either button I can see the tooltip flash for less than a second and disappear right after, sometimes reappearing again.

http://www.codeguru.com/Cpp/controls/controls/tooltipcontrols/article.php/c2277/
describes how to enable tooltips for disabled controls changing the HWND from the dlg ones to the controls. Perhaps I need to implement this. In the TTN_NEEDTEXT handler the HWND is that of the control.


 

by: AndyAinscowPosted on 2004-08-19 at 05:40:51ID: 11840539

I've just tried the TTS_ALWAYSTIP on a disabled (text callback) control and despite help says it doesn't display the tip!

You should be able to use the rectangle approach (needs unique number for each rectangular area).  Instead of passing the ID of the control to attatch the tip to you pass a bounding rectangle and an ID number.  If I understand that correctly it isn't checking if it is on a control - it checks if it is in the rectangle.

something like
CRect rect;
GetDlgItem(IDC_X)->GetWindowRect(&rect);
ScreenToClient(&rect);
AddTool(this, LPSTR_TEXTCALLBACK, &rect, 1);
GetDlgItem(IDC_Y)->GetWindowRect(&rect);
ScreenToClient(&rect);
AddTool(this, LPSTR_TEXTCALLBACK, &rect, 2);

 

by: SteHPosted on 2004-08-19 at 06:05:10ID: 11840788

Now I tried changing the adding in OnInitDialog to
        ftooltip.AddTool (this, LPSTR_TEXTCALLBACK, cr, 1);
        ftooltip.AddTool (this, LPSTR_TEXTCALLBACK, cr, 5000);
        ftooltip.AddTool (&c_cbMeasureChip, LPSTR_TEXTCALLBACK, cr, 5000);
no success. TTN_NEEDTEXT handler gets only called sometimes. Why this?

        ftooltip.AddTool (GetDlgItem(IDC_BT_TEST_CHIP), LPSTR_TEXTCALLBACK);
Works better but the tooltip flashes for only a very short time. No one will be able to read this.

 

by: SteHPosted on 2004-08-19 at 06:32:53ID: 11841069

The help is even more inconsistent. For the callback case it states that

lpszText

Pointer to the text for the tool. If this parameter contains the value LPSTR_TEXTCALLBACK, TTN_NEEDTEXT notification messages go to the parent of the window that pWnd points to.

Since I suppply this to pWnd the parent of the dialog should get the TTN_NEEDTEXT message.

How I understand the tooltip now it seems that the (disabled) control over the main dialog will prevent the main dialog handling the tooltip. But what stuns me is that I tried to move the cr(CRect) to be above the control but still

Looking more carefully at your code I discovered that you use address to CRect structures whereas I used the CRect objects. Why doesn't my version fail?

 

by: AndyAinscowPosted on 2004-08-19 at 06:51:16ID: 11841282

ulp?  argle! out of cheese error. Please re-install the universe. grnch. boiiing.

 

by: AndyAinscowPosted on 2004-08-19 at 06:54:17ID: 11841324

I don't have any more time at present.  Maybe this evening I can look at this.


<What happens if you supply a text string, ignore the callback at present - try to simplify the problem>

 

by: AndyAinscowPosted on 2004-08-19 at 13:11:57ID: 11845779

Using the rectangle approach I can get callback text for a disabled control.  
In the callback function the following line needs to be removed
   if (pTTT->uFlags & TTF_IDISHWND)
as it is not using a window as the ID.

Using the TTS_ALWAYSTIP fails on a disabled control both for callback and static tips text.

 

by: SteHPosted on 2004-08-20 at 00:48:25ID: 11849839

The callback is a bit less demanding. This I got for some of the disabled controls but not always! Only having got a text set no tooltip is displayed or for a too short time to be visible.

But I think I discovered a part of the problem which I did not wrote here yet. This dialog is a subdialog of the main one. Sometimes this resulted in the message TTN_NEEDTEXT to be sent to the main dialog which did not handle this message. In there I can see that
HWND ctl = (HWND)pNMHDR->idFrom;
is the handle of the subdialog with the corresponding control.

Since I had problems adding tools of subdialogs to the main dialog I added a tooltip control to each subdialog responsible for its tools. For all enabled controls this works OK. Only for the disabled ones the messages seem to get lost in the hierachy. The TTN_NEEDTEXT doesn't seem to get always posted to the parent window of the first parameter in AddTool. Sometimes they arrive at the window itself and sometime at its parent. Is there any known algorithm to decide which gets the message on what conditions.

 

by: SteHPosted on 2004-08-20 at 01:45:09ID: 11850143

The line
    if (pTTT->uFlags & TTF_IDISHWND)
is needed but in a different context:

    UINT id;
    if (pTTT->uFlags & TTF_IDISHWND)
    {
          id = ::GetDlgCtrlID((HWND)nID;
    }
    else {
          id = nID;
    }

For static controls not the HWND is idFrom but the control ID itself. Hope this gets me closer to my goal.

 

by: AndyAinscowPosted on 2004-08-20 at 02:32:40ID: 11850338

2nd comment - good.
1st comment - I don't understand why it is failing with the alwaystip setting.  Algorithm - that would be in the commoncontrol implementation itself.  Maybe this is another of the rich selection of features available in windows.

 

by: SteHPosted on 2004-08-20 at 02:37:31ID: 11850352

Snippet from
http://www.codeguru.com/Cpp/controls/controls/tooltipcontrols/article.php/c2277

// This function is a patch that overcomes MFC bug of
// tooltips that don't show up on in disabled controls
// if modal dialogs. Call this function in your overidable of
// PreTranslateMessage, before calling the inherited one.

 

by: SteHPosted on 2004-08-20 at 05:28:37ID: 11850907

A solution I found (or better a work around) is putting a static control underneath the buttons.

Inactive buttons let the tooltips display by the hidden static underneath using
        c_cbPlaceChip.GetWindowRect (&cr);
        ScreenToClient (&cr);
        ftooltip.AddTool (this, LPSTR_TEXTCALLBACK, &cr, IDC_STATIC_PLACECHIP);
The last parameter is the value which gets passed to the TTN_NEEDTEXT handler. I can choose anything different from 0 and -1 but using the value of the string resource = control ID is the easiest.

tips for active buttons are still handled via them:
        ftooltip.AddTool (GetDlgItem(IDC_BT_PLACECHIP), IDC_BT_PLACECHIP);

Thx for your help. Since I did part of the work for the solution myself I grade it as B.

 

by: AndyAinscowPosted on 2004-08-20 at 05:34:47ID: 11850926

A solution I found (or better a work around) is putting a static control underneath the buttons.


As long as it works.  It ought to be possible to accomplish exactly this with the rectangle method, you could always pass the hwnd of the real control as the numeric ID.  That would use less handles as you aren't having to have as many controls.  It would also make mods to the dialog easier (resize/move only one control).

 

by: SteHPosted on 2004-08-20 at 05:46:01ID: 11850986

Will try if this is achievable. Perhaps with a ID different from a control?

 

by: AndyAinscowPosted on 2004-08-20 at 05:49:32ID: 11851004

I did it here last night, disabled a control, tested - no tip, got the window rect, convert to client added tip for rect, it worked.

 

by: SteHPosted on 2004-08-20 at 06:44:24ID: 11851259

Do you have more controls on it?

I tried the same approach as well but to no avail. The button if not added as tool is eating the mouse move messages so the rect/static doesn't get its turn. Do you have some code were this is working?

On www.flounder.com there is a validating edit control with a disabled button which explains why it is disabled. But there the dialog seems to handle all tooltip messages since there is only one control.

 

by: AndyAinscowPosted on 2004-08-20 at 07:23:48ID: 11851525

It was a list box on a dialog.  When disabled the rect approach worked, when enabled then having it as a control worked.  (both callback - the code I initially posted was for displaying different tips depending on the line in the list the mouse was on.)

 

by: SteHPosted on 2004-08-23 at 00:34:31ID: 11867862

Ok, so the difference to my approach was that I put a static underneath. Using just the rectangle of the button works OK in my case as well. I just needed to make sure that they are not both wired to the same tool ID (the buttons control ID). But you are right, having to move/resize an additional control on the panel makes it more difficult. A simple string resource for the rectangle is sufficient and more efficient.

So thanks again.

 

by: AndyAinscowPosted on 2004-08-23 at 01:48:16ID: 11868265

Your welcome.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...