Message Balloons



Click here for larger image

Environment: VC++ 6.0, MFC, Windows 2000/XP/9x/ME/NT

Introduction

There are times when one would like to display messages in an non-obtrusive way. Message Balloons are one of the new ways. Message Balloons are taking precedence over message boxes for small display messages as they even prevent the user from clicking an OK and still get the message across. These kind of Message Balloons are becoming a part of standard user interface with MSN explorer and Windows XP. Still no library has been provided for making these balloons. Hence this attempt.

How to use the class provided ?

Include the following two files in your project:
  • BalloonTip.h
  • BalloonTip.cpp
There are two interfaces to create and show the message balloons.
  • CBalloonTip::Show()
  • CBalloonTip::Hide()


CBalloonTip::Show()-: This is a pseudo constructor because we want to force heap creation of the balloon, so that it remains in the memory even after it has been called. It will be automatically destroyed when a it receives a WM_TIMER message which is set in the CBalloon::MakeVisible(). The constructor for CBalloonTip is protected, hence this helps in forcing heap creation.The following code shows how to create a Message Balloon and show it.
LOGFONT lf;
::ZeroMemory (&lf, sizeof (lf));
lf.lfHeight = 16;
lf.lfWeight = FW_BOLD;
lf.lfUnderline = FALSE;
::strcpy (lf.lfFaceName, _T("Arial"));

CBalloonTip::Show(
    CPoint(200, 200),  // Point on the screen where 
                       // the tip will be shown
    CSize(250, 100),   // Size of the total rectangle 
                       // encompassing the balloon 
    _T("Please enter a password !!"), // Message to be shown
                                      // in the balloon
    lf,     // LOGFONT structure for 
            // font properties 
    5,      // Time in seconds to show the balloon
    FALSE   // TRUE  == Balloon is up(Balloon Tip is down) 
            // FALSE ==  Balloon is down(Balloon Tip is up)
);


CBalloonTip::Hide()-: This is for destroying the Balloon for any particular condition that may arise before it is automatically destroyed in the CBalloonTip::OnTimer(). Either way if CBalloonTip::Hide() is not called the Balloon is destroyed in CBalloonTip::OnTimer(). So the caller(user of this class) does not need to worry about the memory cleanup.

Class Design Details

CBalloonTip is derived from CFrameWnd. The balloon is created from the combination of two regions, one is a polygon region to show the the Balloon Tip and the other is a Round Rectangle region. This is done in the CBalloonTip::OnCreate().
int CBalloonTip::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    //..........Some code
    //...................

    CRgn rgnComb;
    
    rgnComb.CreateRectRgn( t_Rect.left, 
                           t_Rect.top,
                           t_Rect.right,
                           t_Rect.bottom);

    int iRetComb = rgnComb.CombineRgn(&m_rgnTip,
                                      &m_rgnRoundRect,
                                      RGN_OR);
}
The m_rgnTip and m_rgnRoundRect are created with different calculations depending upon whether the balloon tip is down or up. The visible window or balloon region is finally set using SetWindowRgn(rgnComb.operator HRGN(), TRUE) in the CBalloonTip::OnCreate().
The Balloon window is not shown up in the taskbar by making the Balloon a child of an invisible parent in CBalloonTip::PreCreateWindow() This parent window is a member variable (CBalloon::m_wndInvisibleParent) of the class itself and is destroyed automatically when the Balloon is destroyed. So the non-appearance of the Balloon window in the task bar is taken care of automatically.

BOOL CBalloonTip::PreCreateWindow(CREATESTRUCT& cs)
{
    //...............Some code
    //........................

    if (!::IsWindow(m_wndInvisibleParent.m_hWnd))
    {
        // Try creating the invisible parent window
        PCSTR pstrOwnerClass = ::AfxRegisterWndClass(0);
       
        BOOL bError = m_wndInvisibleParent.CreateEx(
                          0,
                          pstrOwnerClass, 
                          _T(""), 
                          WS_POPUP,
                          0,
                          0,
                          0,
                          0,
                          NULL,
                          0
                      );
    }
}

Window Creation

The balloon is created with respect from the point where it is supposed to be displayed. So the calculation of balloon rectangle has to be recalculated w.r.t the point at which it is to be shown. Different calculations have to be done if the Balloon tip is down or up. This is done in CBalloontip::Show() as shown below,
CBalloonTip* CBalloonTip::Show( CPoint pt,
                                CSize size,
                                CString strMessage,
                                LOGFONT lf,
                                UINT nSecs,
                                BOOL bBalloonUp)
{
    //.........Some code
    //..................

    if (bBalloonUp)
    {
        nRectLeft   = pt.x - (size.cx * 0.65);
        nRectRight  = pt.x + (size.cx * 0.35);
        nRectTop    = pt.y - size.cy;
        nRectBottom = pt.y;
    }
    else
    {
        nRectLeft   = pt.x - (size.cx * 0.35);
        nRectRight  = pt.x + (size.cx * 0.65);
        nRectTop    = pt.y;
        nRectBottom = pt.y + (size.cy);
    }
}
The actual Windows. window balloon is created in CBalloonTip::Show() using
pBalloonTip->Create( CRect( nRectLeft,
                            nRectTop,
                            nRectRight,
                            nRectBottom));
The CRect passed in the above function will represent the actual position of the balloon in screen co-ordinates. The timer for the Balloon destruction is set in the next line in CBalloonTip::Show()
pBalloonTip->MakeVisisble(nSecs);
  • Only one instance of the Balloon is allowed to created at a time using the static variable CBalloonTip::nBalloonInstances
  • Overview of the demo project

    Sample Image

  • Just click the "OK" button without entering anything in the the edit boxes.
  • Compatibility

    Tested using VC++ 6 with MFC on Windows 2000. Should work fine on other Windows OSs(95/98/NT/ME/XP) also, as it uses no OS specific code.

    Conclusion

    I hope that this contribution will make some improvement in the user interface code of your forthcoming programs!!! Any suggestions, improvements or bugs detected are welcome. Enjoy.....

    Downloads

    Download demo project - 15 Kb
    Download source - 6 Kb


    Comments

    • Ce sont les plus chaudes lisseur ghd au printemps 2013

      Posted by kkfbgh127 on 07/16/2013 04:14pm

      Processus de changements de couleur de la texture de surface un peu de cheveux colorés et décolorés. Par conséquent, il est particulièrement important d'éviter plus de stress à la surface de l'ajout håret.I coloré, l'une des plaques soutenus par des ressorts et donner si vous utilisez trop de force au cours de plaques mobiles brevetés stylingen.De fournir une protection supplémentaire et est trois fois plus lisse que disques classiques et de réduire considérablement la friction. En outre, l'une des plaques pris en charge par un ressort et laisser la place si vous utilisez trop de force durant le coiffage. [url=http://bbeatsinorge.cabanova.com/]ghd lisseur pas cher[/url] Lisseur GHD est un outil de style professionnel avec revêtement avancé de perles en céramique pour une distribution uniforme de la chaleur et de douceur glissent à revêtement céramique normal. Il ne sera pas coincé dans les cheveux et le rendre brillant et droite à zéro tid.Høytpresterende redresseur avec cordon de revêtement en céramique et chauffage rapide à 10 sekunder.Den fonctionnalités réglage automatique de la tension pour le bon fonctionnement dans le monde, il s'éteint automatiquement après 60 minutes et il a un fil à charnière de 3 mètres. Une pochette de rangement résistant luxueux et chauffage inclus. [url=http://ghdpascherferfr.blinkweb.com/]ghd lisseur prix[/url] Chaque ghd pink aura un code de suivi unique qui peut être vérifié en suivant les instructions de personnes box.any ne comprennent pas que la façon dont vous coupez, le style et portez vos cheveux peut avoir une énorme différence dans l'apparence générale. Vous vous demandez pourquoi actrices hollywoodiennes poussant 40 ans, mais encore de maintenir cette apparence de jeunesse magnifique. Une grande partie du secret est les cheveux et le maquillage, oui, je sais que certains choisissent l'approche chirurgicale, mais je ne vais pas parler du niveau d'embellissement.

      Reply
    • New one

      Posted by snareenactina on 12/01/2012 11:31pm

      laguardia Globalization has continually increased international competition in sports. Yahoo! Small Business It’s true that many workers are likely to initially save at least part of the extra money in their paycheck that will appear as a result of a payroll tax cut. That will ultimately help solve the problem that has been the greatest drag on national growth: The enormous debt that burdens middle class households. chystala So if I were the MPAA, how would I handle this? jianshefei Our testers put 100s of products through their paces at our National Testing and Research Center. Learn more about how we test for: warwickshire Processing tomatoes But the enormous recent finds have led to demands for greater equality. The so-called nonproducing states have been making the argument in Congress that mineral rights belong to Brazilians as a whole and the proceeds should be divided accordingly. teske Companies all over the UK face similar challenges in the pursuit of growth, writes Brian Groom shortcomings I dont think this is so and what Alex's argument lacks is any analysis of power in society. Our decisions about how and what to change about our lives is not wholly our own. To present it as such is wildly naive and ahistorical. stewing Orders are not shipped or delivered on weekends or holidays.

      Reply
    • Goal

      Posted by snareenactina on 11/12/2012 06:12am

      gvbpublic Country reports for all countries of the world can be found via the following link: Venezuela’s President Hugo Chavez oversaw the inauguration of a new petrochemical complex and a thermoelectric power plant yesterday, while responding to opposition criticisms that the broadcast of such events constitutes “campaigning.” Hi Matt! yellowthroat As the major epicenter of world trade, the United States enjoys leverage that many other nations do not. For one, since it is the world's leading consumer, it is the number one customer of companies all around the world. Many businesses compete for a share of the United States market. In addition, the United States occasionally uses its economic leverage to impose economic sanctions in different regions of the world. USA is the top export market for almost 60 trading nations worldwide. broods Background - Shortcut: b phonology Sure, but don't leave the bankers out of the equation. Ultimately the government does what the bankers want. projectcbm Vietnam ranks 109 out of 177 countries on the Human Development Index. chirurgus Follow us: birdbus BRAZIL has a lot to be proud of. A decade of faster growth and progressive social policies has brought a prosperity that is ever more widely shared. The unemployment rate for April, at 6.4%, is the lowest on record. Credit is booming, particularly to the swelling numbers who have moved out of poverty and into the middle class. Income inequality, though still high, has fallen sharply. For most Brazilians life has never been so good. rnib After viewing product detail pages or search results, look here to find an easy way to navigate back to pages you are interested in.

      Reply
    • Use CToolTipCtrl, this doesn't work.

      Posted by Legacy on 04/12/2002 12:00am

      Originally posted by: Paul Richards

      Don't even bother with this, CToolTipCtrl supports multiline, and delay times.

      Search this site for CToolTipCtrl for more info.

      Reply
    • nice idea, Doesnt Work Feb02

      Posted by Legacy on 02/20/2002 12:00am

      Originally posted by: cts

      No Balloons in Wind98 VC6

      Reply
    • The Reason of balloon can't see!

      Posted by Legacy on 12/14/2001 12:00am

      Originally posted by: DaFu Chen

      It has a bug in the CBalloonDialogDlg::OnOK()

      pEditName->GetLine(0, szName);
      pEditPassWd->GetLine(0, szPassWd);

      The GetLine() fuction has two versions :

      int GetLine( int nIndex, LPTSTR lpszBuffer ) const;
      int GetLine( int nIndex, LPTSTR lpszBuffer, int MaxLength ) const;

      For two parameters version, the first word of the buffer must specify the maximum number of bytes that can be copied to the buffer.

      So, change them to three parameters version like this:

      pEditName->GetLine(0, szName,40);
      pEditPassWd->GetLine(0, szPassWd,40);

      Now if you have not input the user name or password and press the "OK" button, you can see the balloons

      Good luck

      Reply
    • No Baloon seen on Win98

      Posted by Legacy on 12/13/2001 12:00am

      Originally posted by: Hari Ramakrishnan P

      I tried it for Win98, i cann't see any baloon.

      Reply
    • Good one....

      Posted by Legacy on 12/12/2001 12:00am

      Originally posted by: Srinidhi Rao

      Hey Prateek,
      
      

      Thats a good one. Indeed it would be a different way of communicating messages. Thanks for good work.

      It seems there is a problem with the Demo Zip. Check it out. Yeah, you can always write a simple demo app tp get it running... :-)

      Thanks
      Srini...

      Reply
    • Cool.. but..

      Posted by Legacy on 12/11/2001 12:00am

      Originally posted by: soichi

      As far as I see on the article, it looks really nice. But the zip files for the project you attached to the article contains CRC error on the resouce.rc! :) It will be nice if you could fix this problem.

      Thanks!

      Reply
    Leave a Comment
    • Your email address will not be published. All fields are required.

    Top White Papers and Webcasts

    • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

    • Hundreds of millions of users have adopted public cloud storage solutions to satisfy their Private Online File Sharing and Collaboration (OFS) needs. With new headlines on cloud privacy issues appearing almost daily, the need to explore private alternatives has never been stronger. Join ESG Senior Analyst Terri McClure and Connected Data in this on-demand webinar to take a look at the business drivers behind OFS adoption, how organizations can benefit from on-premise deployments, and emerging private OFS …

    Most Popular Programming Stories

    More for Developers

    RSS Feeds