Make shell applet popup messages for fatal errors

This commit is contained in:
Ron Pedde 2007-02-06 04:32:16 +00:00
parent ec9ab04b40
commit d8187985e8
2 changed files with 72 additions and 41 deletions

View File

@ -19,6 +19,13 @@
#include "NotifyIcon.h" #include "NotifyIcon.h"
#include "FireflyShell.h" #include "FireflyShell.h"
CNotifyMsg::CNotifyMsg(UINT32 id, UINT32 intval, const CString &strval) {
this->id = id;
this->intval = intval;
this->strval = strval;
}
CNotifyIcon::CNotifyIcon() CNotifyIcon::CNotifyIcon()
{ {
ZeroMemory(&m_nid, sizeof(NOTIFYICONDATA)); ZeroMemory(&m_nid, sizeof(NOTIFYICONDATA));
@ -79,20 +86,21 @@ void CNotifyIcon::OnClose()
GetApplication()->Exit(); GetApplication()->Exit();
} }
void CNotifyIcon::PopupBalloon(UINT title_id, UINT text_id, DWORD flags) void CNotifyIcon::PopupBalloon(CString &title, CString &text, DWORD flags) {
{ m_nid.uFlags |= NIF_INFO;
SafeStringCopy(m_nid.szInfoTitle, title, 64);
SafeStringCopy(m_nid.szInfo,text, 256);
m_nid.dwInfoFlags = flags;
m_nid.uTimeout = 10000;
Shell_NotifyIcon(NIM_MODIFY, &m_nid);
}
void CNotifyIcon::PopupBalloon(UINT title_id, UINT text_id, DWORD flags) {
CString title, text; CString title, text;
title.LoadString(title_id); title.LoadString(title_id);
text.LoadString(text_id); text.LoadString(text_id);
m_nid.uFlags |= NIF_INFO; PopupBalloon(title, text, flags);
SafeStringCopy(m_nid.szInfoTitle, title, 64);
SafeStringCopy(m_nid.szInfo, text, 256);
m_nid.dwInfoFlags = flags;
m_nid.uTimeout = 10000;
Shell_NotifyIcon(NIM_MODIFY, &m_nid);
} }
void CNotifyIcon::Update() void CNotifyIcon::Update()
@ -205,17 +213,16 @@ LRESULT CNotifyIcon::OnRegisteredActivation(UINT, WPARAM, LPARAM, BOOL &bHandled
return m_registered_activation_message; return m_registered_activation_message;
} }
void CNotifyIcon::OnServerEvent(UINT32 id, UINT32 intval, const CString &strval) void CNotifyIcon::OnServerEvent(UINT32 id, UINT32 intval, const CString &strval) {
{
// Note that we're running on a different thread here. We need to punt // Note that we're running on a different thread here. We need to punt
// the event over to the main thread using SendMessage. // the event over to the main thread using SendMessage.
switch (id) CNotifyMsg *pMsgNew = new CNotifyMsg(id, intval,strval);
{
switch (id) {
case 0: case 0:
break;
case 1: case 1:
case 2: case 2:
SendMessage(WM_SERVEREVENT, id); SendMessage(WM_SERVEREVENT, id, (LPARAM) pMsgNew);
break; break;
default: default:
ATLASSERT(false); ATLASSERT(false);
@ -223,11 +230,21 @@ void CNotifyIcon::OnServerEvent(UINT32 id, UINT32 intval, const CString &strval)
} }
} }
LRESULT CNotifyIcon::OnServerEvent(UINT, WPARAM wparam, LPARAM, BOOL &bHandled) LRESULT CNotifyIcon::OnServerEvent(UINT, WPARAM wparam, LPARAM lparam, BOOL &bHandled) {
{ CNotifyMsg *pMsgNotify = (CNotifyMsg *)lparam;
bHandled = true; bHandled = true;
switch (wparam) CString title;
{
title.LoadString(IDR_MAINFRAME);
// CString title, text;
// title.LoadString(title_id);
switch (wparam) {
case 0:
if(pMsgNotify->GetIntval() == 0)
PopupBalloon(title,pMsgNotify->GetStrval());
break;
case 1: case 1:
PopupBalloon(IDR_MAINFRAME, IDS_SCAN_START); PopupBalloon(IDR_MAINFRAME, IDS_SCAN_START);
break; break;
@ -235,6 +252,7 @@ LRESULT CNotifyIcon::OnServerEvent(UINT, WPARAM wparam, LPARAM, BOOL &bHandled)
PopupBalloon(IDR_MAINFRAME, IDS_SCAN_STOP); PopupBalloon(IDR_MAINFRAME, IDS_SCAN_STOP);
break; break;
} }
delete(pMsgNotify);
return 0; return 0;
} }

View File

@ -20,6 +20,18 @@
#include "ServiceControl.h" #include "ServiceControl.h"
#include "ServerEvents.h" #include "ServerEvents.h"
class CNotifyMsg {
UINT32 id;
UINT32 intval;
CString strval;
public:
CNotifyMsg(UINT32 id, UINT32 intval, const CString &strval);
CString &GetStrval(void) { return strval; };
UINT32 GetIntval(void) { return intval; };
};
class CNotifyIcon class CNotifyIcon
: public CWindowImpl<CNotifyIcon>, : public CWindowImpl<CNotifyIcon>,
public ServiceStatusObserver, public ServiceStatusObserver,
@ -60,6 +72,7 @@ class CNotifyIcon
void OnClose(); void OnClose();
void PopupBalloon(UINT title_id, UINT text_id, DWORD flags = NIIF_INFO); void PopupBalloon(UINT title_id, UINT text_id, DWORD flags = NIIF_INFO);
void PopupBalloon(CString &title, CString &text, DWORD flags = NIIF_INFO);
void InflictIconState(); void InflictIconState();
void Update(); void Update();