Thread: Dialog ToolTips

  1. #1

    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__;

    // CHintTestDlg dialog

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

    void CHintTestDlg:oDataExchange(CDataExchange* pDX)
    DDX_Control(pDX, IDC_EDIT2, m_EditWithToolTip);
    DDX_Control(pDX, IDC_EDIT, m_EditField);

    BEGIN_MESSAGE_MAP(CHintTestDlg, CDialog)
    ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )//HandleNeededText ) ///***************


    // CHintTestDlg message handlers

    BOOL CHintTestDlg::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.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 );


    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;
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2;

    // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);

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

    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

    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, 02:59 PM
  2. Edit controls of a dialog from another dialog...
    By Snake in forum Windows Programming
    Replies: 9
    Last Post: 07-01-2005, 03:18 PM
  3. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 03: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, 03:59 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM
Website Security Test