A Class to Display Skinned Popups Like MSN Messenger
.

Click here for a larger image.
Environment: Dunno
Introduction
A few weeks ago I saw a MSN messenger popup class on Codeproject written by Prateek Kaul. Because I needed a taskbar popup with skin support, I decided to write my own new class derived from CWnd.
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 and 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));
When you want to show the popup animation, just call m_wndTaskNotifier.Show("Text to display") anywhere; this will show the animation of the window appearing and then disappearing. You can call the Show() method again 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);
This line 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 a parameter either a Bitmap resource ID or the path of a bitmap file. The optionnal 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 you 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 the normal or selected state.
void SetTextRect(RECT rcText);
This function enables you to define a rectangle within the bitmap, which will be the clipping zone for displaying the text.
void Show(LPCTSTR szCaption,DWORD dwTimeToShow=800,DWOR
dwTimeToStay=3000,DWORD dwTimeToHide=500,int nIncrement=1);
This 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
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();
This 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 (http://www.codeproject.com/useritems/statusbarmsgwnd.asp) and to Vander Nunes for his article about skinning a window (http://www.flipcode.com/articles/article_win32skins.shtml).
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's functionalities, please post a comment. (Sorry for my English; I'm French.)
John O'Byrne
Downloads
Download demo - 207 KbDownload source - 6 Kb

Comments
Interesting
Posted by snareenactina on 11/12/2012 08:41amusajiacong Ah, you touch on one of my favorite analogies. The 1987 cost of my first 2 head, wired remote VCR was $ 659.00. Today, I can get a better one with DVD player for less than $ 89.00 bucks. The cost of the 1970 Nova, was I believe $ 2,300. Today, maybe $ 19,000 for the equivalent. Why? After discarding socialist economic policies in the mid-1990s, Madagascar followed a World Bank- and IMF-led policy of privatization and liberalization that has been undermined since the start of the political crisis. This strategy placed the country on a slow and steady growth path from an extremely low level. Agriculture, including fishing and forestry, is a mainstay of the economy, accounting for more than one-fourth of GDP and employing 80% of the population. Exports of apparel boomed in recent years primarily due to duty-free access to the US, however, Madagascar's failure to comply with the requirements of the African Growth and Opportunity Act (AGOA) led to the termination of the country's duty-free access in January 2010 and a sharp fall in textile production. Deforestation and erosion, aggravated by the use of firewood as the primary source of fuel, are serious concerns. The current political crisis, which began in early 2009, has dealt additional blows to the economy. Tourism dropped more than 50% in 2009 compared with the previous year, and many investors are wary of entering the uncertain investment environment. Learn about outfitting your fleet's vehicles with devices that save fuel. diversified The five health markets typically analyzed are: analternate Business strategies for the digital age. Free website from the Economist Intelligence Unit. bluer If you're reading this at work, brace yourself. berm CANBERRA, July 23 (Xinhua) -- Australia's economy has recorded a 3.2 percent growth in the year to June 2012, said a report by Australia's leading private sector economic advisory released Monday. etims Oil rose on Monday as the dollar slid and stock market gains nullified earlier fears about interest rate hikes. setsls This game is more of a text based MMORPG, and people who are playing it either they are attracted to it from the first moments either not. sinai The article informs consumers about diffrent white collar crimes they can be victims of and how it can effect them.
ReplySupply Chain Management Software - ecVision
Posted by frankfurrter on 12/13/2010 12:41pmecVision develops and deploys supply chain management software solutions for private brands and retailers. These applications provide greater collaboration capabilities and ensure visibility into their global supply network. http://ecvision.com
ReplyHelp..Why cannot download ?
Posted by Ben__21 on 12/14/2005 03:14amIt looks a great class, I am so eager to get it , but the download is invalid :(
-
ReplyRe: Help..Why cannot download ?
Posted by meldor on 12/15/2005 04:27amMe neither. Seems to be a problem with the codeguru server.. Anyway, I found a link to this file: http://cosoft.org.cn/html/osl/showFiles.php?group_id=13656 Hope it helps.
ReplyThis is a great class - thanks!!!!
Posted by keritusa on 03/01/2005 07:40pmThis is well-documented & very easy to integrate. Thanks! Keri
ReplyHi to all C++ guys
Posted by niznaz on 01/20/2005 01:40pmI'm a CaVo programmer, and dont know much about C++. Will some-1 be kind enough to prepare a DLL please ? TIA Nizan
Replyhelp!
Posted by Legacy on 12/09/2003 12:00amOriginally posted by: anonamous
hey man i need help i dnt no wat this program is ment to do
Reply
Pop up window disappears on minimize of parent window
Posted by Legacy on 08/16/2003 12:00amOriginally posted by: shehzad salim
Well u have written a very good class
But there is a problem when I minimize parent window pop up window disappers, and comes back when parent window restores how could I solve this problem...
ReplyPop up window disappears on minimize of parent window
Wonderful world because code like this
Posted by Legacy on 01/27/2003 12:00amOriginally posted by: Invoker
COOL!
ReplyCan i hv this feature in a DLL?
Posted by Legacy on 01/14/2003 12:00amOriginally posted by: Ajaz
Wonderful demo!, I want it in a DLL, can i get it, i am trying to convert in DLL, but not working since yr demo consist of dialog on which yr popup window is dependent for messages and all....
Need Help
ReplyExcellent code!
Posted by Legacy on 12/20/2002 12:00amOriginally posted by: Deepak
Excellent code. Great job!
ReplyLoading, Please Wait ...