Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 640
  • Last Modified:

Floating tooltips in a CFrameWnd

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
Beatachon
Asked:
Beatachon
  • 6
  • 5
1 Solution
 
psdavisCommented:
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
 
psdavisCommented:
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
 
BeatachonAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
BeatachonAuthor Commented:
I just saw in the help that a CToolTipCtrl can provide hints for more than one tool. Okay. I get it now. Thanks.
0
 
psdavisCommented:
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
 
BeatachonAuthor Commented:
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
 
psdavisCommented:
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
 
BeatachonAuthor Commented:
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
 
psdavisCommented:
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
 
BeatachonAuthor Commented:
We've kinda moved this discussion to "ToolTips Don't Work!" Care to join us?
0
 
BeatachonAuthor Commented:
We've kinda moved this discussion to "ToolTips Don't Work!" Let's keep it over there....
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now