//获取指定ID的 Input 控件的值,如输入框
BOOL CAnalyzeHtm::GetInputElementText(CString & str,const CString & id,CDHtmlDialog * dlg)
{
CComPtr<IHTMLInputElement> input = NULL;
if(dlg->GetElementInterface(id,&input) == S_OK && input)
{
CComBSTR temp;
if(input->get_value(&temp) == S_OK)
{
str = temp;
OutputDebugString(id + " " + str);//注释
return TRUE;
}
}
str.Empty();
return FALSE;
}
//获取指定ID的 checkbox 控件的 check 状态 返回 TRUE:checked FALSE:unchecked
BOOL CAnalyzeHtm::GetCheckElementState(const CString & id,CDHtmlDialog * dlg)
{
CComPtr<IHTMLInputElement> input = NULL;
if(dlg->GetElementInterface(id,&input) == S_OK && input)
{
VARIANT_BOOL value;
if(input->get_checked(&value) == S_OK)
//return value == VARIANT_TRUE;
{
if(value == VARIANT_TRUE) //注释
{
OutputDebugString(id + " checked");
return TRUE;
}
}
}
return FALSE;
}
//获取指定ID的text,<p><h><textArea>标签等
BOOL CAnalyzeHtm::GetElementText(CString & str,const CString & id,CDHtmlDialog * dlg)
{
CComPtr<IHTMLElement> sp = NULL;
if(dlg->GetElementInterface(id,&sp) == S_OK) //获取element
{
CComPtr<IHTMLDocument2> htmld = NULL;
if(sp && dlg->GetDHtmlDocument(&htmld) == S_OK) //获取document
{
CComBSTR temp;
if(sp->get_innerText(&temp) == S_OK)
{
str = temp; //BSTR转CString
OutputDebugString(id + " " + str);//注释
return TRUE;
}
}
}
str.Empty();
return FALSE;
}
CDHtmlDialog获取控件内容
最新推荐文章于 2022-04-19 17:57:01 发布
本文介绍了通过COM接口从HTML元素中获取文本值的方法,包括输入框、复选框及普通文本标签等,并展示了如何判断复选框的状态。

349

被折叠的 条评论
为什么被折叠?



