Vladimir:
I never expected so many people to use TAnimatedTrayIcon
so I never even considered version numbers but with the new
TTrayIcon in BDS, while better than the old, it's still weak so
I'd expect that the more people that are aware of it, the more
people that will use it. Since you last saw it, I've made
several changes to the component and even a couple of custom
jobs for individuals so I've labeled it's version as 1.5.0.
The changes that have been made no longer require it to be
Owned by the main form and it should be fine with multiple
instance in the application but I just haven't had time to get
around to changing the code and testing it.
The only question that I have with it is with the
DetermineShellVersion method that sets the FCanBalloon
property. Currently, ballooning is only allowed if the
SHELL32.dll version is greater than or equal to 5.0 but
I ran across something on MSN that makes me think that
ballooning should also be allowed for win2k (4.0) but I
don't have that OS to test it.
I also haven't tested it as a component installed in the IDE
but I did code it to be installed so I'm presuming that all is
well on that front.
Let me know if you find any bugs or make any improvements.
~ JD
//------------------------------------------------------------------------- --
//- -
//- TAnimatedTrayIcon version 1.5.0 -
//- -
//- You may use this code in whole or in part for any purpose except that -
//- you may not sell it as a component or part of a component pack. It's -
//- free for any one who wants it - period. -
//- -
//- Direct questions, comments and changes to idea...@hotmail.com or post -
//- to the vcl.using group. -
//- -
//------------------------------------------------------------------------- --
#ifndef AnimatedTrayIconH
#define AnimatedTrayIconH
//------------------------------------------------------------------------- --
#include <Classes.hpp>
#include <vector>
//------------------------------------------------------------------------- --
// M$ says this should be 0x0500 for shellapi >= 5.0
// but cpp needs it to be 0x0501 or 0x0600
#undef _WIN32_IE
#define _WIN32_IE 0x0501
#include <shellapi.h>
#include <shlwapi.h>
#include <mmsystem.h>
//------------------------------------------------------------------------- --
#include "TrayThread.h"
//------------------------------------------------------------------------- --
enum TBalloonIconType
{
itNone = 0,
itInformation,
itWarning,
itError,
itQuestion,
itNoSound,
itUser
};
//------------------------------------------------------------------------- --
class TAnimatedTrayIcon : public TComponent
{
private:
#define NIIF_QUESTION 0x07
#define NIIF_USER 0x14
typedef TComponent inherited;
LPVOID MinimizeWave, RestoreWave;
DWORD MinimizeSize, RestoreSize;
unsigned int ClickTimer;
unsigned int CM_TRAYNOTIFY;
unsigned int CM_TRAYCREATED;
unsigned int CM_TASKBARCREATED;
std::vector<HWND>vZOrder;
std::vector<TForm*>vForms;
HWND FHandle;
TForm *FParentForm;
TRect BoundsRect, TrayRect;
TAnimatedTrayIconThread *FThread;
bool FMinimized;
bool FHooked;
bool FInstalled;
bool FAnimating;
bool FCanBalloon;
bool FAnimateWindow;
bool FLoopSound;
bool FUseTray;
int FDelay;
int FStaticIndex;
bool FActive;
int FTrayID;
int FFromIndex;
int FToIndex;
TThreadPriority FPriority;
AnsiString FStaticHint;
AnsiString FAnimationHint;
AnsiString FAnimateWave;
TImageList *FImageList;
TPopupMenu *FPopupMenu;
HIMAGELIST hImageList;
AnsiString FBalloonCaption;
AnsiString FBalloonText;
TBalloonIconType FBalloonIconType;
UINT FBalloonIcon;
UINT FBalloonTimeout;
DWORD FStartTickCount;
TShiftState FLeftClickShift;
TMouseEvent FOnMouseUp;
TMouseEvent FOnMouseDown;
TNotifyEvent FOnClick;
TNotifyEvent FOnDblClick;
TNotifyEvent FOnBalloonClick;
TNotifyEvent FOnBalloonShow;
TNotifyEvent FOnBalloonHide;
TNotifyEvent FOnBalloonClose;
TNotifyEvent FOnBalloonTimeOut;
void __fastcall LoadSound( AnsiString ID, DWORD &Size, LPVOID &hMemWave );
void __fastcall SetClickTimer( bool Enable );
void __fastcall ModifyTray();
void __fastcall DetermineShellVersion();
void __fastcall GetSysTrayRect();
// setter methods
void __fastcall SetActive( bool State );
void __fastcall SetStaticIndex( int Index );
void __fastcall SetStaticHint( AnsiString Hint );
void __fastcall SetImageList( TImageList* );
void __fastcall SetPopupMenu( TPopupMenu* );
protected:
virtual void __fastcall Loaded();
virtual void __fastcall Notification( TComponent *AComponent, TOperation Operation );
virtual void __fastcall WndProc( TMessage &Message );
void __fastcall MouseDown(TMouseButton Button, TShiftState Shift );
void __fastcall MouseUp(TMouseButton Button, TShiftState Shift );
bool __fastcall AppHook( TMessage &Message );
public:
void __fastcall StartAnimation();
void __fastcall StopAnimation();
bool __fastcall Minimize();
bool __fastcall Restore();
void __fastcall DoBalloonTip();
__fastcall TAnimatedTrayIcon(TComponent* Owner);
__fastcall TAnimatedTrayIcon::~TAnimatedTrayIcon();
__published:
__property TMouseEvent OnMouseUp = { read = FOnMouseUp, write = FOnMouseUp };
__property TMouseEvent OnMouseDown = { read = FOnMouseDown, write = FOnMouseDown };
__property TNotifyEvent OnClick = { read = FOnClick, write = FOnClick };
__property TNotifyEvent OnDblClick = { read = FOnDblClick, write = FOnDblClick };
__property TNotifyEvent OnBalloonClick = { read = FOnBalloonClick, write = FOnBalloonClick };
__property TNotifyEvent OnBalloonShow = { read = FOnBalloonShow, write = FOnBalloonShow };
__property TNotifyEvent OnBalloonHide = { read = FOnBalloonHide, write = FOnBalloonHide };
__property TNotifyEvent OnBalloonClose = { read = FOnBalloonClose, write = FOnBalloonClose };
__property TNotifyEvent OnBalloonTimeOut = { read = FOnBalloonTimeOut, write = FOnBalloonTimeOut };
__property bool AnimateWindow = { read = FAnimateWindow, write = FAnimateWindow, default = false };
__property int AnimationDelay = { read = FDelay, write = FDelay, default = 50 };
__property int TrayID = { read = FTrayID, write = FTrayID, default = 1643 };
__property int AnimateIndexStart = { read = FFromIndex, write = FFromIndex };
__property int AnimateIndexEnd = { read = FToIndex, write = FToIndex };
__property AnsiString AnimationHint = { read = FAnimationHint, write = FAnimationHint };
__property AnsiString AnimateWaveSound = { read = FAnimateWave, write = FAnimateWave };
__property TThreadPriority AnimationPriority = { read = FPriority, write = FPriority, default = tpNormal };
__property TImageList *ImageList = { read = FImageList, write = SetImageList };
__property TPopupMenu *PopupMenu = { read = FPopupMenu, write = SetPopupMenu };
__property bool LoopAnimateSound = { read = FLoopSound, write = FLoopSound, default = true };
__property bool Active = { read = FActive, write = SetActive, default = false };
__property int StaticIndex = { read = FStaticIndex, write = SetStaticIndex };
__property AnsiString StaticHint = { read = FStaticHint, write = SetStaticHint };
__property bool MinimizeToTray = { read = FUseTray, write = FUseTray, default = true };
__property AnsiString BalloonCaption = { read = FBalloonCaption, write = FBalloonCaption };
__property AnsiString BalloonText = { read = FBalloonText, write = FBalloonText };
__property TBalloonIconType BalloonIconType = { read = FBalloonIconType, write = FBalloonIconType, default = itInformation };
// HICON is not an allowed type so I just used UINT and cast it when it's used
__property UINT BalloonIcon = { read = FBalloonIcon, write = FBalloonIcon };
__property UINT BalloonTimeout = { read = FBalloonTimeout, write = FBalloonTimeout, default = 1500 };
};
//------------------------------------------------------------------------- --
#endif
//------------------------------------------------------------------------- --
#include <vcl.h>
//------------------------------------------------------------------------- --
#pragma hdrstop
//------------------------------------------------------------------------- --
#include "AnimatedTrayIcon.h"
//------------------------------------------------------------------------- --
// Tray.res is not included with the sample.
// All it is [was] is the sound resources.
//#pragma resource "Tray.res"
//------------------------------------------------------------------------- --
#pragma package(smart_init)
// Used to ensure only a single instance of this object type application wide
TAnimatedTrayIcon *ThisAnimatedTrayIconInstance = NULL;
//------------------------------------------------------------------------- --
__fastcall TAnimatedTrayIcon::TAnimatedTrayIcon( TComponent *Owner ) : TComponent(Owner)
{
if( ThisAnimatedTrayIconInstance )
{
...
read more »