Unhandled DHTML events don't bubble to base CDHtmlDialog class
Hello,
I am having difficulty handling DHTML events in a common base class. I am
deriving from CDHtmlDialog:
class CCommonDHtmlDialog : public CDHtmlDialog
{
}
and
class CMainDHtmlDialog : public CCommonDHtmlDialog
{
}
I want to put common event handlers into CCommonDHtmlDialog so all classes
derived from it don't have to have the event handler code duplicated. But
this doesn't seem possible for DHTML_EVENT handlers because the map is
declared like this:
BEGIN_DHTML_EVENT_MAP(CCommonDHtmlDialog)
...
END_DHTML_EVENT_MAP()
As opposed to a normal Windows message map:
BEGIN_MESSAGE_MAP(CCommonDHtmlDialog, CDHtmlDialog)
...
END_MESSAGE_MAP()
The base class (CDHtmlDialog) is specified in the Windows message map but
not in the DHTML event map! This means that DHTML events don't seem to have
a way to bubble to the base class, like Windows messages do. The symptom is
if I handle a DHTML event in CComonDHtmlDialog, it does not take effect in
my CMainDHtmlDialog, because the event is not bubbled from DMainDHtmlDialog
to its base class CCommonDHtmlDialog.
My workaround is to declare entries in the map of CMainDHtmlDialog:
BEGIN_DHTML_EVENT_MAP(CMainDHtmlDialog)
DHTML_EVENT_TAG(DISPID_HTMLELEMENTEVENTS_ONMOUSEDOWN, _T("body"),
OnHtmlMouseDown)
END_DHTML_EVENT_MAP()
and manually forward them to CCommonDHtmlDialog:
HRESULT CMainDHtmlDialog::OnHtmlMouseDown(IHTMLElement* pElement)
{
return CCommonDHtmlDialog::OnHtmlMouseDown(pElement);
}
This way, at least the handler code is placed in a base class. But it's a
pain to have to put event handlers in every derived class. Does anyone else
have this problem, and did you find a workaround?
Thanks,
David