Click here to Skip to main content
15,894,646 members
Articles / Desktop Programming / MFC

Text Only Status Bar

Rate me:
Please Sign up or sign in to vote.
3.40/5 (4 votes)
3 Jun 2000 119.1K   3.9K   22  
An easy to use and implement Text Only Status Bar with Tool tip text extracted from the status bar panes.
// TextualStatusBar.cpp : implementation file
//

#include "stdafx.h"
#include "TextualStatusBar.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTextualStatusBar

CTextualStatusBar::CTextualStatusBar()
{
}

CTextualStatusBar::~CTextualStatusBar()
{
}


BEGIN_MESSAGE_MAP(CTextualStatusBar, CStatusBar)
	//{{AFX_MSG_MAP(CTextualStatusBar)
	ON_WM_CREATE()
	ON_WM_DESTROY()
	ON_WM_NCHITTEST()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CTextualStatusBar message handlers

int CTextualStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CStatusBar::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolTip.Create(this, TTS_ALWAYSTIP) ||
		!m_wndToolTip.AddTool(this, "Tool tip for status bar")
		)
		AfxMessageBox("Unable to add tool tip for status bar");


	return 0;
}

void CTextualStatusBar::OnDestroy() 
{
	m_wndToolTip.DestroyWindow();
	CStatusBar::OnDestroy();
	
}

BOOL CTextualStatusBar::PreTranslateMessage(MSG* pMsg) 
{
	m_wndToolTip.RelayEvent(pMsg);
	return CStatusBar::PreTranslateMessage(pMsg);
}

UINT CTextualStatusBar::OnNcHitTest(CPoint point) 
{
	CStatusBarCtrl& statusBar = GetStatusBarCtrl();

    int i = -1;
    CRect rectPane;
    CPoint ptTmp(point);
    ScreenToClient(&ptTmp);
    int nCount = GetCount();

    while (i++ < nCount)
    {
        statusBar.GetRect(i, rectPane);
        if (rectPane.PtInRect(ptTmp) )
        {
            CString strTip;
            m_wndToolTip.GetText(strTip, this);
            LPCTSTR lpPaneText = GetPaneText(i);
            if (strTip != lpPaneText)
            {
                m_wndToolTip.UpdateTipText(lpPaneText, this);
            }
            break;
        }
    }
    
	return CStatusBar::OnNcHitTest(point);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
Software Developer (Senior) Comcast Cable
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions