/**
 * Returns the selected text within the active document
 **/
BSTR IEView::getSelection() {
    BSTR text = NULL;
    IHTMLDocument2 *document = getDocument();
    if (document != NULL) {
        IHTMLSelectionObject *pSelection = NULL;
        if (SUCCEEDED(document->get_selection( &pSelection )) && pSelection != NULL) {
            IDispatch *pDisp = NULL;
            if (SUCCEEDED(pSelection->createRange( &pDisp )) &&  pDisp != NULL) {
                IHTMLTxtRange *pRange = NULL;
                if (SUCCEEDED(pDisp->QueryInterface(IID_IHTMLTxtRange, (void**)&pRange))) {
                    if (SUCCEEDED(pRange->get_text(&text))) {
                        text = Utils::dupString(text);
                    }
                    pRange->Release();
                }
                pDisp->Release();
            }
            pSelection->Release();
        }
        document->Release();
    }
    return text;
}
Beispiel #2
0
//-------------------------------------------------------------------------------
// Name: HrGetRangeFromSelection
// Desc: Запросит Ранг Выделенного
//-------------------------------------------------------------------------------
HRESULT COfsDhtmlEditCtrl::HrGetRangeFromSelection(IHTMLTxtRange **ppRange)
{
    IHTMLSelectionObject    *pSel=0;
    IHTMLTxtRange           *pTxtRange=0;
    IDispatch               *pID=0;
    HRESULT                 hr=E_FAIL;

    if (ppRange == NULL)
        return E_INVALIDARG;

    *ppRange = NULL;

	IHTMLDocument2* pDoc = NULL;

	if (SUCCEEDED(HrGetDoc(&pDoc)))
	{

		if(pDoc)
		{
			pDoc->get_selection(&pSel);
			if (pSel)
			{
				pSel->createRange(&pID);
				if (pID)
				{
					hr = pID->QueryInterface(IID_IHTMLTxtRange, (LPVOID *)ppRange);
					pID->Release();
				}
				pSel->Release();
			}

			pDoc->Release();
		}

	}
	return hr;
}