在页面编辑环境下,如何定位所选中的表单项,在线等~~~

hubeicaolei 2003-02-25 10:40:40
在页面编辑时,当选中一个表单项,如text,select的时候,能够选中这个表单项的html代码,就像frontpage中,在普通模式中选中一个表单项,在原文件模式中会发现这个表单项的代码被选中一样。
如何用vc做到这一点?
...全文
46 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2003-03-03
  • 打赏
  • 举报
回复
In Microsoft Visual C++, this method call translates to IHTMLControlRange::execCommand. The following code illustrates how to implement the same technique in Visual C++ given an IDispatch pointer to the document that contains the image and the ID of the IMG element wrapped in a VARIANT structure (with a type VT_BSTR):

STDMETHODIMP CMyBrowser::CopyImage(LPDISPATCH pDispDoc, VARIANT vImageID)
{
HRESULT hr = E_FAIL;
IHTMLDocument2* pDoc = NULL;
IHTMLElement* pelmBody = NULL;
IHTMLElement2* pelmBodyTwo = NULL;
IDispatch* pdispImgElement = NULL;
IDispatch* pdispCtrlRange = NULL;
IHTMLElementCollection* pColl = NULL;
IHTMLControlElement* pCtrlElement = NULL;
IHTMLControlRange* pCtrlRange = NULL;
BSTR bstrCommand = SysAllocString(L"select");//can be replaced by copy,past,etc.
VARIANT_BOOL vbReturn;
VARIANT vEmpty;
VariantInit(&vEmpty);

if (pDispDoc == NULL)
goto Cleanup;

if (FAILED(pDispDoc->QueryInterface(IID_IHTMLDocument2, (void**) &pDoc)))
goto Cleanup;

if (FAILED(pDoc->get_all(&pColl)))
goto Cleanup;

if (FAILED(pColl->item(vImageID, vEmpty, &pdispImgElement))
|| pdispImgElement == NULL)
goto Cleanup;

if (FAILED(pDoc->get_body(&pelmBody)) || pelmBody == NULL)
goto Cleanup;

if (FAILED(pelmBody->QueryInterface(IID_IHTMLElement2, (void**) &pelmBodyTwo))
|| pelmBodyTwo == NULL)
goto Cleanup;

if (FAILED(pelmBodyTwo->createControlRange(&pdispCtrlRange))
|| pdispCtrlRange == NULL)
goto Cleanup;

if (FAILED(pdispCtrlRange->QueryInterface(IID_IHTMLControlRange, (void**) &pCtrlRange))
|| pCtrlRange == NULL)
goto Cleanup;

if (FAILED(pdispImgElement->QueryInterface(IID_IHTMLControlElement, (void**) &pCtrlElement))
|| pCtrlElement == NULL)
goto Cleanup;

hr = pCtrlRange->add(pCtrlElement);

if (SUCCEEDED(hr))
hr = pCtrlRange->execCommand(bstrCommand, VARIANT_FALSE, vEmpty, &vbReturn);

pCtrlElement->Release();
hr = S_OK;

Cleanup:

SysFreeString(bstrCommand);

if (pCtrlRange)
pCtrlRange->Release();

if (pdispCtrlRange)
pdispCtrlRange->Release();

if (pelmBodyTwo)
pelmBodyTwo->Release();

if (pelmBody)
pelmBody->Release();

if (pdispImgElement)
pdispImgElement->Release();

if (pColl)
pColl->Release();

if (pDispDoc)
pDispDoc->Release();

return hr;
}
Tasehouny 2003-03-02
  • 打赏
  • 举报
回复
我想这个不难吧,你在定位这个控件(edit,select等),就可以得到它的IHTMLElement指针,这样你就得得到它所对应的HTML代码,用outerHTML 方法得到,然后以这个得到HTML代码在源文件中查找,然后标记它。

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧