Click here to Skip to main content
15,885,875 members
Articles / Desktop Programming / MFC

Message Balloons

,
Rate me:
Please Sign up or sign in to vote.
4.84/5 (11 votes)
1 Apr 2012CPOL4 min read 237.7K   7.2K   97  
Message Balloons as opposed to Message Boxes
/*******************************************************************************
File:        BalloonTip.h

Description: This file contains the module for creating a a balloon tip which can
             be shown anywhere on a parent window
             

Created: Nov 1, 2001
Author:  Prateek Kaul
e-mail:  kaulpr@yahoo.com

Compiler with version number : Visual C++ 6.0


Copyright (c) 2001, Prateek Kaul
All rights Reserved.

The copyright to the computer program(s) herein is the property of Prateek Kaul
The program(s) may be used and/or copied only with the written permission of 
Prateek Kaul or in accordance with the terms and conditions stipulated
in the agreement/contract under which the program(s) have been supplied.
********************************************************************************/

#ifndef _BALLOONTIP_H
#define _BALLOONTIP_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

const int ID_TIMER = 100;

/*---------------------------------------------------------------------------
 class CBalloonTip

 Created: Nov 1, 2001
 Author:  Prateek Kaul
 e-mail:  kaulpr@yahoo.com

 Abstract : For creating a balloon tip

 Revisions :none.
----------------------------------------------------------------------------*/

class CBalloonTip : public CFrameWnd
{
    DECLARE_MESSAGE_MAP()

public:
	
// Implementation

    // Creates a new CBalloonTip Object
    static CBalloonTip* Show(
               CPoint pt,         // Point where the balloon tip will be  
               CSize size,        // Size of the balloon
               CString strMessage,// Messsage to be shown
               LOGFONT lf, // A LOGFONT structure from which the message font will created  
               UINT nSecs, // Seconds for which the balloon will be shown
               BOOL bBalloonUp    // Is balloon show up or upside down?
            );
    
    void Hide(); // Makes the window invisible, does not destroy, and release resources.
                 // The window will auto destruct after the stipulated nSecs sent in Show()

protected:

// Implementation

  	CBalloonTip(CString strMessage, LOGFONT lf, BOOL bBalloonUp);
    ~CBalloonTip();
    BOOL Create(CRect rect);       // Create the Windows(R) window, HANDLE etc ...
    void MakeVisisble(UINT nSecs); // Show the balloon for nSecs Seconds

// Overrides and messages
	//{{AFX_MSG(CBalloonTip)
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnPaint();
	//}}AFX_MSG
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);

// Attributes
    BOOL    m_bBalloonUp;   // Is balloon up or upside down
	CRect   m_rectText;     // Rectabgle where the text will be in the balloon
    CRect   m_rectWindow;   // Rectangle in which the balloon will be displayed in screen coordinates
    CString m_strMessage;   // Message to be displayed in the balloon
	CFont   m_fontBalloonText; // Font of the message
	CRgn    m_rgnTip;          // The region of the tip
	CRgn    m_rgnRoundRect;   // The region of the round rectangle  
    CWnd    m_wndInvisibleParent; // Invisible parent of this window, this avoids the balloon's
                                  // appreance in the Taskbar
};

#endif // _BALLOONTIP_H

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Written By
Web Developer
Canada Canada
I have been programming for the past 5 years or so. I started out with C for about 1 year, then took a break and ended up doing Access and VB for a short while. It was then followed by more C, a bit of Java and database development in Oracle and SQL Server and web development in ASP, until I arrived in the C++ and MS windows world. I have been working with MFC for the past 2-3 years and have some COM and Win32 API experience as well. I have recently begun the journey of .NET as well, trying to keep up with the latest hype.

Comments and Discussions