Solved

Floating tooltips in a CFrameWnd

Posted on 1998-08-11
11
585 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need Help INsttalling wget on Mavericks OS X 3 90
countEvens challenge 2 78
lucky13 challenge 11 124
ShiftLeft challenge 21 76
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 …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

867 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

13 Experts available now in Live!

Get 1:1 Help Now