Click here to Skip to main content
Click here to Skip to main content

Taskbar Notification dialog

By , 11 Jul 2002
 

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

  • TN_TEXT_NORMAL
  • TN_TEXT_BOLD
  • TN_TEXT_ITALIC
  • TN_TEXT_UNDERLINE

 

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.

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

About the Author

John O'Byrne
Web Developer
United States United States
Member
I live in Santa Clara CA and work as a software engineer for SAP Business Objects.
 
My areas of expertise are user interface developments in Eclipse RCP / SWT / Draw 2D and C#

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questioncan i add close button on notification bitmap???memberpramod_17_1027 Nov '12 - 16:07 
Hi,
 
I have written on application. in that application i have used notification dialog. i want to add Close button in that so user can close that dialog if they want.
how can we add close button on notification dialog???
 
thanks....
QuestionHow to scroll information in the pop up window?memberqingqingcao21 Dec '11 - 19:35 
Laugh | :laugh: Nice code,Thank u! I learn a lot from your code.....But i have a problem to ask you for help!
When the dialog's "m_nAnimStatus = IDT_WAITING",i want to show my information which is saved in an array one by one in the style of scrolling until all the information is shown,how to accomplish this?
 
Wish your reply~~~@_@
QuestionHow can i add a button in the Notifier Dlg?membersl11l11l11l20 Sep '11 - 17:23 
thanks...
QuestionWTL Task Bar NotifiermemberGene OK17 Aug '11 - 7:36 
I just completed a port of this code to WTL. VS 2010 project. Works on Windows XP, Vista, 7, x64 and Win32 compiles. http://www.codewiz51.com/wiki/WTL-Task-Bar-Notifier.ashx[^]
~Gene
 
-- Life is not a spectator sport. I came to play.
My Web Site, Blog & Wiki

QuestionDoes not work for Windows 7?memberrootdial8 Jul '09 - 0:02 
Hi there,
i tested my app on Windows 7 and it looks like the taskbar-Dialog
does not show up if i use this class. Worked fine for Windows XP so far Frown | :-(
 
Can someone confirm that or post any comment relating this problem?
AnswerRe: Does not work for Windows 7?memberMr. S12 Feb '11 - 6:49 
It's working at my system: Win7 x64
 
Try to delete the RT_Manifest of the resources and update version informations in stdafx.h
 
#ifndef WINVER				// Allow use of features specific to Windows 95 and Windows NT 4 or later.
#define WINVER 0x0501		// Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
 
#ifndef _WIN32_WINNT		// Allow use of features specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0501		// Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif						
 
#ifndef _WIN32_WINDOWS		// Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0501 // Change this to the appropriate value to target Windows Me or later.
#endif
 
#ifndef _WIN32_IE			// Allow use of features specific to IE 4.0 or later.
#define _WIN32_IE 0x0700	// Change this to the appropriate value to target IE 5.0 or later.
#endif

QuestionDoes Anyone has the xmesseger.zip file ?membertipiak0728 Jun '09 - 8:50 
Hello,
 
I find this class is very great but i need to use it in a thread. I saw in the comments the version xmessenger.zip but all the links are dead. Does anyone has it ?
If yes please send me the archive to tipiak07@yahoo.com. I will try to provide a link to share it for people who will need it in future reads of this article.
Best regards.
AnswerRe: Does Anyone has the xmesseger.zip file ?memberhandaomeng24 Mar '10 - 7:12 
also send me tangwanghan@gmail.com
thanks!
66

GeneralMultiple Text regionsmemberjamalhaider7 May '08 - 3:34 
Thanks for the great article Smile | :) .
 
How can multiple text regions can be defined on this dialog? Actually I need to have different Text formatting.
GeneralShockwave ActiveX problem!!memberpark00887 Jan '08 - 0:07 
It's a good stuff.
But, I found it makes a problem when it is used with "shockwave active x".
 
First, I made a dialog that contains "shockwave active x".
Second, launched this taskbar notification window up within the dialog.
Third, a focus changed to the poped window.
Finally, I have just clicked a keyboard when the focus went to the poped window.
Then, the dialog was stopped and I should end up the dialog using the Task Manager.
 
Does anyone solve this kind of problem? Then, please let me know.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 12 Jul 2002
Article Copyright 2002 by John O'Byrne
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid