How To Programmatically Copy an IMG Element to the Clipboard
来源:互联网 发布:雅思作文 知乎 编辑:程序博客网 时间:2024/05/24 15:41
The best way to copy an image on a Web page to the clipboard is to use the execCommand method of the controlRangeobject. The following code illustrates to do this from within script on the page itself (given the ID of the image to be copied):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):
function copyImage(sImgID) { var ctrlRange = document.body.createControlRange(); ctrlRange.add(document.all(sImgID)); ctrlRange.execCommand("Copy"); }
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"Copy"); 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; }
0 0
- How To Programmatically Copy an IMG Element to the Clipboard
- How To Programmatically Copy an IMG Element to the Clipboard
- How to close an InfoPath form programmatically
- How to snap an OpenGL client and send it to the clipboard
- How to programmatically change the default view of an InfoPath form
- Gnome-terminal, How to Copy selection to clipboard automatically?
- Copy Html To Clipboard
- How to Copy an Assembly From the GAC to the File System
- how to know whether an element has an class
- How to get the MouseEvent coordinates for an element that has CSS3 Transform?
- How to Retrieve Remote MAC Address Programmatically
- How to write view controller programmatically
- how to manage Zope objects programmatically.
- How to use SSH in Java Programmatically
- How to programmatically click a WPF button
- How to Copy an Entire Directory in VB6?
- How to copy an object in objective c
- How to copy values of an array into another array
- #Otsu双阈值的二值化分割(opencv2实现)
- Android Activity和Intent机制学习笔记
- HDOJ Number Sequence(java)
- hdu_1251统计难题
- 贪心题集
- How To Programmatically Copy an IMG Element to the Clipboard
- ==与equals()的区别
- apache tomcat 6集群负载和session复制
- 多媒体编程——声音播放(1)
- OpenCV学习之五: 如何用指令启动或关闭OpenCV的CPU指令集CV_SSE2,CV_SSSE4等优化
- C++空类默认函数
- Android adb shell am/pm使用
- BZOJ [Usaco2007 Jan]Protecting the Flowers 护花(隐藏题)
- hibernate_Restrictions用法