Listing 4
class WinEvent;
class WinEventSource : public EventSource <WinEvent>
{
public:
WinEventSource() {};
~WinEventSource() {};
};
class WinEvent : public Event <WinEventSource>
{
public:
explicit WinEvent(HACCEL h):m_haccel(h)
{setRestore(true);activateEvent();}
void eventProcess(); bool eventTrigged();
bool activateEvent() {theEventSource.addEvent(this); return true;}
void deactivateEvent() {};
~WinEvent (){};
private:
MSG m_msg;
HACCEL m_haccel;
};
WinEventSource Event<WinEventSource>::theEventSource;
bool WinEvent::eventTrigged()
{ if (PeekMessage (&m_msg, NULL, 0, 0, PM_REMOVE))
return true;
else return false;
}
void WinEvent::eventProcess()
{ if (!TranslateAccelerator(m_msg.hwnd, m_haccel, &m_msg))
{ TranslateMessage( &m_msg );
DispatchMessage( &m_msg );
}
activateEvent(); //always restore
}