Basically I want to develop a BHO that validates certain fields on a form and auto-places disposable e-mails in the appropriate fields (more for my own knowledge). So in the DOCUMENTCOMPLETE event I have this:
for(long i = 0; i < *len; i++)
{
VARIANT* name = new VARIANT();
name->vt = VT_I4;
name->intVal = i;
VARIANT* id = new VARIANT();
id->vt = VT_I4;
id->intVal = 0;
IDispatch* disp = 0;
IHTMLFormElement* form = 0;
HRESULT r = forms->item(*name,*id,&disp);
if(S_OK != r)
{
MessageBox(0,L"Failed to get form dispatch",L"",0);// debug only
continue;
}
disp->QueryInterface(IID_IHTMLFormElement2,(void**)&form);
if(form == 0)
{
MessageBox(0,L"Failed to get form element from dispatch",L"",0);// debug only
continue;
}
// Code to listen for onsubmit events here...
}
How would I use the IHTMLFormElement interface to listen for the onsubmit event?
Once you have the pointer to the element you want to sink events for, you would
QueryInterface()it forIConnectionPointContainerand then connect to that:Some notes:
dwCookieandcpc, since you need them later when you callpcp->Unadvise()to disconnect the sink.pcp->Advise()above, I pass this. You can use any object you have that implementsIDispatch, which may or may not be this object. Design left to you.riidwill be the event dispinterface you want to sink. In this case, you probably wantDIID_HTMLFormElementEvents2.Here’s how to disconnect:
Let me know if you have further questions.
Edit-1:
Yeah, that DIID was wrong. It should be:
DIID_HTMLFormElementEvents2.Here is how I found it: