Click here to Skip to main content
15,886,110 members
Articles / Desktop Programming / Win32
Tip/Trick

Badges for Windows 7

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
9 Mar 2012CPOL 12.4K   482   3  
Short description how to create a sexy badge for windows 7 taskbar

Introduction 

How to use ITaskbarList3 in C++ to add overlay icon into taskbar. 

Using the code

Before using ITaskbarList3, we must receive TaskbarButtonCreated message from system. First we must register this message.

C++
s_uTBBC = RegisterWindowMessage(L"TaskbarButtonCreated");

In our message loop we can catch this message and call our function:

C++
if( message == s_uTBBC ) {
    onTaskbarButtonCreated(wParam, lParam);
}

Create instance of ITaskbarList3 and set the overlay icon.

C++
static LRESULT onTaskbarButtonCreated(WPARAM wParam, LPARAM lParam) {

    HRESULT result = CoCreateInstance(CLSID_TaskbarList, NULL, 
                        CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_pTaskBarlist));

    if (SUCCEEDED(result)) { 
        result = m_pTaskBarlist->HrInit(); 
        if (SUCCEEDED(result)) {

            HICON icon = createBadgeIcon(_T("78"));
            m_pTaskBarlist->SetOverlayIcon(m_hWnd, icon, _T("Status"));
            DeleteObject(icon);

        }
    }

    return 0;
}

I use GDI+ for creating badge icon. For create cool small ellipse I use circle (letter 'l') from Wingdings font :)

C++
static HICON createBadgeIcon(const TCHAR *value) {

    Color bagdeColor = Color(233, 0, 0);
    Color textColor = Color(244, 244, 244);
//
    Bitmap *bitmap = new Bitmap(24, 24, PixelFormat32bppARGB);
    m_Graphics = Graphics::FromImage(bitmap);
//
    StringFormat format(StringFormatFlagsNoWrap);
    format.SetAlignment(StringAlignmentCenter); 
    format.SetLineAlignment(StringAlignmentCenter);
//
    m_Graphics->DrawString(_T("l"), 1, 
                            new Font(_T("Wingdings"), 24), 
                            RectF(1, 2, 24, 24), 
                            &format, 
                            new SolidBrush(bagdeColor));
    m_Graphics->DrawString(value, wcslen(value), 
                            new Font(_T("Calibri"), 8), 
                            RectF(1, 2, 24, 20), 
                            &format, new SolidBrush(textColor));
//
    HICON icon;
    bitmap->GetHICON(&icon);
    // Cleanup
    delete bitmap;
    return icon;
}

History

Version 1.0.

License

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


Written By
Malaysia Malaysia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --