Solved

Floating tooltips in a CFrameWnd

Posted on 1998-08-11
11
580 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

760 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

18 Experts available now in Live!

Get 1:1 Help Now