Click here to Skip to main content
12,512,130 members (51,545 online)
Click here to Skip to main content

Stats

67.1K views
2.5K downloads
67 bookmarked
Posted

Shell Extensibility - Explorer Desk Band, Tray Notification Icon et al.

, 28 Aug 2009 CPOL
A simple Calendar utility that demonstrates basic Shell extensibility techniques: desk band, tray notification icon, locales.
Calendar
CalendarDeskBand
CalendarDeskBand.def
CalendarDeskBand.rgs
CalendarDeskBandApp.rgs
CalendarSysTray
Res
01.ico
02.ico
03.ico
04.ico
05.ico
06.ico
07.ico
08.ico
09.ico
10.ico
11.ico
12.ico
13.ico
14.ico
15.ico
16.ico
17.ico
18.ico
19.ico
20.ico
21.ico
22.ico
23.ico
24.ico
25.ico
26.ico
27.ico
28.ico
29.ico
30.ico
31.ico
Blank-16x16-16.ico
Calendar.ico
Common
Win32
Release
Calendar.exe
x64
Release
Calendar.exe
#pragma once

#include "OptionsDialog.h"

///////////////////////////////////////////////////////////////////////////
//
typedef CWinTraitsOR<0, WS_EX_LAYERED, CFrameWinTraits> CCalendarWinTraits;

#define MONTHCAL_MSG_MAP_ID  1
const UINT WM_SYSTRAYNOTIFY = WM_APP + 1;
const UINT WM_APPBARNOTIFY = WM_APP + 2;

///////////////////////////////////////////////////////////////////////////
//
class CCalendarWindow :
    public CWindowImpl<CCalendarWindow, CWindow, CCalendarWinTraits>
{
public:
    CCalendarWindow();

    DECLARE_WND_CLASS_EX(TEXT("CalendarWindow"), 0, COLOR_WINDOW)

    static LPCTSTR GetWndCaption()
    {
        static CString strCaption;
        if(strCaption.IsEmpty())
        {
            ATLVERIFY(strCaption.LoadString(IDS_CALENDAR));
        }
            
        return strCaption;
    }

    BEGIN_MSG_MAP(CCalendarWindow)
        MESSAGE_HANDLER(WM_CREATE, OnCreate)
        MESSAGE_HANDLER(WM_SIZE, OnSize)
        MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand)
        MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
        MESSAGE_HANDLER(WM_SYSTRAYNOTIFY, OnSysTrayNotify)
        MESSAGE_HANDLER(WM_CLOSE, OnClose)
        MESSAGE_HANDLER(WM_TIMECHANGE, OnTimeChange)
        MESSAGE_HANDLER(WM_TIMER, OnTimer)
        MESSAGE_HANDLER(WM_ENDSESSION, OnEndSession)
        MESSAGE_HANDLER(WM_POWERBROADCAST, OnPowerBroadcast)
        MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
        MESSAGE_HANDLER(s_uTaskbarRestart, OnTaskbarRestart)
        ALT_MSG_MAP(MONTHCAL_MSG_MAP_ID)
    END_MSG_MAP()

// message handlers
    LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnSysCommand(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnSysTrayNotify(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnTimeChange(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnTimer(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnEndSession(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnPowerBroadcast(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnSetFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnTaskbarRestart(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);

private:
    bool InitMenu();
    bool InitIcons();
    bool CreateChildren(LPCREATESTRUCT pcs);
    bool ApplySettings(bool bResize);
    bool ApplyTransparency();
    bool ApplyWindowPos(bool bResize);
    bool ApplyCalendarProperties();
    bool ApplySysTrayProperties();
    bool ApplyDeskbandProperties() const;
    bool DeskbandInstalled() const;
    CPath GetDeskbandModulePath() const;
    bool ExtractDeskbandBinary(const CPath& deskbandPath) const;
    bool DeleteDeskbandBinary(const CPath& deskbandPath) const;
    bool RegisterDeskband(const CPath& deskbandPath, bool bRegister) const;
    HRESULT RegisterDeskbandXP(const CPath& deskbandPath, bool bRegister) const;
    DWORD RegisterDeskbandSecure(CPath deskbandPath, bool bRegister) const;
    bool ShowDeskband() const;
    bool HideDeskband() const;
    bool ShowOptions();
    bool InitSettingsPath();
    bool UpdateSysTrayIcon(DWORD dwAction);
    HICON LoadDayIcon(const SYSTEMTIME& st);
    void ShowAboutBox();
    int ShowContextMenu();
    void HandleContextCommand(int nCmd);
    UINT_PTR SetUpdateTimer();
    void UpdateTodayDate(const SYSTEMTIME& stNow);
    void ShowAndActivate();

    const static int UPDATE_TIMER_ID = 1;

private:
    CContainedWindow m_ctrlMonthCal;
    COptionsDialog m_dlgOptions;
    CPath m_pathSettings;
    HICON m_hSysTrayIcon;
    HICON m_hWndIconSmall;
    HICON m_hWndIcon;

    static UINT s_uTaskbarRestart;
};

/////////////////////////////////////////////////////////////////////////////

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

Alex Blekhman
Software Developer
Australia Australia
More than ten years of C++ native development, and counting.

Smile | :)

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160929.1 | Last Updated 28 Aug 2009
Article Copyright 2009 by Alex Blekhman
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid