Click here to Skip to main content
11,575,921 members (58,263 online)
Click here to Skip to main content

Outlook like notification window using ATL

, 11 Aug 2006 CPOL 36.4K 1.1K 44
Rate this:
Please Sign up or sign in to vote.
Create an Outlook like notification window using ATL.

Sample Image - Notifier_using_ATL.jpg

Introduction

When using Microsoft® Outlook®, we come across the mail notification window, which appears slowly and starts disappearing. It displays a summary of a mail, including the sender's name etc. This articles describes how to build that kind of a window using ATL.

Background

I recently came across an article by Nick Wälti. But did not find any C++ code for achieving the same. So I tried to achieve something similar using ATL.

Using the code

There are three classes:

  • CATLNotifyDialog represents the main UI.
  • CNotifyWnd represents the notification window.
  • CBmpButton represents the bitmap button class, used as the 'Close' button.
typedef CWinTraits <WS_CLIPCHILDREN | WS_POPUP |WS_VISIBLE ,0 > CNotificationWinTraits;
class CNotifyWnd : public CWindowImpl<CNotifyWnd,CWindow,CNotificationWinTraits>
{
    .
    .    
    CBmpButton* m_pButton;//owner drawn button class

public:
    //constructor

    DECLARE_WND_CLASS("CNotifyWnd")
    BEGIN_MSG_MAP(CNotifier)
        MESSAGE_HANDLER(WM_CREATE, OnCreate)
        .
        .
        .
        //reflect notifications to child

        REFLECT_NOTIFICATIONS()
    END_MSG_MAP()
    void CreateNotifyWindow();
private:
    LRESULT ChangeOpacity(BYTE iFactor);
    //message handler functions

};

The macro REFLECT_NOTIFICATIONS is declared to send messages to child windows. In this case, the button window is the child. In the OnCreate function, modify the extended style of the window by adding WS_EX_LAYERED. More information on Layered Windows can found in the MSDN.

    if ( ModifyStyleEx(0,WS_EX_LAYERED ))
    {
        //successfully modified style to make window as layered window

        //now use timer

        SetTimer(TIMER_ID ,30);
        m_bTimerActive=TRUE;
    }

The ChangeOpacity function of this class will bring a translucent effect to the window.

LRESULT CNotifyWnd::ChangeOpacity(BYTE iFactor)
{
    //define function pointer

    typedef DWORD (WINAPI *pSetLayeredWindowAttributes)(HWND, DWORD, BYTE, DWORD);
    pSetLayeredWindowAttributes SetLayeredWindowAttributes;
    HMODULE hDLL = LoadLibrary ("user32");
    if (hDLL )
    {
        SetLayeredWindowAttributes = (pSetLayeredWindowAttributes) 
                 GetProcAddress(hDLL,"SetLayeredWindowAttributes");
        ATLASSERT(SetLayeredWindowAttributes );//using WIN2k or onward ?

        BOOL bRes=SetLayeredWindowAttributes(m_hWnd,RGB(255,255,255), 
                                  iFactor, LWA_COLORKEY | LWA_ALPHA);
        FreeLibrary(hDLL);    
    }
    else
    {
        //not able to load library

        ATLASSERT(0);
    }
    return 0;
}

The class CBmpButton is a button class. It uses three bitmaps to represent its states, i.e., normal, mouse move, and pressed. I could not get better bitmaps for this application, but a more artistic person can really make it beautiful.

class CBmpButton :public CWindowImpl<CBmpButton>
{
    UINT m_BitmapId[3];//represents three states of button

    UINT m_nCurrentBmp;
public:
    DECLARE_WND_SUPERCLASS( _T("BitmapButton"), _T("Button") )
    BEGIN_MSG_MAP(CBmpButton)
    //message handlers

    .
    .
    .
      MESSAGE_HANDLER(OCM_DRAWITEM, OnDrawItem)
    DEFAULT_REFLECTION_HANDLER()//this will handle messages refected by parent

    END_MSG_MAP()
private:
    //message handlers

};

Here is an important function of the above class:

LRESULT CBmpButton::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    //make button owner drawn

    ModifyStyle(0,BS_OWNERDRAW);
    return 1;
}

Functions like CBmpButton::OnLButtonDown, CBmpButton::OnLButtonUP, CBmpButton::OnMouseLeave, and CBmpButton::OnMouseLeave will set m_nCurrentBmp with the appropriate bitmap.

    //using this will enable WM_MOUSELEAVE notification

    TrackMouseEvent(&stMouseEvent);

The code assumes that the taskbar is always at the bottom (does not consider other cases).

Points of Interest

It does not use MFC (that's lighter!).

History

  • v1.0 - 11 Aug 2006.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

prasad_som
Software Developer
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionHow to change message Pin
Member 892143513-Nov-12 3:42
memberMember 892143513-Nov-12 3:42 
Questionuse for network Pin
sep26748-Jun-12 4:17
membersep26748-Jun-12 4:17 
QuestionHow to use this component in our web application Pin
lokesh216513-Mar-07 21:24
memberlokesh216513-Mar-07 21:24 
AnswerRe: How to use this component in our web application Pin
prasad_som13-Mar-07 21:38
memberprasad_som13-Mar-07 21:38 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150603.1 | Last Updated 11 Aug 2006
Article Copyright 2006 by prasad_som
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid