// 웹 페이지 <form 태그의 input 태그 값 채우기
bool CMyInternetExplorer::FindInput (bool bClick, bool bSelect,
bool bChangeValue, bool bSetCheck,
bool bType, bool bName, bool bValue,
LPCTSTR sTypeToLook, LPCTSTR sNameToLook,
LPCTSTR sValueToLook,
bool bNewCheckValue, LPCTSTR sNewValue)
{
ASSERT (m_pWebBrowser != NULL);
if (m_pWebBrowser == NULL)
return false;
HRESULT hr;
IDispatch* pHtmlDocDispatch = NULL;
IHTMLDocument2 * pHtmlDoc = NULL;
bool bSearch = true;
// Retrieve the document object.
hr = m_pWebBrowser->get_Document (&pHtmlDocDispatch);
if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
{
hr = pHtmlDocDispatch->QueryInterface
(IID_IHTMLDocument2, (void**)&pHtmlDoc);
if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
{
IHTMLElementCollection* pColl = NULL;
hr = pHtmlDoc->get_all (&pColl);
if (SUCCEEDED (hr) && (pColl != NULL))
{
// Obtained the Anchor Collection...
long nLength = 0;
pColl->get_length (&nLength);
for (int i = 0; i < nLength && bSearch; i++)
{
COleVariant vIdx ((long)i, VT_I4);
IDispatch* pElemDispatch = NULL;
IHTMLElement * pElem = NULL;
hr = pColl->item (vIdx, vIdx, &pElemDispatch);
if (SUCCEEDED (hr) && (pElemDispatch != NULL))
{
hr = pElemDispatch->QueryInterface
(IID_IHTMLElement, (void**)&pElem);
if (SUCCEEDED (hr) && (pElem != NULL))
{
BSTR bstrTagName;
CString sTempTagName;
if (!FAILED (pElem->get_tagName
(&bstrTagName)))
{
sTempTagName = bstrTagName;
sTempTagName.MakeLower ();
//AfxMessageBox (sTempTagName);
SysFreeString (bstrTagName);
}
if (sTempTagName == _T ("input"))
{
IHTMLInputElement * pInputElem = NULL;
hr = pElemDispatch->QueryInterface
(IID_IHTMLInputElement,
(void**)&pInputElem);
if (SUCCEEDED (hr) &&
(pInputElem != NULL))
{
BSTR bstrType, bstrName, bstrValue;
CString sTempType,
sTempName, sTempValue;
if (!FAILED
(pInputElem->get_type
(&bstrType)))
{
sTempType = bstrType;
SysFreeString (bstrType);
}
if (!FAILED (pInputElem->get_name
(&bstrName)))
{
sTempName = bstrName;
SysFreeString (bstrName);
}
if (!FAILED
(pInputElem->get_value
(&bstrValue)))
{
sTempValue = bstrValue;
SysFreeString (bstrValue);
}
// Do the comparison here!
bool bMatches = true;
if (bMatches && bType)
{
if
(!StringHelper::WildcardCompareNoCase
(sTypeToLook, sTempType))
bMatches = false;
}
if (bMatches && bName)
{
if
(!StringHelper::WildcardCompareNoCase
(sNameToLook, sTempName))
bMatches = false;
}
if (bMatches && bValue)
{
if
(!StringHelper::WildcardCompareNoCase
(sValueToLook, sTempValue))
bMatches = false;
}
if (bMatches)
{
// No need to search more!
bSearch = false;
if (bSetCheck)
{
if (bNewCheckValue)
pInputElem->put_checked
(VARIANT_TRUE);
else
pInputElem->put_checked
(VARIANT_FALSE);
}
if (bChangeValue)
{
CString sTemp (sNewValue);
BSTR bstrNewValue =
sTemp.AllocSysString ();
pInputElem->put_value
(bstrNewValue);
SysFreeString
(bstrNewValue);
}
if (bSelect)
pInputElem->select ();
if (bClick)
pElem->click ();
}
pInputElem->Release ();
}
}
pElem->Release ();
}
pElemDispatch->Release ();
}
}
pColl->Release ();
}
pHtmlDoc->Release();
}
pHtmlDocDispatch->Release ();
}
if (bSearch == false)
return true;
return false;
}
반응형
'IT-개발,DB' 카테고리의 다른 글
[개발/VC] 웹페이지 마우스 위치에 있는 엘리먼트 얻어오기 (0) | 2011.09.27 |
---|---|
[개발/MFC] 웹 페이지 <form 태그의 a 태그 anchor 값 찾기 (0) | 2011.09.27 |
[개발/VC] 인터넷 연결체크 (0) | 2011.09.27 |
[개발/MFC] 새 브라우저 생성 (0) | 2011.09.27 |
[IT/윈도우즈] 시작프로그램에 등록된 프로그램이 실행되지 않는 문제의 해결 (0) | 2011.09.23 |
댓글