呵呵,用BHO啊!!!
void CBhoWorker::DoWork(BOOL bForceDo)
{
HRESULT hr = NULL;
// get Doc
CComPtr<IDispatch> spDocDisp;  m_spWebBrowser2->get_Document(&spDocDisp);
CComPtr<IHTMLDocument2> spDoc; spDocDisp->QueryInterface(IID_IHTMLDocument2,(void**)&spDoc); if(spDoc == NULL) return;

CComPtr<IHTMLElementCollection> spAll; spDoc->get_all(&spAll); if(spAll == NULL) return;
_variant_t vName;
_variant_t vIndex; for (int n=0; n<m_nParams; n++)
{
if( m_strUrl.Find(m_pParam[n].m_strUrl) == -1)
continue; int nIdx = 0; sscanf(LPCTSTR(m_pParam[n].m_strIdx),"%d",&nIdx);
vIndex= long(nIdx); int nName = 0;
if (sscanf(LPCTSTR(m_pParam[n].m_strName),"%d",&nName)!=1)
vName = LPCTSTR(m_pParam[n].m_strName);
else
{
vName = long(nName);
vIndex= 0l;
} //item
CComPtr<IDispatch> spItemDisp;
spAll->item(vName,vIndex,&spItemDisp);
if (spItemDisp == NULL)
{
for(long lIndex=0l; ; lIndex++)
{
vName = lIndex;
vIndex= 0l;
spItemDisp = NULL;
spAll->item(vName,vIndex,&spItemDisp); if (spItemDisp == NULL) return;
CComPtr<IHTMLElement> spElment;
spItemDisp->QueryInterface(IID_IHTMLElement,(void**)&spElment);

BSTR bsTextIn;
spElment->get_innerText(&bsTextIn);
_bstr_t bstrTextIn(bsTextIn,FALSE);
CString strTextIn = LPCTSTR(bstrTextIn);

BSTR bsTextTag;
spElment->get_tagName(&bsTextTag);
_bstr_t bstrTextTag(bsTextTag,FALSE);
CString strTextTag = LPCTSTR(bstrTextTag);
if (m_pParam[n].m_strInText == strTextIn &&
m_pParam[n].m_strTag    == strTextTag)
break;
}
}
CComPtr<IHTMLElement> spElment;
spItemDisp->QueryInterface(IID_IHTMLElement,(void**)&spElment);

if (m_pParam[n].m_strIF == "IID_IHTMLElement")
{
if(m_pParam[n].m_strFN == "CLICK")
{
hr = spElment->click();
}
if (m_pParam[n].m_strFN == "REFRESH")
{
m_spWebBrowser2->Refresh();
}
if (m_pParam[n].m_strFN == "REGO")
{
_bstr_t bstsUrl = LPCTSTR(m_strUrl);
m_spWebBrowser2->Navigate(bstsUrl,NULL,NULL,NULL,NULL);
}
if (m_pParam[n].m_strFN == "BACK")
{
m_spWebBrowser2->GoBack();
}
if (m_pParam[n].m_strFN == "GO")
{
_bstr_t bstsUrl = LPCTSTR(m_pParam[n].m_strP1);
m_spWebBrowser2->Navigate(bstsUrl,NULL,NULL,NULL,NULL);
}
if (m_pParam[n].m_strFN == "SLEEP")
{
int nSecend = 3;
sscanf(LPCTSTR(m_pParam[n].m_strP1),"%d", &nSecend);
Sleep(nSecend*1000);
}
Logging(m_pParam[n].m_strP3);
continue;
}
BSTR bsTextTag;
spElment->get_tagName(&bsTextTag);
_bstr_t bstrTextTag(bsTextTag,FALSE);
//tag
CString strTextTag = LPCTSTR(bstrTextTag);
if (strTextTag != m_pParam[n].m_strTag)
return;// BSTR bsTextIn;
// spElment->get_innerText(&bsTextIn);
// _bstr_t bstrTextIn(bsTextIn,FALSE);
// CString strTextIn = LPCTSTR(bstrTextIn);
// if (strTextIn != m_pParam[n].m_strInText)
// return; //interface
Logging(m_pParam[n].m_strP3);
if (m_pParam[n].m_strIF == "IID_IHTMLTextAreaElement")
{
CComPtr<IHTMLTextAreaElement> spTextArea;
spElment->QueryInterface(IID_IHTMLTextAreaElement,(void**)&spTextArea); if(spTextArea == NULL) return ;
_bstr_t bstrText = LPCTSTR(m_pParam[n].m_strP1);
hr = spTextArea->put_value(bstrText);
}
if (m_pParam[n].m_strIF == "IID_IHTMLFormElement")
{
CComPtr<IHTMLFormElement> spForm; spItemDisp->QueryInterface(IID_IHTMLFormElement,(void**)&spForm); if (spForm == NULL) return;
hr = spForm->submit();
}
if (m_pParam[n].m_strIF == "IHTMLInputTextElement")
{
CTime tim = CTime::GetCurrentTime();
CString strText = m_pParam[n].m_strP1;
CString strTextF;

//Text or File
if (m_pParam[n].m_strP2.Find("TEXT") != -1)
{
int nK;
if (scanf(m_pParam[n].m_strP2,"TEXT(%dK)",&nK) == 1)
{
while(1)
{
if (strTextF.GetLength() + strText.GetLength() > nK*1024)
break;
strTextF += strText;
}
}
else
strTextF = strText;
}
else if(m_pParam[n].m_strP2.Find("FILE") != -1)
{
CStdioFile fl;
if(!fl.Open(m_pParam[n].m_strP1, CFile::modeRead|CFile::typeText))
return; CString strCount;
fl.ReadString(strCount);
int nLine = 0;
sscanf(LPCTSTR(strCount),"%d", &nLine); CString strBlank;
for (int n=0; n<nLine; n++)
{
fl.ReadString(strBlank);
if (strTextF.GetLength() + strBlank.GetLength() > 60*1024)
break;
strTextF += strBlank;
}
}
else
strTextF = strText;
if (m_pParam[n].m_strP3 == "NOSAME")
strText.Format("%s%02d%02d",strTextF,tim.GetMinute(),tim.GetSecond()); CComPtr<IHTMLInputTextElement> spInputText;
spItemDisp->QueryInterface(IID_IHTMLInputTextElement ,(void**)&spInputText); if(spInputText == NULL) return;
_bstr_t bstrValue = LPCTSTR(strText);
hr = spInputText->put_value(bstrValue);
}
}
}