Windows Messages
Implementing the WM_PAINT message by using the CWinEvent class shows how the WM_PAINT message is implemented using the CWinEvent class. First, an interface is derived from IWinEvent that defines a method for cracking the WM_PAINT message.
Implementing the WM_PAINT message by using the CWinEvent class
class __declspec(uuid("8A6AF181-40A7-11d3-AF0D-006008AFE059"))
IWindowPaintEvent : public IWinEvent
{
public:
virtual HDC GetDC() const = 0;
};
Next, the class
Deriving CWindowPaintEvent from the CWinEventBase class
class CWindowPaintEvent : public CWinEventBase<IWindowPaintEvent,
&IID_IWindowPaintEvent>
{
…
virtual bool Dispatch(IQueryGuid* pIListener);
virtual HDC GetDC() const;
…
};
bool CWindowPaintEvent::Dispatch(IQueryGuid* pIListener)
{
bool bHandled = false;
IWindowListener* pIWindowListener =
guid_cast<IWindowListener*>(pIListener);
if (pIWindowListener != NULL)
{
bHandled = pIWindowListener->OnPaint(GetDC());
pIWindowListener->Release();
}
return bHandled;
}
HDC CWindowPaintEvent::GetDC() const
{
return (HDC) GetWParam();
}