Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Tech Tips


May 2002/Tech Tips

Listing 4: tipdemo.cpp
Demo program for generic tool tips

/*------------------------------------------------------------------
TipDemo.cpp: Implementation of TipDemo.EXE 
Author:      Zuoliu Ding
------------------------------------------------------------------*/
#include <afxwin.h>
#include <afxcmn.h>
#include "TipWnd.h"
#include "TipHlpr.h"
#include "tipDemo.h"

void CTipDemoDlg ::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CTipDemoDlg )
    DDX_Control(pDX, IDC_IPADDRESS, m_ipAdr);
    DDX_Control(pDX, IDC_CUSTOM, m_custom);
    DDX_Control(pDX, IDC_PROGRESS, m_progress);
    DDX_Control(pDX, IDC_SCROLLBAR, m_scroll);
    DDX_Control(pDX, IDC_SPIN, m_spin);
    DDX_Control(pDX, IDC_SLIDER, m_slider);
    DDX_Check(pDX, IDC_CHECK, m_bCheck);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTipDemoDlg , CDialog)
    //{{AFX_MSG_MAP(CTipDemoDlg )
    ON_WM_MOUSEMOVE()
    ON_BN_CLICKED(IDC_CHECK, OnCheck)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

    m_tip.Create(this, 1);
    m_tip.SetTipBkClr(RGB(255, 255, 0));  // Bright yellow

    UINT uIDs[8] ={IDOK, IDC_RADIO1, IDC_RADIO2, IDC_COMBO,
                   IDC_LIST, IDC_EDIT, IDC_HOTKEY, IDC_CHECK};

    for (int i=0; i<8; i++)
        m_tipHelpers[i].SubclassDlgItem(uIDs[i], this);

    CString str;
    for (i=0; i<10; i++)
    {
       str.Format(_T("List String %d"), i);
       ((CListBox*)&m_tipHelpers[4])->AddString(str);
    }

    m_tipHelpers[5].SetWindowText("An Edit Box");
   ((CComboBox*)GetDlgItem(IDC_COMBO))->SetCurSel(1);
   ((CHotKeyCtrl*)GetDlgItem(IDC_HOTKEY))->
                             SetHotKey('A', HOTKEYF_ALT);

    ((CProgressCtrl*)&m_progress)->SetPos(30);
    ((CSliderCtrl*)&m_slider)->SetRange(1, 10);
    ((CIPAddressCtrl*)&m_ipAdr)->SetAddress(2878873543);

    OnCheck();
    return TRUE;  
}

void CTipDemoDlg ::OnMouseMove(UINT nFlags, CPoint point) 
{
    // No member variable required
    SET_TIP_TEXT(m_tip, IDC_STATICUSAGE, "The Static Text")
    SET_TIP_TEXT(m_tip, IDC_STATICICON, "The Picture: Icon")
    SET_TIP_TEXT(m_tip, IDC_STATICGROUP, "The Group Box")
   
    // Attached to the CTipHelper array m_tipHelpers
    SET_TIP_TEXT(m_tip, IDOK, "The Exit Button")
    SET_TIP_TEXT(m_tip, IDC_RADIO1, "The Radio Button1")
    SET_TIP_TEXT(m_tip, IDC_RADIO2, "The Radio Button2")
    SET_TIP_TEXT(m_tip, IDC_COMBO, "The Combo Box")
    SET_TIP_TEXT(m_tip, IDC_EDIT, "The Edit Box")
    SET_TIP_TEXT(m_tip, IDC_HOTKEY, "The Hotkey Editor")
    SET_TIP_TEXT(m_tip, IDC_CHECK, "The Check Box")
    SET_TIP_TEXT(m_tip, IDC_LIST, "The List Box is " +
                    CString(m_bCheck? "Enabled": "Disabled"))

    // Attached to the DDX_ variables of CTipHelper
    SET_TIP_TEXT(m_tip, IDC_SLIDER, "The Slider Bar")
    SET_TIP_TEXT(m_tip, IDC_PROGRESS, "The Progress Bar")
    SET_TIP_TEXT(m_tip, IDC_IPADDRESS, "The IP Address Editor")
    SET_TIP_TEXT(m_tip, IDC_CUSTOM, "The Custom Control")
    SET_TIP_TEXT(m_tip, IDC_SPIN, "The Spin Control")
    SET_TIP_TEXT(m_tip, IDC_SCROLLBAR, "The Scoll Bar")

    END_TIP_TEXT(m_tip)

    CDialog::OnMouseMove(nFlags, point);
}

void CTipDemoDlg ::OnCheck() 
{
    UpdateData();
    GetDlgItem(IDC_LIST)->EnableWindow(m_bCheck);
}

// End of File


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.