Solved

Resized CDialog and ToolTips

Posted on 1998-05-16
5
482 Views
Last Modified: 2013-11-20
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
Comment
Question by:jhance
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1311609
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
 
LVL 32

Author Comment

by:jhance
ID: 1311610
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
 
LVL 10

Accepted Solution

by:
RONSLOW earned 100 total points
ID: 1311611
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
 
LVL 32

Author Comment

by:jhance
ID: 1311612
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
 
LVL 32

Author Comment

by:jhance
ID: 1311613
That was the problem.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

11 Experts available now in Live!

Get 1:1 Help Now