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;
CString title, text; SafeStringCopy(m_nid.szInfoTitle, title, 64);
title.LoadString(title_id); SafeStringCopy(m_nid.szInfo,text, 256);
text.LoadString(text_id); m_nid.dwInfoFlags = flags;
m_nid.uTimeout = 10000;
Shell_NotifyIcon(NIM_MODIFY, &m_nid);
}
m_nid.uFlags |= NIF_INFO; void CNotifyIcon::PopupBalloon(UINT title_id, UINT text_id, DWORD flags) {
CString title, text;
title.LoadString(title_id);
text.LoadString(text_id);
SafeStringCopy(m_nid.szInfoTitle, title, 64); PopupBalloon(title, text, flags);
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,37 +213,47 @@ 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. CNotifyMsg *pMsgNew = new CNotifyMsg(id, intval,strval);
switch (id)
{ switch (id) {
case 0: case 0:
break; case 1:
case 1: case 2:
case 2: SendMessage(WM_SERVEREVENT, id, (LPARAM) pMsgNew);
SendMessage(WM_SERVEREVENT, id); break;
break; default:
default: ATLASSERT(false);
ATLASSERT(false); break;
break; }
}
} }
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;
{
case 1: title.LoadString(IDR_MAINFRAME);
PopupBalloon(IDR_MAINFRAME, IDS_SCAN_START);
break; // CString title, text;
case 2: // title.LoadString(title_id);
PopupBalloon(IDR_MAINFRAME, IDS_SCAN_STOP);
break; switch (wparam) {
} case 0:
return 0; if(pMsgNotify->GetIntval() == 0)
PopupBalloon(title,pMsgNotify->GetStrval());
break;
case 1:
PopupBalloon(IDR_MAINFRAME, IDS_SCAN_START);
break;
case 2:
PopupBalloon(IDR_MAINFRAME, IDS_SCAN_STOP);
break;
}
delete(pMsgNotify);
return 0;
} }
void CNotifyIcon::EnableUserSwitchNotifications() void CNotifyIcon::EnableUserSwitchNotifications()

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();