<td><textarea name="TxtDes" id="TxtDes" style="height:50px;width:300px;"></textarea></td>
并填充内容?
下面这段代码是用来判断网页中的<td><input name="TxtTitle" type="text" id="TxtTitle" style="width:200px;" /></td>的
MSHTML::IHTMLInputElementPtr pInput(disp);
if(pInput)
{
BSTR bstrtype;
pInput->get_type(&bstrtype);
//printf(_bstr_t(bstrtype));
if(StrCmpW(bstrtype,L"text")==0)
....}
用
if(StrCmpW(bstrtype,L"textarea")==0)
pInput->put_value(_bstr_t("这是描述栏"));试了不行。
分不够可以再加
比如要插入网址:http://lii.org/cs/lii/create/todo中的Short Description or Title *
和Comment下面的输入框。
58 个解决方案
#1
直接用CInterSession post不就行了吗
干嘛这么麻烦
干嘛这么麻烦
#2
http://topic.csdn.net/t/20050713/16/4142294.html#
这上面有获取FORM上的textarea的内容
但是我要填充。
是不是可以用判断
//-----------------------
IHTMLElement* pElement = (IHTMLElement* )hWnd;
HRESULT hr;
BSTR value;
IHTMLInputTextElement* pHTMLInputTextElement;
hr = pElement->QueryInterface(IID_IHTMLInputTextElement,
(void**)&pHTMLTextAreaElement);
再put-value
这上面有获取FORM上的textarea的内容
但是我要填充。
是不是可以用判断
//-----------------------
IHTMLElement* pElement = (IHTMLElement* )hWnd;
HRESULT hr;
BSTR value;
IHTMLInputTextElement* pHTMLInputTextElement;
hr = pElement->QueryInterface(IID_IHTMLInputTextElement,
(void**)&pHTMLTextAreaElement);
再put-value
#3
-------------
我是要集成到原来的程序里面
所以不想改动太大
具体该如何弄呢
#4
请高手帮忙
#5
加高分请高手帮忙
#6
用基本的字符串查找比较试试
#7
if(StrCmpW(bstrtype,L"textarea")==0)
pInput-> put_value(_bstr_t("这是描述栏"));试了不行。
pInput-> put_value(_bstr_t("这是描述栏"));试了不行。
#8
pInput->get_value 行吗?
#9
首先要判断<textarea > </textarea>
然后再填充
主要是判断
pInput-> get_value 行吗?-------不行,这是填充部份的
if(StrCmpW(bstrtype,L"textarea")==0)
pInput-> put_value(_bstr_t("这是在填充描述栏"));试了不行
然后再填充
主要是判断
pInput-> get_value 行吗?-------不行,这是填充部份的
if(StrCmpW(bstrtype,L"textarea")==0)
pInput-> put_value(_bstr_t("这是在填充描述栏"));试了不行
#10
应该是加上这句,下午慢慢调试了,高手都不出手呀
晕
IHTMLTextAreaElement* pHTMLTextAreaElement;
hr = pDispatch->QueryInterface(IID_IHTMLTextAreaElement,
(void**)&pHTMLTextAreaElement);
if (SUCCEEDED(hr))
{
pHTMLTextAreaElement->put_value(L"AAAAAAAAAAAAA");
}
晕
IHTMLTextAreaElement* pHTMLTextAreaElement;
hr = pDispatch->QueryInterface(IID_IHTMLTextAreaElement,
(void**)&pHTMLTextAreaElement);
if (SUCCEEDED(hr))
{
pHTMLTextAreaElement->put_value(L"AAAAAAAAAAAAA");
}
#11
textarea标签对应的元素不是IHTMLInputElementPtr,而是IHTMLTextAreaElementPtr,所以要用IHTMLTextAreaElementPtr::put_value
#12
具体要如何写呢
#13
这是普通textinput的填充代码?那textarea呢,如何写呢
if(StrCmpW(bstrtype,L"text")==0) {
MSHTML::IHTMLElementPtr e(pInput);
_variant_t val;
val=e->getAttribute(_bstr_t(L"id"),0);
if (wcscmp(val.bstrVal,L"name")==0){
pInput->put_value(_bstr_t(name));
#14
UP者有分
#15
首先得到标准元素 IHTMLElementPtr e;
然后:
_bstr_t tag;
e->get_tagName(&tag);
if (tag==_bstr_t("TEXTAREA"))
{
IHTMLTextAreaPtr ta = e;
ta->put_value(...);
}
然后:
_bstr_t tag;
e->get_tagName(&tag);
if (tag==_bstr_t("TEXTAREA"))
{
IHTMLTextAreaPtr ta = e;
ta->put_value(...);
}
#16
error C2664: 'get_tagName' : cannot convert parameter 1 from 'class _bstr_t *' to 'unsigned short ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
\mylist\mylistDlg.cpp(346) : error C2664: 'put_value' : cannot convert parameter 1 from 'char [15]' to 'unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
\mylist\mylistDlg.cpp(357) : error C2181: illegal else without matching if
\mylist\mylistDlg.cpp(376) : error C2181: illegal else without matching if
\mylist\debug\mshtml.tli(220) : error C2601: 'getAttribute' : local function definitions are illegal
\mylist\debug\mshtml.tli(12318) : error C2601: 'item' : local function definitions are illegal
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
\mylist\mylistDlg.cpp(346) : error C2664: 'put_value' : cannot convert parameter 1 from 'char [15]' to 'unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
\mylist\mylistDlg.cpp(357) : error C2181: illegal else without matching if
\mylist\mylistDlg.cpp(376) : error C2181: illegal else without matching if
\mylist\debug\mshtml.tli(220) : error C2601: 'getAttribute' : local function definitions are illegal
\mylist\debug\mshtml.tli(12318) : error C2601: 'item' : local function definitions are illegal
#17
_bstr_t tag;
e->get_tagName(&tag);
if (tag==_bstr_t("TEXTAREA"))
{
MSHTML::IHTMLTextAreaElementPtr ta = e;
ta->put_value("这是描述栏插入");
应该是很多未定义的出错
e->get_tagName(&tag);
if (tag==_bstr_t("TEXTAREA"))
{
MSHTML::IHTMLTextAreaElementPtr ta = e;
ta->put_value("这是描述栏插入");
应该是很多未定义的出错
#18
楼主考虑下用脚本吧
CString strjs;
strjs.Format("document.yourform.TxtDes.value=\"%s\";document.yourform.submit();", 值);
IHTMLDocument2* pHTMLDoc = (IHTMLDocument2*)GetHtmlDocument();
if ( pHTMLDoc != NULL )
{
IHTMLWindow2* pHTMLWnd;
pHTMLDoc->get_parentWindow( &pHTMLWnd );
if ( pHTMLWnd != NULL )
{
CComBSTR bstrjs = strjs.AllocSysString();
CComBSTR bstrlan = SysAllocString(L"javascript");
VARIANT varRet;
pHTMLWnd->execScript(bstrjs, bstrlan, &varRet);
}
}
#19
我原来的代码
Insert()
{
HWND hWnd = AfxGetMainWnd()->m_hWnd;
CoInitialize(NULL);
SHDocVw::IShellWindowsPtr m_spSHWinds;
if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) == S_OK)
{
IDispatchPtr spDisp;
long nCount = m_spSHWinds->GetCount();
for(long i =0;i<nCount;i++)
{
_variant_t va(i, VT_I4);
spDisp = m_spSHWinds->Item(va);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (spBrowser != NULL)
{
IDispatchPtr spDisp;
if(spBrowser->get_Document(&spDisp) == S_OK && spDisp!= 0 )
{
MSHTML::IHTMLDocument2Ptr spHtmlDocument(spDisp);
MSHTML::IHTMLElementPtr spHtmlElement;
if(spHtmlDocument==NULL)
continue;
spHtmlDocument->get_body(&spHtmlElement);
if(spHtmlDocument==NULL)
continue;
HRESULT hr;
MSHTML::IHTMLElementCollection* pColl=NULL;
hr=spHtmlDocument->get_all(&pColl);
if(pColl!=NULL&&SUCCEEDED(hr))
{
long lcount = 0;
pColl->get_length(&lcount);
for(int i=0;i<lcount;i++)
{
_variant_t index;
index.vt=VT_I4;
index.intVal=i;
IDispatchPtr disp;
disp=pColl->item(index,index);
if(disp==NULL)
hr=E_FAIL;
else
{
MSHTML::IHTMLInputElementPtr pInput(disp);
if(pInput)
{
BSTR bstrtype;
pInput->get_type(&bstrtype);
//printf(_bstr_t(bstrtype));
if(StrCmpW(bstrtype,L"text")==0)
{
CString name,Url,Title,Email;
//textarea name="TxtDes" id="TxtDes" style="height:50px;width:300px;"></textarea></td>
MSHTML::IHTMLElementPtr e(pInput);
_variant_t val;
val=e->getAttribute(_bstr_t(L"id"),0);
if (wcscmp(val.bstrVal,L"name")==0){
pInput->put_value(_bstr_t(name));
}
else if (wcscmp(val.bstrVal,L"txtURL")==0){
pInput->put_value(_bstr_t(Url));
}
else if(wcscmp(val.bstrVal,L"TxtTitle")==0){
pInput->put_value(_bstr_t("ÕâÊÇTitle"));
}
else if(wcscmp(val.bstrVal,L"txtName")==0){
pInput->put_value(_bstr_t("ÕâÊÇid=txtName"));
}
else if(wcscmp(val.bstrVal,L"txtEmail")==0){
pInput->put_value(_bstr_t(Email));
}
else{
MSHTML::IHTMLElementPtr e(pInput);
// _variant_t val;
//MSHTML::IHTMLTextAreaElementPtr pHTMLTextAreaElement;
/*
_bstr_t tag;
val=e->get_tagName(&tag);
if (tag==_bstr_t("TEXTAREA"))
{
MSHTML::IHTMLTextAreaElementPtr ta = e;
ta->put_value("..");
*/
// if(StrCmpW(bstrtype,L"textarea")==0)
//
// pInput->put_value(_bstr_t("ÕâÊÇÃèÊöÀ¸"));
else{
pInput->put_value(_bstr_t("..."
}
}
}
SysFreeString(bstrtype);
}
}
}
pColl->Release();
}
}
}
}
}
else
{
printf("Shell Windows interface is not avilable\n");
}
CoUninitialize();
}
#20
wtx_sonery 的代码未能和上面的代码有效地集成在一起,所以。。
#21
MSHTML::IHTMLElement pElement = disp;
_bstr_t sTagName = (const char*)pElement->GettagName();
if( StrCmpW( sTagName, "input" ) == 0 )
{
//input的部分代码
}
else if( StrCmpW( sTagName, "textarea" ) == 0 )
{
//textarea代码
MSHTML::IHTMLTextAreaElementPtr pTextAreaElement = pElement;
pTextAreaElement->put_value( "这是文本框" );
}
_bstr_t sTagName = (const char*)pElement->GettagName();
if( StrCmpW( sTagName, "input" ) == 0 )
{
//input的部分代码
}
else if( StrCmpW( sTagName, "textarea" ) == 0 )
{
//textarea代码
MSHTML::IHTMLTextAreaElementPtr pTextAreaElement = pElement;
pTextAreaElement->put_value( "这是文本框" );
}
#22
LS的代码不正确,出错很多
以下是部份出错代码
'->GettagName' must point to class/struct/union
type 'MSHTML::IHTMLElement' does not have an overloaded member 'operator ->'
see declaration of 'IHTMLElement
2664: 'put_value' : cannot convert parameter 1 from 'char [15]' to 'unsigned short *'
StrCmpW' : cannot convert parameter 2 from 'char [9]' to 'const unsigned short *'
以下是部份出错代码
'->GettagName' must point to class/struct/union
type 'MSHTML::IHTMLElement' does not have an overloaded member 'operator ->'
see declaration of 'IHTMLElement
2664: 'put_value' : cannot convert parameter 1 from 'char [15]' to 'unsigned short *'
StrCmpW' : cannot convert parameter 2 from 'char [9]' to 'const unsigned short *'
#23
大概的步骤应该是先获取
IHTMLTextAreaElement* pHTMLTextAreaElement; 这个指针,]
或是这个指针,具体要查下MSDN/
IHTMLInputElementPtr
然后判断是不是TextArea,然后put_value()
IHTMLTextAreaElement* pHTMLTextAreaElement; 这个指针,]
或是这个指针,具体要查下MSDN/
IHTMLInputElementPtr
然后判断是不是TextArea,然后put_value()
hr = pDispatch-> QueryInterface(IID_IHTMLTextAreaElement,
(void**)&pHTMLTextAreaElement);
if (SUCCEEDED(hr))
{
pHTMLTextAreaElement-> put_value(L"AAAAAAAAAAAAA");
#24
我不知道你用的是MFC还是ATL,也不知道你#import类型库时使用的是什么样的属性,总之不同情况下生成的封装代码是不一样的,所以调用方法有一定区别,比如如果是MFC,则封装的读写属性方法应该是GetValue/PutValue,如果是ATL,如果使用了原始接口和方法,则用get_value/put_value,如果没有使用原始接口,则直接用abc=a->value/a->value=abc; 而且参数类型都会有不同。
那个编译错误是由于参数类型不正确,自己看看生成的封装类用的是什么类型。
模式一:
_bstr_t tag = e->tagName;
if (tag==_bstr_t("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
ta->value = "test";
}
模式二:
CComBSTR tag;
e->get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
CComBSTR v = "test";
ta->put_value(v);
}
MFC模式三:
CComBSTR tag;
e->Getvalue(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
CComBSTR v = "test";
ta->Putvalue(v);
}
自己对号入座吧。
那个编译错误是由于参数类型不正确,自己看看生成的封装类用的是什么类型。
模式一:
_bstr_t tag = e->tagName;
if (tag==_bstr_t("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
ta->value = "test";
}
模式二:
CComBSTR tag;
e->get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
CComBSTR v = "test";
ta->put_value(v);
}
MFC模式三:
CComBSTR tag;
e->Getvalue(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
CComBSTR v = "test";
ta->Putvalue(v);
}
自己对号入座吧。
#25
我用的是在MFC中
#26
模式一:
我把 ta-> value = "test"; 改为ta-> put_value(_bstr_t("test"));
_bstr_t tag = e-> tagName;
if (tag==_bstr_t("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
ta-> put_value(_bstr_t("test"));
}
编译正确,却无法插入。
模式三
rror C2039: 'Getvalue' : is not a member of 'IHTMLElement'
\mshtml.tlh(1586) : see declaration of 'IHTMLElement'
.cpp(343) : error C2039: 'Putvalue' : is not a member of 'IHTMLTextAreaElement'
program files\microsoft visual studio\vc98\include\mshtml.h(31472) : see declaration of 'IHTMLTextAreaElement'
Error executing cl.exe.
Creating browse info file...
mylist.exe - 2 error(s), 1 warning(s)
包含的头文件是
//------------------
#import <mshtml.tlb> // Internet Explorer 5
#import <shdocvw.dll>
#include "Shlwapi.h"
#pragma comment(lib,"Shlwapi.lib")
//--------------------
#include <mshtml.h>
#include <atlbase.h>
#include <oleacc.h>
我把 ta-> value = "test"; 改为ta-> put_value(_bstr_t("test"));
_bstr_t tag = e-> tagName;
if (tag==_bstr_t("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
ta-> put_value(_bstr_t("test"));
}
编译正确,却无法插入。
模式三
rror C2039: 'Getvalue' : is not a member of 'IHTMLElement'
\mshtml.tlh(1586) : see declaration of 'IHTMLElement'
.cpp(343) : error C2039: 'Putvalue' : is not a member of 'IHTMLTextAreaElement'
program files\microsoft visual studio\vc98\include\mshtml.h(31472) : see declaration of 'IHTMLTextAreaElement'
Error executing cl.exe.
Creating browse info file...
mylist.exe - 2 error(s), 1 warning(s)
包含的头文件是
//------------------
#import <mshtml.tlb> // Internet Explorer 5
#import <shdocvw.dll>
#include "Shlwapi.h"
#pragma comment(lib,"Shlwapi.lib")
//--------------------
#include <mshtml.h>
#include <atlbase.h>
#include <oleacc.h>
#27
模式二编译正确,也无法插入
我插入的示例网页如下:
http://lii.org/cs/lii/create/todo
要插入这二部份下面的text空白处
Short Description or Title *
Comment
无法实现,
其他原来的代码可以实现插入其他text栏
我插入的示例网页如下:
http://lii.org/cs/lii/create/todo
要插入这二部份下面的text空白处
Short Description or Title *
Comment
无法实现,
其他原来的代码可以实现插入其他text栏
#28
CComBSTR tag;
e-> get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
CComBSTR v = "test";
ta-> put_value(v);
}
为什么编译正确却无法插入?
得到TABNAME无用吗,难道还要其他的什么?
#29
有谁帮我解释下?!
#30
都没有人?!
还是。。
还是。。
#31
用element的put_innerText这个成员
#32
具体如何弄呢,和原来的集成?
#33
textarea有点特殊,不能使用value来赋值.
之前问过别人js的这个问题
我是使用html对话框测试的,测试代码是这样写的.
之前问过别人js的这个问题
我是使用html对话框测试的,测试代码是这样写的.
IDispatch *pDis;
this->GetElement( _T("TxtDes") , &pDis );
IHTMLElement* pA=0;
pDis->QueryInterface( IID_IHTMLElement , (void**)&pA );
pA->put_innerText( _bstr_t("asbausdisud") );
#34
非常谢谢akirya,我把代码集成在原来的代码之中
编译成功,却还是无法插入
http://lii.org/cs/lii/create/todo
中的
Short Description or Title *
和Comment
下面的输入框。
编译成功,却还是无法插入
http://lii.org/cs/lii/create/todo
中的
Short Description or Title *
和Comment
下面的输入框。
CComBSTR tag;
e-> get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
IHTMLElement* pA=0;
CComBSTR v = "test";
pA->put_innerText( _bstr_t("插入文字") );
// ta-> put_value(v);
}
#35
先确定或者的元素是要插入的地方么?
你显示元素的ID和Name看看是什么.
你显示元素的ID和Name看看是什么.
#36
填充没有任何问题。你代码肯定有不对。
[img=http://iamduyu.googlepages.com/fill_textarea.jpg]http://iamduyu.googlepages.com/fill_textarea.jpg[/img]
[img=http://iamduyu.googlepages.com/fill_textarea.jpg]http://iamduyu.googlepages.com/fill_textarea.jpg[/img]
#37
下面关于这部份的功能实现的代码
CComBSTR tag;
e-> get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
IHTMLElement* pA=0;
CComBSTR v = "test";
pA->put_innerText( _bstr_t("这是描述栏填充") );
}
请指教下
#38
CComBSTR tag;
e-> get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
IHTMLElement* pA=0;
pA->put_innerText( _bstr_t("这是描述栏填充") );
}
#39
肯定之前的代码都有问题了,代码多贴点出来,包括如何定位到这个元素的,此外你可以跟踪看看有没有执行到if语句里面去
#40
头文件如下:
全部代码如下:
#include "stdafx.h"
#include "Fill.h"
#include "FillDlg.h"
#import <mshtml.tlb> // Internet Explorer 5
#import <shdocvw.dll>
#include "Shlwapi.h"
#pragma comment(lib,"Shlwapi.lib")
//--------------------
#include <mshtml.h>
#include <atlbase.h>
#include <oleacc.h>
//------------------------
全部代码如下:
void CFillDlg::OnButton()
{
CoInitialize(NULL);
SHDocVw::IShellWindowsPtr m_spSHWinds;
if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) == S_OK)
{
IDispatchPtr spDisp;
long nCount = m_spSHWinds->GetCount();
for(long i =0;i<nCount;i++)
{
_variant_t va(i, VT_I4);
spDisp = m_spSHWinds->Item(va);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (spBrowser != NULL)
{
IDispatchPtr spDisp;
if(spBrowser->get_Document(&spDisp)== S_OK && spDisp!=0)
{
MSHTML::IHTMLDocument2Ptr spHtmlDocument(spDisp);
MSHTML::IHTMLElementPtr spHtmlElement;
if(spHtmlDocument==NULL)
continue;
spHtmlDocument->get_body(&spHtmlElement);
if(spHtmlDocument==NULL)
continue;
HRESULT hr;
MSHTML::IHTMLElementCollection* pColl=NULL;
hr=spHtmlDocument->get_all(&pColl);
if(pColl!=NULL&&SUCCEEDED(hr))
{
long lcount = 0;
pColl->get_length(&lcount);
for(int i=0;i<lcount;i++)
{
_variant_t index;
index.vt=VT_I4;
index.intVal=i;
IDispatchPtr disp;
disp=pColl->item(index,index);
if(disp==NULL)
hr=E_FAIL;
else
{
MSHTML::IHTMLInputElementPtr pInput(disp);
if(pInput)
{
BSTR bstrtype;
pInput->get_type(&bstrtype);
//printf(_bstr_t(bstrtype));
if(StrCmpW(bstrtype,L"text")==0)
{
MSHTML::IHTMLElementPtr e(pInput);
_variant_t val;
val=e->getAttribute(_bstr_t(L"id"),0);
if (wcscmp(val.bstrVal,L"one")==0){
pInput->put_value(_bstr_t("这是id=one"));
}
else if (wcscmp(val.bstrVal,L"two")==0){
pInput->put_value(_bstr_t("这是id=two"));
}
else{
//---------------以下为插入<textarea></textarea>的代码
CComBSTR tag;
e-> get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
IHTMLElement* pA=0;
pA->put_innerText( _bstr_t("这是textarea") );
}
// ---------------------------
else
pInput->put_value(_bstr_t("这是id不知道的"));
}
}
SysFreeString(bstrtype);
}
}
}
pColl->Release();
}
}
}
}
}
else
{
printf("Shell Windows interface is not avilable\n");
}
CoUninitialize();
}
#41
代码要整理一下,光看匹配的括号都很费劲。
MSHTML::IHTMLInputElementPtr pInput(disp);这句有问题,如果你要找的就是textarea元素的话,pInput的值肯定是NULL,所以应该直接用MSHTML::IHTMLTextAreaElementPtr pta(disp);如果值不是NULL,说明这个元素就是textarea元素,然后直接调用赋值语句pta->put_value(_bstr_t("ok"));
事实上你上面的代码如果跟踪执行的话,根本进入不到put_value语句,因为if(pInput)这个条件肯定是不成立的,所以我前面要你单步跟踪一下就是这个道理。
MSHTML::IHTMLInputElementPtr pInput(disp);这句有问题,如果你要找的就是textarea元素的话,pInput的值肯定是NULL,所以应该直接用MSHTML::IHTMLTextAreaElementPtr pta(disp);如果值不是NULL,说明这个元素就是textarea元素,然后直接调用赋值语句pta->put_value(_bstr_t("ok"));
事实上你上面的代码如果跟踪执行的话,根本进入不到put_value语句,因为if(pInput)这个条件肯定是不成立的,所以我前面要你单步跟踪一下就是这个道理。
#42
MSHTML::IHTMLTextAreaElementPtr pta(disp);
if(pta)
{
IHTMLElement* pA=0;
pta->put_value(_bstr_t("这是插入文本区域"));
}
试了不行,上面的代码有错吗?
#43
跟踪,还是跟踪。所谓的不行是指put_value失败还是根本没执行?
#44
跟踪到if(pta)
其中pta的value是二进制的0x00000000.按F11进函数,一直到出函数都没有变化
this指针变红色,值没有注意,红色的话,我记得是有变化才会这样的,有交互
一直跳出断点,pta的值没有变化,
其中pta的value是二进制的0x00000000.按F11进函数,一直到出函数都没有变化
this指针变红色,值没有注意,红色的话,我记得是有变化才会这样的,有交互
一直跳出断点,pta的值没有变化,
#45
0x00000000是16进制。不好意思
#46
disp-value 0x0017122c
pta->value 0x00000000 值一直为“0”
this->value 0x0012fe74
_com_ptr_t<_com_IIId<MSHTML:IHTMLTextAraeElemment>->value 0 ''
pta->value 0x00000000 值一直为“0”
this->value 0x0012fe74
_com_ptr_t<_com_IIId<MSHTML:IHTMLTextAraeElemment>->value 0 ''
#47
CComBSTR tag;
e-> get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
IHTMLElement* pA=0;
pA->put_innerText( _bstr_t("ÕâÊÇtextarea") );
}
跟踪调试这段代码。断点设在e-get_tagName(&tag);
e &tag的值都是非空
设断点在if (tag==CComBSTR("TEXTAREA"))
返回的值却是“0”
#48
if(pta)不通过,说明这个元素不是TEXTAREA元素,继续下一个循环吧,等找到TEXTAREA元素为止。
#49
如果只是为了测试,自己做一个测试网页,在所需元素上加一个id属性,比如<textarea id="abc"></textarea>,然后就不要在DOM里面用元素集合来循环找了,直接用
IHTMLDocument3::getElementById(_bstr_t("abc"))就能找到这个元素
IHTMLDocument3::getElementById(_bstr_t("abc"))就能找到这个元素
#50
当然不是测试了,我是想插入所有这样<textarea></textarea>的区域。
if(pta)不通过
---------------------
再跟踪就跳出这个函数了。
if(pta)不通过
---------------------
再跟踪就跳出这个函数了。
#1
直接用CInterSession post不就行了吗
干嘛这么麻烦
干嘛这么麻烦
#2
http://topic.csdn.net/t/20050713/16/4142294.html#
这上面有获取FORM上的textarea的内容
但是我要填充。
是不是可以用判断
//-----------------------
IHTMLElement* pElement = (IHTMLElement* )hWnd;
HRESULT hr;
BSTR value;
IHTMLInputTextElement* pHTMLInputTextElement;
hr = pElement->QueryInterface(IID_IHTMLInputTextElement,
(void**)&pHTMLTextAreaElement);
再put-value
这上面有获取FORM上的textarea的内容
但是我要填充。
是不是可以用判断
//-----------------------
IHTMLElement* pElement = (IHTMLElement* )hWnd;
HRESULT hr;
BSTR value;
IHTMLInputTextElement* pHTMLInputTextElement;
hr = pElement->QueryInterface(IID_IHTMLInputTextElement,
(void**)&pHTMLTextAreaElement);
再put-value
#3
-------------
我是要集成到原来的程序里面
所以不想改动太大
具体该如何弄呢
#4
请高手帮忙
#5
加高分请高手帮忙
#6
用基本的字符串查找比较试试
#7
if(StrCmpW(bstrtype,L"textarea")==0)
pInput-> put_value(_bstr_t("这是描述栏"));试了不行。
pInput-> put_value(_bstr_t("这是描述栏"));试了不行。
#8
pInput->get_value 行吗?
#9
首先要判断<textarea > </textarea>
然后再填充
主要是判断
pInput-> get_value 行吗?-------不行,这是填充部份的
if(StrCmpW(bstrtype,L"textarea")==0)
pInput-> put_value(_bstr_t("这是在填充描述栏"));试了不行
然后再填充
主要是判断
pInput-> get_value 行吗?-------不行,这是填充部份的
if(StrCmpW(bstrtype,L"textarea")==0)
pInput-> put_value(_bstr_t("这是在填充描述栏"));试了不行
#10
应该是加上这句,下午慢慢调试了,高手都不出手呀
晕
IHTMLTextAreaElement* pHTMLTextAreaElement;
hr = pDispatch->QueryInterface(IID_IHTMLTextAreaElement,
(void**)&pHTMLTextAreaElement);
if (SUCCEEDED(hr))
{
pHTMLTextAreaElement->put_value(L"AAAAAAAAAAAAA");
}
晕
IHTMLTextAreaElement* pHTMLTextAreaElement;
hr = pDispatch->QueryInterface(IID_IHTMLTextAreaElement,
(void**)&pHTMLTextAreaElement);
if (SUCCEEDED(hr))
{
pHTMLTextAreaElement->put_value(L"AAAAAAAAAAAAA");
}
#11
textarea标签对应的元素不是IHTMLInputElementPtr,而是IHTMLTextAreaElementPtr,所以要用IHTMLTextAreaElementPtr::put_value
#12
具体要如何写呢
#13
这是普通textinput的填充代码?那textarea呢,如何写呢
if(StrCmpW(bstrtype,L"text")==0) {
MSHTML::IHTMLElementPtr e(pInput);
_variant_t val;
val=e->getAttribute(_bstr_t(L"id"),0);
if (wcscmp(val.bstrVal,L"name")==0){
pInput->put_value(_bstr_t(name));
#14
UP者有分
#15
首先得到标准元素 IHTMLElementPtr e;
然后:
_bstr_t tag;
e->get_tagName(&tag);
if (tag==_bstr_t("TEXTAREA"))
{
IHTMLTextAreaPtr ta = e;
ta->put_value(...);
}
然后:
_bstr_t tag;
e->get_tagName(&tag);
if (tag==_bstr_t("TEXTAREA"))
{
IHTMLTextAreaPtr ta = e;
ta->put_value(...);
}
#16
error C2664: 'get_tagName' : cannot convert parameter 1 from 'class _bstr_t *' to 'unsigned short ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
\mylist\mylistDlg.cpp(346) : error C2664: 'put_value' : cannot convert parameter 1 from 'char [15]' to 'unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
\mylist\mylistDlg.cpp(357) : error C2181: illegal else without matching if
\mylist\mylistDlg.cpp(376) : error C2181: illegal else without matching if
\mylist\debug\mshtml.tli(220) : error C2601: 'getAttribute' : local function definitions are illegal
\mylist\debug\mshtml.tli(12318) : error C2601: 'item' : local function definitions are illegal
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
\mylist\mylistDlg.cpp(346) : error C2664: 'put_value' : cannot convert parameter 1 from 'char [15]' to 'unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
\mylist\mylistDlg.cpp(357) : error C2181: illegal else without matching if
\mylist\mylistDlg.cpp(376) : error C2181: illegal else without matching if
\mylist\debug\mshtml.tli(220) : error C2601: 'getAttribute' : local function definitions are illegal
\mylist\debug\mshtml.tli(12318) : error C2601: 'item' : local function definitions are illegal
#17
_bstr_t tag;
e->get_tagName(&tag);
if (tag==_bstr_t("TEXTAREA"))
{
MSHTML::IHTMLTextAreaElementPtr ta = e;
ta->put_value("这是描述栏插入");
应该是很多未定义的出错
e->get_tagName(&tag);
if (tag==_bstr_t("TEXTAREA"))
{
MSHTML::IHTMLTextAreaElementPtr ta = e;
ta->put_value("这是描述栏插入");
应该是很多未定义的出错
#18
楼主考虑下用脚本吧
CString strjs;
strjs.Format("document.yourform.TxtDes.value=\"%s\";document.yourform.submit();", 值);
IHTMLDocument2* pHTMLDoc = (IHTMLDocument2*)GetHtmlDocument();
if ( pHTMLDoc != NULL )
{
IHTMLWindow2* pHTMLWnd;
pHTMLDoc->get_parentWindow( &pHTMLWnd );
if ( pHTMLWnd != NULL )
{
CComBSTR bstrjs = strjs.AllocSysString();
CComBSTR bstrlan = SysAllocString(L"javascript");
VARIANT varRet;
pHTMLWnd->execScript(bstrjs, bstrlan, &varRet);
}
}
#19
我原来的代码
Insert()
{
HWND hWnd = AfxGetMainWnd()->m_hWnd;
CoInitialize(NULL);
SHDocVw::IShellWindowsPtr m_spSHWinds;
if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) == S_OK)
{
IDispatchPtr spDisp;
long nCount = m_spSHWinds->GetCount();
for(long i =0;i<nCount;i++)
{
_variant_t va(i, VT_I4);
spDisp = m_spSHWinds->Item(va);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (spBrowser != NULL)
{
IDispatchPtr spDisp;
if(spBrowser->get_Document(&spDisp) == S_OK && spDisp!= 0 )
{
MSHTML::IHTMLDocument2Ptr spHtmlDocument(spDisp);
MSHTML::IHTMLElementPtr spHtmlElement;
if(spHtmlDocument==NULL)
continue;
spHtmlDocument->get_body(&spHtmlElement);
if(spHtmlDocument==NULL)
continue;
HRESULT hr;
MSHTML::IHTMLElementCollection* pColl=NULL;
hr=spHtmlDocument->get_all(&pColl);
if(pColl!=NULL&&SUCCEEDED(hr))
{
long lcount = 0;
pColl->get_length(&lcount);
for(int i=0;i<lcount;i++)
{
_variant_t index;
index.vt=VT_I4;
index.intVal=i;
IDispatchPtr disp;
disp=pColl->item(index,index);
if(disp==NULL)
hr=E_FAIL;
else
{
MSHTML::IHTMLInputElementPtr pInput(disp);
if(pInput)
{
BSTR bstrtype;
pInput->get_type(&bstrtype);
//printf(_bstr_t(bstrtype));
if(StrCmpW(bstrtype,L"text")==0)
{
CString name,Url,Title,Email;
//textarea name="TxtDes" id="TxtDes" style="height:50px;width:300px;"></textarea></td>
MSHTML::IHTMLElementPtr e(pInput);
_variant_t val;
val=e->getAttribute(_bstr_t(L"id"),0);
if (wcscmp(val.bstrVal,L"name")==0){
pInput->put_value(_bstr_t(name));
}
else if (wcscmp(val.bstrVal,L"txtURL")==0){
pInput->put_value(_bstr_t(Url));
}
else if(wcscmp(val.bstrVal,L"TxtTitle")==0){
pInput->put_value(_bstr_t("ÕâÊÇTitle"));
}
else if(wcscmp(val.bstrVal,L"txtName")==0){
pInput->put_value(_bstr_t("ÕâÊÇid=txtName"));
}
else if(wcscmp(val.bstrVal,L"txtEmail")==0){
pInput->put_value(_bstr_t(Email));
}
else{
MSHTML::IHTMLElementPtr e(pInput);
// _variant_t val;
//MSHTML::IHTMLTextAreaElementPtr pHTMLTextAreaElement;
/*
_bstr_t tag;
val=e->get_tagName(&tag);
if (tag==_bstr_t("TEXTAREA"))
{
MSHTML::IHTMLTextAreaElementPtr ta = e;
ta->put_value("..");
*/
// if(StrCmpW(bstrtype,L"textarea")==0)
//
// pInput->put_value(_bstr_t("ÕâÊÇÃèÊöÀ¸"));
else{
pInput->put_value(_bstr_t("..."
}
}
}
SysFreeString(bstrtype);
}
}
}
pColl->Release();
}
}
}
}
}
else
{
printf("Shell Windows interface is not avilable\n");
}
CoUninitialize();
}
#20
wtx_sonery 的代码未能和上面的代码有效地集成在一起,所以。。
#21
MSHTML::IHTMLElement pElement = disp;
_bstr_t sTagName = (const char*)pElement->GettagName();
if( StrCmpW( sTagName, "input" ) == 0 )
{
//input的部分代码
}
else if( StrCmpW( sTagName, "textarea" ) == 0 )
{
//textarea代码
MSHTML::IHTMLTextAreaElementPtr pTextAreaElement = pElement;
pTextAreaElement->put_value( "这是文本框" );
}
_bstr_t sTagName = (const char*)pElement->GettagName();
if( StrCmpW( sTagName, "input" ) == 0 )
{
//input的部分代码
}
else if( StrCmpW( sTagName, "textarea" ) == 0 )
{
//textarea代码
MSHTML::IHTMLTextAreaElementPtr pTextAreaElement = pElement;
pTextAreaElement->put_value( "这是文本框" );
}
#22
LS的代码不正确,出错很多
以下是部份出错代码
'->GettagName' must point to class/struct/union
type 'MSHTML::IHTMLElement' does not have an overloaded member 'operator ->'
see declaration of 'IHTMLElement
2664: 'put_value' : cannot convert parameter 1 from 'char [15]' to 'unsigned short *'
StrCmpW' : cannot convert parameter 2 from 'char [9]' to 'const unsigned short *'
以下是部份出错代码
'->GettagName' must point to class/struct/union
type 'MSHTML::IHTMLElement' does not have an overloaded member 'operator ->'
see declaration of 'IHTMLElement
2664: 'put_value' : cannot convert parameter 1 from 'char [15]' to 'unsigned short *'
StrCmpW' : cannot convert parameter 2 from 'char [9]' to 'const unsigned short *'
#23
大概的步骤应该是先获取
IHTMLTextAreaElement* pHTMLTextAreaElement; 这个指针,]
或是这个指针,具体要查下MSDN/
IHTMLInputElementPtr
然后判断是不是TextArea,然后put_value()
IHTMLTextAreaElement* pHTMLTextAreaElement; 这个指针,]
或是这个指针,具体要查下MSDN/
IHTMLInputElementPtr
然后判断是不是TextArea,然后put_value()
hr = pDispatch-> QueryInterface(IID_IHTMLTextAreaElement,
(void**)&pHTMLTextAreaElement);
if (SUCCEEDED(hr))
{
pHTMLTextAreaElement-> put_value(L"AAAAAAAAAAAAA");
#24
我不知道你用的是MFC还是ATL,也不知道你#import类型库时使用的是什么样的属性,总之不同情况下生成的封装代码是不一样的,所以调用方法有一定区别,比如如果是MFC,则封装的读写属性方法应该是GetValue/PutValue,如果是ATL,如果使用了原始接口和方法,则用get_value/put_value,如果没有使用原始接口,则直接用abc=a->value/a->value=abc; 而且参数类型都会有不同。
那个编译错误是由于参数类型不正确,自己看看生成的封装类用的是什么类型。
模式一:
_bstr_t tag = e->tagName;
if (tag==_bstr_t("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
ta->value = "test";
}
模式二:
CComBSTR tag;
e->get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
CComBSTR v = "test";
ta->put_value(v);
}
MFC模式三:
CComBSTR tag;
e->Getvalue(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
CComBSTR v = "test";
ta->Putvalue(v);
}
自己对号入座吧。
那个编译错误是由于参数类型不正确,自己看看生成的封装类用的是什么类型。
模式一:
_bstr_t tag = e->tagName;
if (tag==_bstr_t("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
ta->value = "test";
}
模式二:
CComBSTR tag;
e->get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
CComBSTR v = "test";
ta->put_value(v);
}
MFC模式三:
CComBSTR tag;
e->Getvalue(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
CComBSTR v = "test";
ta->Putvalue(v);
}
自己对号入座吧。
#25
我用的是在MFC中
#26
模式一:
我把 ta-> value = "test"; 改为ta-> put_value(_bstr_t("test"));
_bstr_t tag = e-> tagName;
if (tag==_bstr_t("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
ta-> put_value(_bstr_t("test"));
}
编译正确,却无法插入。
模式三
rror C2039: 'Getvalue' : is not a member of 'IHTMLElement'
\mshtml.tlh(1586) : see declaration of 'IHTMLElement'
.cpp(343) : error C2039: 'Putvalue' : is not a member of 'IHTMLTextAreaElement'
program files\microsoft visual studio\vc98\include\mshtml.h(31472) : see declaration of 'IHTMLTextAreaElement'
Error executing cl.exe.
Creating browse info file...
mylist.exe - 2 error(s), 1 warning(s)
包含的头文件是
//------------------
#import <mshtml.tlb> // Internet Explorer 5
#import <shdocvw.dll>
#include "Shlwapi.h"
#pragma comment(lib,"Shlwapi.lib")
//--------------------
#include <mshtml.h>
#include <atlbase.h>
#include <oleacc.h>
我把 ta-> value = "test"; 改为ta-> put_value(_bstr_t("test"));
_bstr_t tag = e-> tagName;
if (tag==_bstr_t("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
ta-> put_value(_bstr_t("test"));
}
编译正确,却无法插入。
模式三
rror C2039: 'Getvalue' : is not a member of 'IHTMLElement'
\mshtml.tlh(1586) : see declaration of 'IHTMLElement'
.cpp(343) : error C2039: 'Putvalue' : is not a member of 'IHTMLTextAreaElement'
program files\microsoft visual studio\vc98\include\mshtml.h(31472) : see declaration of 'IHTMLTextAreaElement'
Error executing cl.exe.
Creating browse info file...
mylist.exe - 2 error(s), 1 warning(s)
包含的头文件是
//------------------
#import <mshtml.tlb> // Internet Explorer 5
#import <shdocvw.dll>
#include "Shlwapi.h"
#pragma comment(lib,"Shlwapi.lib")
//--------------------
#include <mshtml.h>
#include <atlbase.h>
#include <oleacc.h>
#27
模式二编译正确,也无法插入
我插入的示例网页如下:
http://lii.org/cs/lii/create/todo
要插入这二部份下面的text空白处
Short Description or Title *
Comment
无法实现,
其他原来的代码可以实现插入其他text栏
我插入的示例网页如下:
http://lii.org/cs/lii/create/todo
要插入这二部份下面的text空白处
Short Description or Title *
Comment
无法实现,
其他原来的代码可以实现插入其他text栏
#28
CComBSTR tag;
e-> get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
CComBSTR v = "test";
ta-> put_value(v);
}
为什么编译正确却无法插入?
得到TABNAME无用吗,难道还要其他的什么?
#29
有谁帮我解释下?!
#30
都没有人?!
还是。。
还是。。
#31
用element的put_innerText这个成员
#32
具体如何弄呢,和原来的集成?
#33
textarea有点特殊,不能使用value来赋值.
之前问过别人js的这个问题
我是使用html对话框测试的,测试代码是这样写的.
之前问过别人js的这个问题
我是使用html对话框测试的,测试代码是这样写的.
IDispatch *pDis;
this->GetElement( _T("TxtDes") , &pDis );
IHTMLElement* pA=0;
pDis->QueryInterface( IID_IHTMLElement , (void**)&pA );
pA->put_innerText( _bstr_t("asbausdisud") );
#34
非常谢谢akirya,我把代码集成在原来的代码之中
编译成功,却还是无法插入
http://lii.org/cs/lii/create/todo
中的
Short Description or Title *
和Comment
下面的输入框。
编译成功,却还是无法插入
http://lii.org/cs/lii/create/todo
中的
Short Description or Title *
和Comment
下面的输入框。
CComBSTR tag;
e-> get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
IHTMLElement* pA=0;
CComBSTR v = "test";
pA->put_innerText( _bstr_t("插入文字") );
// ta-> put_value(v);
}
#35
先确定或者的元素是要插入的地方么?
你显示元素的ID和Name看看是什么.
你显示元素的ID和Name看看是什么.
#36
填充没有任何问题。你代码肯定有不对。
[img=http://iamduyu.googlepages.com/fill_textarea.jpg]http://iamduyu.googlepages.com/fill_textarea.jpg[/img]
[img=http://iamduyu.googlepages.com/fill_textarea.jpg]http://iamduyu.googlepages.com/fill_textarea.jpg[/img]
#37
下面关于这部份的功能实现的代码
CComBSTR tag;
e-> get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
IHTMLElement* pA=0;
CComBSTR v = "test";
pA->put_innerText( _bstr_t("这是描述栏填充") );
}
请指教下
#38
CComBSTR tag;
e-> get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
IHTMLElement* pA=0;
pA->put_innerText( _bstr_t("这是描述栏填充") );
}
#39
肯定之前的代码都有问题了,代码多贴点出来,包括如何定位到这个元素的,此外你可以跟踪看看有没有执行到if语句里面去
#40
头文件如下:
全部代码如下:
#include "stdafx.h"
#include "Fill.h"
#include "FillDlg.h"
#import <mshtml.tlb> // Internet Explorer 5
#import <shdocvw.dll>
#include "Shlwapi.h"
#pragma comment(lib,"Shlwapi.lib")
//--------------------
#include <mshtml.h>
#include <atlbase.h>
#include <oleacc.h>
//------------------------
全部代码如下:
void CFillDlg::OnButton()
{
CoInitialize(NULL);
SHDocVw::IShellWindowsPtr m_spSHWinds;
if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) == S_OK)
{
IDispatchPtr spDisp;
long nCount = m_spSHWinds->GetCount();
for(long i =0;i<nCount;i++)
{
_variant_t va(i, VT_I4);
spDisp = m_spSHWinds->Item(va);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (spBrowser != NULL)
{
IDispatchPtr spDisp;
if(spBrowser->get_Document(&spDisp)== S_OK && spDisp!=0)
{
MSHTML::IHTMLDocument2Ptr spHtmlDocument(spDisp);
MSHTML::IHTMLElementPtr spHtmlElement;
if(spHtmlDocument==NULL)
continue;
spHtmlDocument->get_body(&spHtmlElement);
if(spHtmlDocument==NULL)
continue;
HRESULT hr;
MSHTML::IHTMLElementCollection* pColl=NULL;
hr=spHtmlDocument->get_all(&pColl);
if(pColl!=NULL&&SUCCEEDED(hr))
{
long lcount = 0;
pColl->get_length(&lcount);
for(int i=0;i<lcount;i++)
{
_variant_t index;
index.vt=VT_I4;
index.intVal=i;
IDispatchPtr disp;
disp=pColl->item(index,index);
if(disp==NULL)
hr=E_FAIL;
else
{
MSHTML::IHTMLInputElementPtr pInput(disp);
if(pInput)
{
BSTR bstrtype;
pInput->get_type(&bstrtype);
//printf(_bstr_t(bstrtype));
if(StrCmpW(bstrtype,L"text")==0)
{
MSHTML::IHTMLElementPtr e(pInput);
_variant_t val;
val=e->getAttribute(_bstr_t(L"id"),0);
if (wcscmp(val.bstrVal,L"one")==0){
pInput->put_value(_bstr_t("这是id=one"));
}
else if (wcscmp(val.bstrVal,L"two")==0){
pInput->put_value(_bstr_t("这是id=two"));
}
else{
//---------------以下为插入<textarea></textarea>的代码
CComBSTR tag;
e-> get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
IHTMLElement* pA=0;
pA->put_innerText( _bstr_t("这是textarea") );
}
// ---------------------------
else
pInput->put_value(_bstr_t("这是id不知道的"));
}
}
SysFreeString(bstrtype);
}
}
}
pColl->Release();
}
}
}
}
}
else
{
printf("Shell Windows interface is not avilable\n");
}
CoUninitialize();
}
#41
代码要整理一下,光看匹配的括号都很费劲。
MSHTML::IHTMLInputElementPtr pInput(disp);这句有问题,如果你要找的就是textarea元素的话,pInput的值肯定是NULL,所以应该直接用MSHTML::IHTMLTextAreaElementPtr pta(disp);如果值不是NULL,说明这个元素就是textarea元素,然后直接调用赋值语句pta->put_value(_bstr_t("ok"));
事实上你上面的代码如果跟踪执行的话,根本进入不到put_value语句,因为if(pInput)这个条件肯定是不成立的,所以我前面要你单步跟踪一下就是这个道理。
MSHTML::IHTMLInputElementPtr pInput(disp);这句有问题,如果你要找的就是textarea元素的话,pInput的值肯定是NULL,所以应该直接用MSHTML::IHTMLTextAreaElementPtr pta(disp);如果值不是NULL,说明这个元素就是textarea元素,然后直接调用赋值语句pta->put_value(_bstr_t("ok"));
事实上你上面的代码如果跟踪执行的话,根本进入不到put_value语句,因为if(pInput)这个条件肯定是不成立的,所以我前面要你单步跟踪一下就是这个道理。
#42
MSHTML::IHTMLTextAreaElementPtr pta(disp);
if(pta)
{
IHTMLElement* pA=0;
pta->put_value(_bstr_t("这是插入文本区域"));
}
试了不行,上面的代码有错吗?
#43
跟踪,还是跟踪。所谓的不行是指put_value失败还是根本没执行?
#44
跟踪到if(pta)
其中pta的value是二进制的0x00000000.按F11进函数,一直到出函数都没有变化
this指针变红色,值没有注意,红色的话,我记得是有变化才会这样的,有交互
一直跳出断点,pta的值没有变化,
其中pta的value是二进制的0x00000000.按F11进函数,一直到出函数都没有变化
this指针变红色,值没有注意,红色的话,我记得是有变化才会这样的,有交互
一直跳出断点,pta的值没有变化,
#45
0x00000000是16进制。不好意思
#46
disp-value 0x0017122c
pta->value 0x00000000 值一直为“0”
this->value 0x0012fe74
_com_ptr_t<_com_IIId<MSHTML:IHTMLTextAraeElemment>->value 0 ''
pta->value 0x00000000 值一直为“0”
this->value 0x0012fe74
_com_ptr_t<_com_IIId<MSHTML:IHTMLTextAraeElemment>->value 0 ''
#47
CComBSTR tag;
e-> get_tagName(&tag);
if (tag==CComBSTR("TEXTAREA"))
{
IHTMLTextAreaElementPtr ta = e;
IHTMLElement* pA=0;
pA->put_innerText( _bstr_t("ÕâÊÇtextarea") );
}
跟踪调试这段代码。断点设在e-get_tagName(&tag);
e &tag的值都是非空
设断点在if (tag==CComBSTR("TEXTAREA"))
返回的值却是“0”
#48
if(pta)不通过,说明这个元素不是TEXTAREA元素,继续下一个循环吧,等找到TEXTAREA元素为止。
#49
如果只是为了测试,自己做一个测试网页,在所需元素上加一个id属性,比如<textarea id="abc"></textarea>,然后就不要在DOM里面用元素集合来循环找了,直接用
IHTMLDocument3::getElementById(_bstr_t("abc"))就能找到这个元素
IHTMLDocument3::getElementById(_bstr_t("abc"))就能找到这个元素
#50
当然不是测试了,我是想插入所有这样<textarea></textarea>的区域。
if(pta)不通过
---------------------
再跟踪就跳出这个函数了。
if(pta)不通过
---------------------
再跟踪就跳出这个函数了。