/////////////////////////////////////////////////////////////////////////////
// SystemTray.cpp : implementation file
//
// MFC VERSION
//
// This is a conglomeration of ideas from the MSJ "Webster" application,
// sniffing round the online docs, and from other implementations such
// as PJ Naughter's "CTrayNotifyIcon" (http://indigo.ie/~pjn/ntray.html)
// especially the "CSystemTray::OnTrayNotification" member function.
// Joerg Koenig suggested the icon animation stuff
//
// This class is a light wrapper around the windows system tray stuff. It
// adds an icon to the system tray with the specified ToolTip text and
// callback notification value, which is sent back to the Parent window.
//
// The tray icon can be instantiated using either the constructor or by
// declaring the object and creating (and displaying) it later on in the
// program. eg.
//
// CSystemTray m_SystemTray; // Member variable of some class
//
// ...
// // in some member function maybe...
// m_SystemTray.Create(pParentWnd, WM_MY_NOTIFY, "Click here",
// hIcon, nSystemTrayID);
//
// Written by Chris Maunder (cmaunder@mail.com)
// Copyright (c) 1998-2003.
//
// Updated: 25 Jul 1998 - Added icon animation, and derived class
// from CWnd in order to handle messages. (CJM)
// (icon animation suggested by Joerg Koenig.
// Added API to set default menu item. Code provided
// by Enrico Lelina.
//
// Updated: 6 June 1999 - SetIcon can now load non-standard sized icons (Chip Calvert)
// Added "bHidden" parameter when creating icon
// (Thanks to Michael Gombar for these suggestions)
// Restricted tooltip text to 64 characters.
//
// Updated: 9 Nov 1999 - Now works in WindowsCE.
// Fix for use in NT services (Thomas Mooney, TeleProc, Inc)
// Added W2K stuff by Michael Dunn
//
// Updated: 1 Jan 2000 - Added tray minimisation stuff.
//
// Updated: 21 Sep 2000 - Added GetDoWndAnimation - animation only occurs if the system
// settings allow it (Matthew Ellis). Updated the GetTrayWndRect
// function to include more fallback logic (Matthew Ellis)
// NOTE: Signature of GetTrayWndRect has changed!
//
// Updated: 4 Aug 2003 - Fixed bug that was stopping icon from being recreated when
// Explorer crashed
// Fixed resource leak in SetIcon
// Animate() now checks for empty icon list - Anton Treskunov
// Added the virutal CustomizeMenu() method - Anton Treskunov
//
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is
// not sold for profit without the authors written consent, and
// providing that this notice and the authors name is included. If
// the source code in this file is used in any commercial application
// then acknowledgement must be made to the author of this file
// (in whatever form you wish).
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability for any damage caused through use.
//
// Expect bugs.
//
// Please use and enjoy. Please let me know of any bugs/mods/improvements
// that you have found/implemented and I will fix/incorporate them into this
// file.
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SystemTray.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#ifndef _WIN32_WCE // Use C++ exception handling instead of structured.
#undef TRY
#undef CATCH
#undef END_CATCH
#define TRY try
#define CATCH(ex_class, ex_object) catch(ex_class* ex_object)
#define END_CATCH
#endif // _WIN32_WCE
#ifndef _countof
#define _countof(x) ( sizeof(x) / sizeof(x[0]) )
#endif
IMPLEMENT_DYNAMIC(CSystemTray, CWnd)
const UINT CSystemTray::m_nTimerID = 4567;
UINT CSystemTray::m_nMaxTooltipLength = 64; // This may change...
const UINT CSystemTray::m_nTaskbarCreatedMsg = ::RegisterWindowMessage(_T("TaskbarCreated"));
CWnd CSystemTray::m_wndInvisible;
/////////////////////////////////////////////////////////////////////////////
// CSystemTray construction/creation/destruction
CSystemTray::CSystemTray()
{
Initialise();
}
CSystemTray::CSystemTray(CWnd* pParent, // The window that will recieve tray notifications
UINT uCallbackMessage, // the callback message to send to parent
LPCTSTR szToolTip, // tray icon tooltip
HICON icon, // Handle to icon
UINT uID, // Identifier of tray icon
BOOL bHidden /*=FALSE*/, // Hidden on creation?
LPCTSTR szBalloonTip /*=NULL*/, // Ballon tip (w2k only)
LPCTSTR szBalloonTitle /*=NULL*/, // Balloon tip title (w2k)
DWORD dwBalloonIcon /*=NIIF_NONE*/,// Ballon tip icon (w2k)
UINT uBalloonTimeout /*=10*/) // Balloon timeout (w2k)
{
Initialise();
Create(pParent, uCallbackMessage, szToolTip, icon, uID, bHidden,
szBalloonTip, szBalloonTitle, dwBalloonIcon, uBalloonTimeout);
}
void CSystemTray::Initialise()
{
memset(&m_tnd, 0, sizeof(m_tnd));
m_bEnabled = FALSE;
m_bHidden = TRUE;
m_bRemoved = TRUE;
m_DefaultMenuItemID = 0;
m_DefaultMenuItemByPos = TRUE;
m_bShowIconPending = FALSE;
m_uIDTimer = 0;
m_hSavedIcon = NULL;
m_pTargetWnd = NULL;
m_uCreationFlags = 0;
#ifdef SYSTEMTRAY_USEW2K
OSVERSIONINFO os = { sizeof(os) };
GetVersionEx(&os);
m_bWin2K = ( VER_PLATFORM_WIN32_NT == os.dwPlatformId && os.dwMajorVersion >= 5 );
#else
m_bWin2K = FALSE;
#endif
}
// update by Michael Dunn, November 1999
//
// New version of Create() that handles new features in Win 2K.
//
// Changes:
// szTip: Same as old, but can be 128 characters instead of 64.
// szBalloonTip: Text for a balloon tooltip that is shown when the icon
// is first added to the tray. Pass "" if you don't want
// a balloon.
// szBalloonTitle: Title text for the balloon tooltip. This text is shown
// in bold above the szBalloonTip text. Pass "" if you
// don't want a title.
// dwBalloonIcon: Specifies which icon will appear in the balloon. Legal
// values are:
// NIIF_NONE: No icon
// NIIF_INFO: Information
// NIIF_WARNING: Exclamation
// NIIF_ERROR: Critical error (red circle with X)
// uBalloonTimeout: Number of seconds for the balloon to remain visible.
// Must be between 10 and 30 inclusive.
BOOL CSystemTray::Create(CWnd* pParent, UINT uCallbackMessage, LPCTSTR szToolTip,
HICON icon, UINT uID, BOOL bHidden /*=FALSE*/,
LPCTSTR szBalloonTip /*=NULL*/,
LPCTSTR szBalloonTitle /*=NULL*/,
DWORD dwBalloonIcon /*=NIIF_NONE*/,
UINT uBalloonTimeout /*=10*/)
{
#ifdef _WIN32_WCE
m_bEnabled = TRUE;
#else
// this is only for Windows 95 (or higher)
m_bEnabled = (GetVersion() & 0xff) >= 4;
if (!m_bEnabled)
{
ASSERT(FALSE);
return FALSE;
}
#endif
m_nMaxTooltipLength = _countof(m_tnd.szTip);
//
system tray 源码MFC and SDK
需积分: 9 185 浏览量
2008-11-12
13:34:30
上传
评论
收藏 23KB ZIP 举报
蒜蓉粉丝蒸扇贝
- 粉丝: 13
- 资源: 8
最新资源
- 基于Matlab人脸肤色定理的教师人数统计+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab霍夫曼变换的表盘读数识别+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab火灾烟雾检测源码带GUI界面+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab的恶劣天气交通标志识别系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB的霍夫曼变换的表盘示数识别+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab的车道线识别系统 +源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB的教室人数统计系统带Gui界面+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB的教室人数统计系统带Gui界面+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB 的霍夫曼变换答题卡识别源码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab+bp神经网络的神经网络汉字识别系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈