BHO onsubmit 이벤트
-
07-07-2019 - |
문제
기본적으로 나는 적절한 필드 (내 자신의 지식에 대한 자세한 내용)에서 양식의 특정 필드를 검증하고 자동 전달 일회용 전자 메일을 검증하는 BHO를 개발하고 싶습니다. 그래서 DocumentComplete 이벤트에서는 다음과 같습니다.
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...
}
ihtmlformelement 인터페이스를 사용하여 OnSubmit 이벤트를 듣는 방법은 무엇입니까?
해결책
이벤트를 싱크하려는 요소에 대한 포인터가 있으면 QueryInterface()
그것을 위해 IConnectionPointContainer
그런 다음 연결하십시오.
REFIID riid = DIID_HTMLFormElementEvents2;
CComPtr<IConnectionPointContainer> spcpc;
HRESULT hr = form->QueryInterface(IID_IConnectionPointContainer, (void**)&spcpc);
if (SUCCEEDED(hr))
{
CComPtr<IConnectionPoint> spcp;
hr = spcpc->FindConnectionPoint(riid, &spcp);
if (SUCCEEDED(hr))
{
DWORD dwCookie;
hr = pcp->Advise((IDispatch *)this, &dwCookie);
}
}
몇 가지 메모 :
- 캐시를 원할 것입니다
dwCookie
그리고cpc
, 나중에 전화 할 때 필요하기 때문에pcp->Unadvise()
싱크를 분리합니다. - 전화에서
pcp->Advise()
위, 나는 이것을 통과한다. 해당 도구가있는 객체를 사용할 수 있습니다IDispatch
, 이 개체 일 수도 있고 아닐 수도 있습니다. 디자인이 당신에게 맡겨졌습니다. riid
당신이 침몰하려는 이벤트 dispinterface가 될 것입니다. 이 경우, 당신은 아마 원할 것입니다DIID_HTMLFormElementEvents2
.
연결을 끊는 방법은 다음과 같습니다.
pcp->Unadvise(dwCookie);
추가 질문이 있으면 알려주세요.
편집 1 :
그래, 그 디드는 틀렸다. 그것은해야한다: DIID_HTMLFormElementEvents2
.
내가 찾은 방법은 다음과 같습니다.
C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK>findstr /spin /c:"Events2" *.h | findstr /i /c:"form"
제휴하지 않습니다 StackOverflow