Solved

Floating tooltips in a CFrameWnd

Posted on 1998-08-11
11
592 Views
Last Modified: 2013-11-20
I want to put floating tooltips in my app. The catch is that I have a bunch of buttons, but they're not in a toolbar. AND... although my window is derived from CFrameWnd, I did not use class Wizard. So what method should I use to add these hints?
0
Comment
Question by:Beatachon
  • 6
  • 5
11 Comments
 
LVL 7

Expert Comment

by:psdavis
ID: 1320591
Add

CToolTips m_ToolTips;

to your header file, then on your OnInitialUpdate...

m_ToolTips.Create(this);
m_ToolTips.Activate(TRUE);

m_ToolTips.AddTool( &m_ctlWindow, "ToolTip" );

Where m_ctlWindow is a CWnd pointer to your control.

If I'm oversimplifying this, then comment me right back.

Phillip
0
 
LVL 7

Accepted Solution

by:
psdavis earned 50 total points
ID: 1320592
Add

CToolTips m_ToolTips;

to your header file, then on your OnInitialUpdate...

m_ToolTips.Create(this);
m_ToolTips.Activate(TRUE);

m_ToolTips.AddTool( &m_ctlWindow, "ToolTip" );

Where m_ctlWindow is a CWnd pointer to your control.

If I'm oversimplifying this, then comment me right back.

Phillip

0
 

Author Comment

by:Beatachon
ID: 1320593
So you're saying I have to associate a CToolTipCtrl with each button I create?
Will the CToolTipCtrl be automatically deleted or do I have to specifically delete each object. (Meaning I shouldn't use new to create the CToolTipCtrls. Or, at least, I have to keep pointers handy to each one?)
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:Beatachon
ID: 1320594
I just saw in the help that a CToolTipCtrl can provide hints for more than one tool. Okay. I get it now. Thanks.
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1320595
Yes, a single CToolTipCtrl can have more than one tooltip associated with it.  I was in error in my code, it should have been...

CToolTipCtrl m_ToolTips;

Just keep adding more controls with AddTool until they're all done.  Since you are inserting the CToolTipCtrl in your header file, it will be created and deleted with the life of the dialog.  So, no pointers, no new, no delete.

K?

Phillip
0
 

Author Comment

by:Beatachon
ID: 1320596
It's not working. Here's the code:
      _toolTips.Create(this, WS_VISIBLE);
      _toolTips.Activate(TRUE);

      if(_mode == 2 || _mode == 6)
      {
            ForBackButs.top = ForBackButs.bottom + 5;
            ForBackButs.bottom = ForBackButs.bottom + 25;
            ForBackButs.left = ForBackButs.right - 15;
            
            _cForwardButton = new CButton();
            _cForwardButton->Create("->", WS_CHILD|BS_PUSHBUTTON | WS_VISIBLE, ForBackButs, this, ID_FORWARD);

            ForBackButs.right = ForBackButs.left - 5;
            ForBackButs.left = ForBackButs.right - 15;

            _cReverseButton = new CButton();
            _cReverseButton->Create("<-", WS_CHILD|BS_PUSHBUTTON | WS_VISIBLE, ForBackButs, this, ID_REVERSE);
      
            _toolTips.AddTool((CWnd*)_cForwardButton, "Hi, There");
            _toolTips.AddTool((CWnd*)_cReverseButton, "Hi, There");
      }      
See anything wrong?
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1320597
Sorry for the delay, trip to Dallas.

As far as the ToolTips are concerned, they're correct.  Let's delve into the code though...

1) Personal.  Get rid of those _ before every variable.  They're worthless.  What is the _c for?  If this is a class, how about "m_" as the beginning and even better, how about "m_btnForward" and "m_btnBackward"
2) More information.  Is this a dialog or a view?  Where is this code, in the OnCreate, OnInitDialog, constructor?  Are you seeing the buttons exactly how you were expecting?
3) On the AddTool, you don't need the cast of the (CWnd*).  The buttons are derived from CWnd.
4) I've noticed a bug in the tooltips.  Do you have a AfxMessageBox or a regular message box pop up inside of this area.  Sometimes the tooltips will turn off!

Let's try it again and respond back.

Phillip

0
 

Author Comment

by:Beatachon
ID: 1320598
1) As for the _, it's just a convention around here, same as m_, only most of the guys around here don't do MFC. So...
2)It's just a window derived from a CFrameWnd. Neither a view or a dialog.(It actually has a parameter of NULL passed in Create, so the desktop is really it's parent.) This code was in OnCreate, I tried calling PostMessage(WM_SIZE) and ShowWindow(SW_SHOW) before doing the tooptips. It also didn't work.
3)Just habit.
4)Yes, but not before the buttons are created, and only when there's an error.
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1320599
1) The m_ isn't MFC, it's C++.  What's the '_c' stand for?  
2) Do you have a CWinApp?
3) The less casts, the better.  C++ can't do type checking if you cast stuff.  This way if the _cForwardButton gets changed types, the compiler will catch it.
4) Just a hunch.

Phillip
0
 

Author Comment

by:Beatachon
ID: 1320600
We've kinda moved this discussion to "ToolTips Don't Work!" Care to join us?
0
 

Author Comment

by:Beatachon
ID: 1320601
We've kinda moved this discussion to "ToolTips Don't Work!" Let's keep it over there....
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 72
repeatEnd java challenge 42 84
Include multiple hostnames in this command? 3 55
Problem to App source 6 38
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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