[Webinar] Streamline your web hosting managementRegister Today

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

Resized CDialog and ToolTips

I'm having a problem with Tooltips operations in my CDialog derived window.  My dialog is possibly resized with a "show me more" type button.  When it's clicked, the window is made larger and more controls are visible and enabled.  When this happens, however, the tooltips no longer work.  I never get the callback triggered.  I've tried disabling and re-enabling the tooltips but nothing seems to help.
0
jhance
Asked:
jhance
  • 3
  • 2
1 Solution
 
RONSLOWCommented:
What method do you use for your tooltips (there are several ways to do it).  I use the MFC provided tooltips for the dialog, rather than creating my own tooltip control .. one just has to respond to the approriate messages.

I can let you have the code I use in my dialog classes.  The code is not specific to a given dialog .. in fact, I have a CDialog-derived class that adds tooltip support and then derive all my dialog classes from that.

0
 
jhanceAuthor Commented:
RONSLOW,

Here a simplified version of what I'm working with.  I don't get any calls to OnToolTipNotify.  I'm stumped...


// tooltipDlg.cpp : implementation file
//

#include "stdafx.h"
#include "tooltip.h"
#include "tooltipDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTooltipDlg dialog

CTooltipDlg::CTooltipDlg(CWnd* pParent /*=NULL*/)
      : CDialog(CTooltipDlg::IDD, pParent)
{
      //{{AFX_DATA_INIT(CTooltipDlg)
            // NOTE: the ClassWizard will add member initialization here
      //}}AFX_DATA_INIT
      // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
      m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTooltipDlg::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CTooltipDlg)
            // NOTE: the ClassWizard will add DDX and DDV calls here
      //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTooltipDlg, CDialog)
      //{{AFX_MSG_MAP(CTooltipDlg)
      ON_WM_PAINT()
      ON_WM_QUERYDRAGICON()
      ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnToolTipNotify)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTooltipDlg message handlers

BOOL CTooltipDlg::OnInitDialog()
{
      CDialog::OnInitDialog();

      // Set the icon for this dialog.  The framework does this automatically
      //  when the application's main window is not a dialog
      SetIcon(m_hIcon, TRUE);                  // Set big icon
      SetIcon(m_hIcon, FALSE);            // Set small icon
      
      // TODO: Add extra initialization here
      CRect crsz, tmpSz;
      GetWindowRect(crsz);
      tmpSz.SetRect(crsz.left, crsz.top, crsz.right+100, crsz.bottom+100);
      MoveWindow(tmpSz, TRUE);

      EnableToolTips(TRUE);
      
      return TRUE;  // return TRUE  unless you set the focus to a control
}

BOOL CTooltipDlg::OnToolTipNotify(UINT id, NMHDR * pNMHDR, LRESULT * pResult)
{
      static char msg[512];

      TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
    UINT nID =pNMHDR->idFrom;
    if (pTTT->uFlags & TTF_IDISHWND)
    {
        // idFrom is actually the HWND of the tool
        nID = ::GetDlgCtrlID((HWND)nID);
        if(nID)
        {
                  sprintf(msg, "%d", nID);
            pTTT->lpszText = msg;
            pTTT->hinst = AfxGetResourceHandle();
            return(TRUE);
        }
    }
    return(FALSE);
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTooltipDlg::OnPaint()
{
      if (IsIconic())
      {
            CPaintDC dc(this); // device context for painting

            SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

            // Center icon in client rectangle
            int cxIcon = GetSystemMetrics(SM_CXICON);
            int cyIcon = GetSystemMetrics(SM_CYICON);
            CRect rect;
            GetClientRect(&rect);
            int x = (rect.Width() - cxIcon + 1) / 2;
            int y = (rect.Height() - cyIcon + 1) / 2;

            // Draw the icon
            dc.DrawIcon(x, y, m_hIcon);
      }
      else
      {
            CDialog::OnPaint();
      }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTooltipDlg::OnQueryDragIcon()
{
      return (HCURSOR) m_hIcon;
}

0
 
RONSLOWCommented:
This could be due to a know bug in VC5 for which there is a known easy workaround.

Add the following virtual function override...

int CTooltipDlg::OnToolHitTest(CPoint point, TOOLINFO* pTI) const {
    UINT cbSizeWas;
    if (pTI) {
        cbSizeWas = pTI->cbSize;
        pTI->cbSize = sizeof(TOOLINFO);
    }
    int ret = CDialog::OnToolHitTest(point,pTI);
    if (pTI) {
        pTI->cbSize = cbSizeWas;
    }
    return ret;
}

This is explained in MS KB aritcla Q172276 "BUG: CToolTipCtrl Not Displaying Text After VS SP1, SP2 Install"

Also change your message map to

ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT,0,0xFFFF,OnToolTipNotify)

that way ALL control ID's will generate the message.

0
 
jhanceAuthor Commented:
I think that this may be part of the issue.  I had tooltips working in the un-resized dialog at one time but recently couldn't get any at all.  I have installed SP2 and this would explain my recent frustration at not being able to get any tool tips at all.  I'll make the changes here and see if I can duplicate my original problem where the tool tips would work until the dialog was resized.
0
 
jhanceAuthor Commented:
That was the problem.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now