Skip to main content
Email Password   helpLost your password?

Introduction

A few weeks ago I saw a MSN messenger popup class on Codeproject written by Prateek Kaul. Since I needed a taskbar popup with skin support, I decided to write my own new class.

This is my first submission to Codeproject, since I think my code begins to be mature enough to be posted.

Compatibility

This class needs MFC to be either statically or dynamically linked in your project; it has been written, compiled and tested under Visual Studio .Net (but should work with VC6)

How to use the Class

The class is very easy to use: Just add TaskbarNotifier.h and TaskbarNotifier.cpp into your project, then include TaskbarNotifier.h into your application, add a CTaskbarNotifier member variable in the header file of your Dialog or Window class.

In the OnInitDialog or OnCreate member functions add the following lines:

m_wndTaskbarNotifier.Create(this);
m_wndTaskbarNotifier.SetSkin(IDB_MY_BITMAP_RESOURCE);
m_wndTaskbarNotifier.SetTextFont("Arial",90,TN_TEXT_NORMAL,TN_TEXT_UNDERLINE);
m_wndTaskbarNotifier.SetTextColor(RGB(0,0,0),RGB(0,0,200));
m_wndTaskbarNotifier.SetTextRect(CRect(10,40,m_wndTaskbarNotifier1.m_nSkinWidth-10,
                                 m_wndTaskbarNotifier1.m_nSkinHeight-25));

Then when you want to show the popup animation just call anywhere m_wndTaskNotifier.Show("Text to display"); this will show the animation of the window appearing and then disappearing. You can call again the Show() method whenever you want. If the popup was still here, the text is just replaced, if it was disappearing, it maximizes again.

Be sure not to allocate the CTaskbarNotifier each time you want to show a message, because the skinning function takes a little CPU time to generate the region used to make a non rectangular window.

Class Documentation

int Create(CWnd *pWndParent);

Creates the popup window which remains hidden until Show() is called

 

BOOL SetSkin(UINT nBitmapID,short red=-1,short green=-1,short blue=-1);
BOOL SetSkin(LPCTSTR szFileName,short red=-1,short green=-1,short blue=-1);

Those two functions assign a skin to the popup, they take as parameter either a Bitmap resource ID or the path of a bitmap file.
The optional parameters are the RGB values for the transparency color for the bitmap. Use these parameters only if you want a non rectangular window; if these parameters are left blank no Region is created.

 

void SetTextFont(LPCTSTR szFont,int nSize,int nNormalStyle,int nSelectedStyle);

This function permits to specify the Font used for displaying the text (two styles are possible, one for the normal state and one when the mouse is over the window)

nNormalStyle or nSelectedStyle can be one or a combination of these parameters

 

void SetTextColor(COLORREF crNormalTextColor,COLORREF crSelectedTextColor);

This function sets the color of the text when in normal or selected state.

 

void SetTextRect(RECT rcText);

This function allows to define a rectangle within the bitmap which will be the clipping zone for displaying the text.

 

void Show(LPCTSTR szCaption,DWORD dwTimeToShow=800,DWORD dwTimeToStay=3000,
           DWORD dwTimeToHide=500,int nIncrement=1);

Dispays the popup window animation:

szCaption: Text to display
dwTimeToShow: Duration in milliseconds for the popup to be fully visible
dwTimeToStay: Duration in milliseconds for the popup to be stay visible
dwTimeToHide: Time in millisecond for the popup to completely disappear
nIncrement: Pixel increment for moving the window during the animation (the higher, the faster)

Show can be called even if the popup is already visible, being hiding or showing.

void Hide();

Manually Hides the popup.

Additional notes:

When the user clicks on the popup, a message is being sent to its parent window (WM_TASKBARNOTIFIERCLICKED defined in TaskbarNotifier.h), you can intercept it by adding in your Message Map macro:

ON_MESSAGE(WM_TASKBARNOTIFIERCLICKED,OnTaskbarNotifierClicked)

The fact I'm not releasing the HRGN handle is because when you call SetWindowRgn() function, the GDI takes care of the object deletion.

Conclusion

Thanks to Prateek Kaul whose code inspired me to write this class and to Vander Nunes for his article about skinning a window.

I hope this class will be useful to you, if you find any memory or GDI leaks, please let me know. If you have suggestions to enhance this class functionalities, please post a comment.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralDoes not work for Windows 7? Pin
rootdial
1:02 8 Jul '09  
GeneralDoes Anyone has the xmesseger.zip file ? Pin
tipiak07
9:50 28 Jun '09  
GeneralMultiple Text regions Pin
jamalhaider
4:34 7 May '08  
GeneralShockwave ActiveX problem!! Pin
park0088
1:07 7 Jan '08  
GeneralGREAT work!!! Pin
Assafk
3:08 31 Oct '07  
GeneralBad look on Vista Pin
_alav_
2:30 15 Oct '07  
GeneralRe: Bad look on Vista Pin
Sachin_Developer
20:53 30 Apr '08  
GeneralAnimated Gif is possible ? Pin
lbispo
10:44 11 Jul '07  
GeneralLong textes arent smart handled Pin
KarstenK
0:24 9 Jul '07  
GeneralHave you sample code... Pin
Antonio2929
0:44 13 Jun '07  
Generala problem about hide main window, then popup window hide. Pin
jacky_zz
20:06 31 May '07  
GeneralRe: a problem about hide main window, then popup window hide. Pin
stevenxyj
17:16 29 Sep '07  
GeneralRe: a problem about hide main window, then popup window hide. Pin
Member 4481224
21:05 28 Jan '08  
GeneralRe: a problem about hide main window, then popup window hide. Pin
Ralph Mullenders
3:05 2 Apr '08  
GeneralCan i add button or option in notifier window Pin
gugalia
20:58 1 May '07  
Questioncan i popup this notifier using win service..? Pin
raam_kimi
0:21 6 Feb '07  
Generalif my Module is console program, how can i use this style? Pin
charlie7908
5:20 27 Oct '06  
General'CWnd' : base class undefined [modified] Pin
JavaBeginner01
13:47 25 Aug '06  
GeneralRe: 'CWnd' : base class undefined Pin
Luke DeStevens
11:18 9 Oct '07  
GeneralAn error Pin
duplace
23:18 10 Aug '06  
QuestionHow to add flickering function.. [modified] Pin
wegaia
5:57 10 Aug '06  
GeneralNice but a little problem... Pin
howenActions
0:39 14 Jun '06  
GeneralError Pin
TheChode
10:17 6 Nov '05  
Questionhow to use this class in a managed c++ .net application Pin
olegarior
12:40 7 Oct '05  
AnswerRe: how to use this class in a managed c++ .net application Pin
scorpion_anshul
19:38 14 Jan '06  


Last Updated 11 Jul 2002 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009