Click here to Skip to main content
15,884,836 members
Articles / Desktop Programming / MFC

Tool tip on window

Rate me:
Please Sign up or sign in to vote.
4.60/5 (11 votes)
16 Oct 20011 min read 104K   3.4K   34  
Tooltips for window according to specified rectangular areas of that window
// ToolTipView.cpp : implementation of the CToolTipView class
//

#include "stdafx.h"
#include "ToolTip.h"

#include "ToolTipDoc.h"
#include "ToolTipView.h"



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

/////////////////////////////////////////////////////////////////////////////
// CToolTipView

IMPLEMENT_DYNCREATE(CToolTipView, CView)

BEGIN_MESSAGE_MAP(CToolTipView, CView)
	//{{AFX_MSG_MAP(CToolTipView)
	ON_WM_CREATE()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONDBLCLK()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CToolTipView construction/destruction

CToolTipView::CToolTipView()
{
	// TODO: add construction code here
}

CToolTipView::~CToolTipView()
{
}

BOOL CToolTipView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CToolTipView drawing

void CToolTipView::OnDraw(CDC* pDC)
{
	CToolTipDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CToolTipView printing

BOOL CToolTipView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CToolTipView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CToolTipView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CToolTipView diagnostics

#ifdef _DEBUG
void CToolTipView::AssertValid() const
{
	CView::AssertValid();
}

void CToolTipView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CToolTipDoc* CToolTipView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CToolTipDoc)));
	return (CToolTipDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CToolTipView message handlers

int CToolTipView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;

    // Sets the Delay and create tip window
    m_MyTip.SetDelay(1000);
    m_MyTip.CreateTipWnd(this);
    return 0;
}

void CToolTipView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_MyTip.ShowTip(point);
	CView::OnMouseMove(nFlags, point);
}




void CToolTipView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
    CTipInfo info(CRect(0, 0, 100, 100), "Top Left corner of Window");
    m_MyTip.AddTip(info);	

    // specifies bottom roght corner of window
    CRect t_rect;
    GetClientRect(&t_rect);
    t_rect.top = t_rect.bottom - 100 ;
    t_rect.left = t_rect.right - 100 ;
    info.SetReagion(t_rect);
    info.SetText("Bottom Right corner of Window");
    m_MyTip.AddTip(info);

    // specifies middile area of window
    t_rect.top  = t_rect.bottom / 2 - 50;
    t_rect.left = t_rect.right / 2 - 50;
    t_rect.bottom = t_rect.top + 100;
    t_rect.right = t_rect.left + 100;
    info.SetReagion(t_rect);
    info.SetText("Middile area of window");
    m_MyTip.AddTip(info);
    
	CView::OnLButtonDblClk(nFlags, 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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
India India
I am a Software Professional and Currently working in C-DAC (Centre For Development of Advanced Computing). This is a Scientific Socity under ministry of india of Information Technology.
I have completed My B.C.A. Degree with 77% marks, I am certified by microsofr as Microsoft Certified Professional in Visual Basic 6.0(70-176). Currently working on Visual C++ 6.0 and Using MFC support in my Applicaitons.
For Future Studying 3D graphics desinging like OpenGL and DirectX.

Comments and Discussions