Dialog ToolTips

This is a discussion on Dialog ToolTips within the Windows Programming forums, part of the Platform Specific Boards category; Anyone know how to get tooltips to appear when using a dialog?? Here is the code i have so far, ...

  1. #1
    Unregistered
    Guest

    Angry Dialog ToolTips

    Anyone know how to get tooltips to appear when using a dialog?? Here is the code i have so far, but the I can't see the tool tip when it runs. Thanks...

    // HintTestDlg.cpp : implementation file
    //

    #include <string.h>
    #include "stdafx.h"
    #include "HintTest.h"
    #include "HintTestDlg.h"
    #include "CNCEdit.h"

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

    /////////////////////////////////////////////////////////////////////////////
    // CHintTestDlg dialog

    CHintTestDlg::CHintTestDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CHintTestDlg::IDD, pParent),alreadySet(false)
    {
    //{{AFX_DATA_INIT(CHintTestDlg)
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    //EnableToolTips(TRUE);
    }

    void CHintTestDlg:oDataExchange(CDataExchange* pDX)
    {
    CDialog:oDataExchange(pDX);
    //{{AFX_DATA_MAP(CHintTestDlg)
    DDX_Control(pDX, IDC_EDIT2, m_EditWithToolTip);
    DDX_Control(pDX, IDC_EDIT, m_EditField);
    //}}AFX_DATA_MAP
    }

    BEGIN_MESSAGE_MAP(CHintTestDlg, CDialog)
    //{{AFX_MSG_MAP(CHintTestDlg)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    //}}AFX_MSG_MAP
    ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )//HandleNeededText ) ///***************

    END_MESSAGE_MAP()

    /////////////////////////////////////////////////////////////////////////////
    // CHintTestDlg message handlers

    BOOL CHintTestDlg::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
    //m_EditField.EnableToolTips(TRUE);
    m_EditField.SetWindowText( "This is the edit" );
    m_EditWithToolTip.SetWindowText( "This is supposed to have a tool tip with it so you can read this whole line" );
    m_EditWithToolTip.EnableToolTips( TRUE );

    EnableToolTips(TRUE);

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

    // 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 CHintTestDlg::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 CHintTestDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    //m_EditField.
    }

    BOOL CHintTestDlg::OnToolTipNotify/*HandleNeededText*/( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
    {
    TOOLTIPTEXT *pTTT = reinterpret_cast<TOOLTIPTEXT *>(pNMHDR);
    UINT nID = pNMHDR->idFrom;
    if( pTTT->uFlags & TTF_IDISHWND )
    {
    nID = ::GetDlgCtrlID( reinterpret_cast<HWND>(nID) );
    if( nID == IDC_EDIT2 )
    {
    CString cstEditText;
    m_EditWithToolTip.GetWindowText( cstEditText );
    strcpy( pTTT->szText, cstEditText.GetBuffer(cstEditText.GetLength( )) );
    }
    }

    return TRUE;
    }

    int CHintTestDlg::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
    {
    return 1;
    }

  2. #2
    Unregistered
    Guest

    Thumbs up

    I figured it out... I had to remove the OnToolHitTest function from the code. OnToolHitTest is a method in the CDialog class and by having it in my code it was being called insted of my OnToolTipNotify function.

    Thanks all...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 01:59 PM
  2. Edit controls of a dialog from another dialog...
    By Snake in forum Windows Programming
    Replies: 9
    Last Post: 07-01-2005, 02:18 PM
  3. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 02:42 PM
  4. Getting the position of a dialog without parent on the screen
    By stormbringer in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2003, 02:59 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21