Solved

Resized CDialog and ToolTips

Posted on 1998-05-16
5
491 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sameEnds challenge 3 187
if loop in java 3 161
Modbus - whats the maximum I can store in one register? 4 81
Execute multiple curl cmds with sleep and send output to file 10 114
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

735 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