Solved

Floating tooltips in a CFrameWnd

Posted on 1998-08-11
11
600 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 163
sum67 challenge 35 108
Annoying "thing" blocks my view 4 115
Problem to App source 6 71
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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