请问怎么在mfc中对话框程序一运行就成为系统托盘 请问怎么在mfc中对话框程序一运行就成为系统托盘 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用这个类:#ifndef _INCLUDED_SYSTEMTRAY_H_#define _INCLUDED_SYSTEMTRAY_H_/////////////////////////////////////////////////////////////////////////////// CSystemTray windowclass CSystemTray : public CObject{// Construction/destructionpublic: CSystemTray(); CSystemTray(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID); virtual ~CSystemTray();// Operationspublic: CFrameWnd * m_pFrame; BOOL Enabled() { return m_bEnabled; } BOOL Visible() { return !m_bHidden; } //Create the tray icon Create(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID); //Change or retrieve the Tooltip text BOOL SetTooltipText(LPCTSTR pszTooltipText); BOOL SetTooltipText(UINT nID); CString GetTooltipText() const; //Change or retrieve the icon displayed BOOL SetIcon(HICON hIcon); BOOL SetIcon(LPCTSTR lpIconName); BOOL SetIcon(UINT nIDResource); BOOL SetStandardIcon(LPCTSTR lpIconName); BOOL SetStandardIcon(UINT nIDResource); HICON GetIcon() const; void HideIcon(); void ShowIcon(); void RemoveIcon(); void MoveToRight(); //Change or retrieve the window to send notification messages to BOOL SetNotificationWnd(CWnd* pNotifyWnd); CWnd* GetNotificationWnd() const; //Default handler for tray notification message// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CSystemTray) //}}AFX_VIRTUAL// Implementationprotected: BOOL m_bEnabled; // does O/S support tray icon? BOOL m_bHidden; // Has the icon been hidden? NOTIFYICONDATA m_tnd; DECLARE_DYNAMIC(CSystemTray)};#endif#include "stdafx.h"#include "SystemTray.h"//#include "MenuEx.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endifIMPLEMENT_DYNAMIC(CSystemTray, CObject)/////////////////////////////////////////////////////////////////////////////// CSystemTray construction/creation/destructionCSystemTray::CSystemTray(){ memset(&m_tnd, 0, sizeof(m_tnd)); m_bEnabled = FALSE; m_bHidden = FALSE;}CSystemTray::CSystemTray(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szToolTip, HICON icon, UINT uID){ Create(pWnd, uCallbackMessage, szToolTip, icon, uID); m_bHidden = FALSE;}BOOL CSystemTray::Create(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szToolTip, HICON icon, UINT uID){ // this is only for Windows 95 (or higher) VERIFY(m_bEnabled = ( GetVersion() & 0xff ) >= 4); if (!m_bEnabled) return FALSE; //Make sure Notification window is valid VERIFY(m_bEnabled = (pWnd && ::IsWindow(pWnd->GetSafeHwnd()))); if (!m_bEnabled) return FALSE; //Make sure we avoid conflict with other messages ASSERT(uCallbackMessage >= WM_USER); //Tray only supports tooltip text up to 64 characters ASSERT(_tcslen(szToolTip) <= 64); // load up the NOTIFYICONDATA structure m_tnd.cbSize = sizeof(NOTIFYICONDATA); m_tnd.hWnd = pWnd->GetSafeHwnd(); m_tnd.uID = uID; m_tnd.hIcon = icon; m_tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; m_tnd.uCallbackMessage = uCallbackMessage; strcpy (m_tnd.szTip, szToolTip); // Set the tray icon m_pFrame = (CFrameWnd*)pWnd; VERIFY(m_bEnabled = Shell_NotifyIcon(NIM_ADD, &m_tnd)); return m_bEnabled;}CSystemTray::~CSystemTray(){ RemoveIcon();}/////////////////////////////////////////////////////////////////////////////// CSystemTray icon manipulationvoid CSystemTray::MoveToRight(){ HideIcon(); ShowIcon();}void CSystemTray::RemoveIcon(){ if (!m_bEnabled) return; m_tnd.uFlags = 0; Shell_NotifyIcon(NIM_DELETE, &m_tnd); m_bEnabled = FALSE;}void CSystemTray::HideIcon(){ if (m_bEnabled && !m_bHidden) { m_tnd.uFlags = NIF_ICON; Shell_NotifyIcon (NIM_DELETE, &m_tnd); m_bHidden = TRUE; }}void CSystemTray::ShowIcon(){ if (m_bEnabled && m_bHidden) { m_tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; Shell_NotifyIcon(NIM_ADD, &m_tnd); m_bHidden = FALSE; }}BOOL CSystemTray::SetIcon(HICON hIcon){ if (!m_bEnabled) return FALSE; m_tnd.uFlags = NIF_ICON; m_tnd.hIcon = hIcon; return Shell_NotifyIcon(NIM_MODIFY, &m_tnd);}BOOL CSystemTray::SetIcon(LPCTSTR lpszIconName){ HICON hIcon = AfxGetApp()->LoadIcon(lpszIconName); return SetIcon(hIcon);}BOOL CSystemTray::SetIcon(UINT nIDResource){ HICON hIcon = AfxGetApp()->LoadIcon(nIDResource); return SetIcon(hIcon);}BOOL CSystemTray::SetStandardIcon(LPCTSTR lpIconName){ HICON hIcon = LoadIcon(NULL, lpIconName); return SetIcon(hIcon);}BOOL CSystemTray::SetStandardIcon(UINT nIDResource){ HICON hIcon = ::LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(nIDResource)); return SetIcon(hIcon);} HICON CSystemTray::GetIcon() const{ HICON hIcon = NULL; if (m_bEnabled) hIcon = m_tnd.hIcon; return hIcon;}/////////////////////////////////////////////////////////////////////////////// CSystemTray tooltip text manipulationBOOL CSystemTray::SetTooltipText(LPCTSTR pszTip){ if (!m_bEnabled) return FALSE; m_tnd.uFlags = NIF_TIP; _tcscpy(m_tnd.szTip, pszTip); return Shell_NotifyIcon(NIM_MODIFY, &m_tnd);}BOOL CSystemTray::SetTooltipText(UINT nID){ CString strText; VERIFY(strText.LoadString(nID)); return SetTooltipText(strText);}CString CSystemTray::GetTooltipText() const{ CString strText; if (m_bEnabled) strText = m_tnd.szTip; return strText;}/////////////////////////////////////////////////////////////////////////////// CSystemTray notification window stuffBOOL CSystemTray::SetNotificationWnd(CWnd* pWnd){ if (!m_bEnabled) return FALSE; //Make sure Notification window is valid ASSERT(pWnd && ::IsWindow(pWnd->GetSafeHwnd())); m_tnd.hWnd = pWnd->GetSafeHwnd(); m_tnd.uFlags = 0; return Shell_NotifyIcon(NIM_MODIFY, &m_tnd);}CWnd* CSystemTray::GetNotificationWnd() const{ return CWnd::FromHandle(m_tnd.hWnd);}/////////////////////////////////////////////////////////////////////////////// CSystemTray implentation of OnTrayNotification 到哪里找到 emmintrin.h?? 请各位帮我看看这个错误怎么改,我是新手! 菜鸟级问题,请各位朋友帮忙 100分求助,关于SDK界面编程的 谁有SDK写的发邮件得类 Some fucking problems of my MFCDialog interface! 关于SQL的远程连接问题 屏幕坐标,客户区坐标,物理坐标,逻辑坐标是怎样区分的?????????????????? 在VC中如何修改中断 请懂C语言的高手帮忙看看,先谢了 服务端提供文件下载功能。 当两上以上的用户下载不同的文件时不出错,但当两上以上的用户同时下载,同一文件时就出错。有什么解决方法? 封装ADO对象遇到的小问题
#ifndef _INCLUDED_SYSTEMTRAY_H_
#define _INCLUDED_SYSTEMTRAY_H_/////////////////////////////////////////////////////////////////////////////
// CSystemTray windowclass CSystemTray : public CObject
{
// Construction/destruction
public:
CSystemTray();
CSystemTray(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID);
virtual ~CSystemTray();// Operations
public:
CFrameWnd * m_pFrame;
BOOL Enabled() { return m_bEnabled; }
BOOL Visible() { return !m_bHidden; } //Create the tray icon
Create(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID); //Change or retrieve the Tooltip text
BOOL SetTooltipText(LPCTSTR pszTooltipText);
BOOL SetTooltipText(UINT nID);
CString GetTooltipText() const; //Change or retrieve the icon displayed
BOOL SetIcon(HICON hIcon);
BOOL SetIcon(LPCTSTR lpIconName);
BOOL SetIcon(UINT nIDResource);
BOOL SetStandardIcon(LPCTSTR lpIconName);
BOOL SetStandardIcon(UINT nIDResource);
HICON GetIcon() const;
void HideIcon();
void ShowIcon();
void RemoveIcon();
void MoveToRight(); //Change or retrieve the window to send notification messages to
BOOL SetNotificationWnd(CWnd* pNotifyWnd);
CWnd* GetNotificationWnd() const; //Default handler for tray notification message// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSystemTray)
//}}AFX_VIRTUAL// Implementation
protected:
BOOL m_bEnabled; // does O/S support tray icon?
BOOL m_bHidden; // Has the icon been hidden?
NOTIFYICONDATA m_tnd; DECLARE_DYNAMIC(CSystemTray)
};
#endif#include "stdafx.h"
#include "SystemTray.h"
//#include "MenuEx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endifIMPLEMENT_DYNAMIC(CSystemTray, CObject)/////////////////////////////////////////////////////////////////////////////
// CSystemTray construction/creation/destructionCSystemTray::CSystemTray()
{
memset(&m_tnd, 0, sizeof(m_tnd));
m_bEnabled = FALSE;
m_bHidden = FALSE;
}CSystemTray::CSystemTray(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szToolTip,
HICON icon, UINT uID)
{
Create(pWnd, uCallbackMessage, szToolTip, icon, uID);
m_bHidden = FALSE;
}BOOL CSystemTray::Create(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szToolTip,
HICON icon, UINT uID)
{
// this is only for Windows 95 (or higher)
VERIFY(m_bEnabled = ( GetVersion() & 0xff ) >= 4);
if (!m_bEnabled) return FALSE; //Make sure Notification window is valid
VERIFY(m_bEnabled = (pWnd && ::IsWindow(pWnd->GetSafeHwnd())));
if (!m_bEnabled) return FALSE;
//Make sure we avoid conflict with other messages
ASSERT(uCallbackMessage >= WM_USER); //Tray only supports tooltip text up to 64 characters
ASSERT(_tcslen(szToolTip) <= 64); // load up the NOTIFYICONDATA structure
m_tnd.cbSize = sizeof(NOTIFYICONDATA);
m_tnd.hWnd = pWnd->GetSafeHwnd();
m_tnd.uID = uID;
m_tnd.hIcon = icon;
m_tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
m_tnd.uCallbackMessage = uCallbackMessage;
strcpy (m_tnd.szTip, szToolTip); // Set the tray icon
m_pFrame = (CFrameWnd*)pWnd;
VERIFY(m_bEnabled = Shell_NotifyIcon(NIM_ADD, &m_tnd));
return m_bEnabled;
}CSystemTray::~CSystemTray()
{
RemoveIcon();
}
/////////////////////////////////////////////////////////////////////////////
// CSystemTray icon manipulationvoid CSystemTray::MoveToRight()
{
HideIcon();
ShowIcon();
}void CSystemTray::RemoveIcon()
{
if (!m_bEnabled) return; m_tnd.uFlags = 0;
Shell_NotifyIcon(NIM_DELETE, &m_tnd);
m_bEnabled = FALSE;
}void CSystemTray::HideIcon()
{
if (m_bEnabled && !m_bHidden) {
m_tnd.uFlags = NIF_ICON;
Shell_NotifyIcon (NIM_DELETE, &m_tnd);
m_bHidden = TRUE;
}
}void CSystemTray::ShowIcon()
{
if (m_bEnabled && m_bHidden) {
m_tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
Shell_NotifyIcon(NIM_ADD, &m_tnd);
m_bHidden = FALSE;
}
}BOOL CSystemTray::SetIcon(HICON hIcon)
{
if (!m_bEnabled) return FALSE; m_tnd.uFlags = NIF_ICON;
m_tnd.hIcon = hIcon; return Shell_NotifyIcon(NIM_MODIFY, &m_tnd);
}BOOL CSystemTray::SetIcon(LPCTSTR lpszIconName)
{
HICON hIcon = AfxGetApp()->LoadIcon(lpszIconName); return SetIcon(hIcon);
}BOOL CSystemTray::SetIcon(UINT nIDResource)
{
HICON hIcon = AfxGetApp()->LoadIcon(nIDResource); return SetIcon(hIcon);
}BOOL CSystemTray::SetStandardIcon(LPCTSTR lpIconName)
{
HICON hIcon = LoadIcon(NULL, lpIconName); return SetIcon(hIcon);
}BOOL CSystemTray::SetStandardIcon(UINT nIDResource)
{
HICON hIcon = ::LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(nIDResource)); return SetIcon(hIcon);
}
HICON CSystemTray::GetIcon() const
{
HICON hIcon = NULL;
if (m_bEnabled)
hIcon = m_tnd.hIcon; return hIcon;
}/////////////////////////////////////////////////////////////////////////////
// CSystemTray tooltip text manipulationBOOL CSystemTray::SetTooltipText(LPCTSTR pszTip)
{
if (!m_bEnabled) return FALSE; m_tnd.uFlags = NIF_TIP;
_tcscpy(m_tnd.szTip, pszTip); return Shell_NotifyIcon(NIM_MODIFY, &m_tnd);
}BOOL CSystemTray::SetTooltipText(UINT nID)
{
CString strText;
VERIFY(strText.LoadString(nID)); return SetTooltipText(strText);
}CString CSystemTray::GetTooltipText() const
{
CString strText;
if (m_bEnabled)
strText = m_tnd.szTip; return strText;
}/////////////////////////////////////////////////////////////////////////////
// CSystemTray notification window stuffBOOL CSystemTray::SetNotificationWnd(CWnd* pWnd)
{
if (!m_bEnabled) return FALSE; //Make sure Notification window is valid
ASSERT(pWnd && ::IsWindow(pWnd->GetSafeHwnd())); m_tnd.hWnd = pWnd->GetSafeHwnd();
m_tnd.uFlags = 0; return Shell_NotifyIcon(NIM_MODIFY, &m_tnd);
}CWnd* CSystemTray::GetNotificationWnd() const
{
return CWnd::FromHandle(m_tnd.hWnd);
}/////////////////////////////////////////////////////////////////////////////
// CSystemTray implentation of OnTrayNotification