2

I want my CMFCButton to show tooltip when mouse over. It doesn't work if I use SetToolTip() method in OnInitDialog

CMFCButton* bt = ((CMFCButton*)GetDlgItem(IDC_MFCBUTTON1)); 
bt->SetTooltip(_T("tooltip")); 

BUT it does work if I put this code in message handle function like another button's click handle. What I want is that the CMFCButton could show tooltip when the dialog is created, where should I put these code?

======================== By the way, The tooltip text I set in the Property view does not work for most time.

1

2 Answers 2

1

I just derived a class

class CMyButton : public CMFCButton
{
public:
    void SetDelayFullTextTooltipSet(bool DelayFullTextTooltipSet)
    {
        m_bDelayFullTextTooltipSet = DelayFullTextTooltipSet;
    }
};

Instead of a CMFCButton variable on the Dialog class I use the button, I now have a CMyButton.

And in the OnInitDialog, after the SetTooltip call, I do

button.SetDelayFullTextTooltipSet(FALSE);
3
  • Can't we see a complete class here please? Feb 23, 2017 at 17:49
  • 1
    This is the correct answer. Should be marked as such. Feb 23, 2017 at 18:11
  • 1
    @AndrewTruckle: It is the complete class; has no more than what is displayed here.
    – sergiol
    Feb 23, 2017 at 19:42
0

Have you called the base class' OnInitDialog()? The main point is that the control needs to be created before you call SetToolTip() on it. Step into OnInitDialog() with the debugger and see if m_hWnd of the control has a value at the moment you call SetToolTip().

1
  • Yes, I called the base class "OnInitDialog()" and the mfcButton's member m_pToolTip is valid. The code bt->GetTooltipCtrl().GetText(str,bt) can get the right tooltip text I set in the property card, but it just cannot show unless I call setToolTip(str) after the dialog been created.
    – Keosu
    Mar 12, 2013 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.