views:

70

answers:

1

Hi,

How can I get Current user selection or current cursor location in HTML document? I am useg MSHTML interfaces in MFC.

Thanks. :)

A: 
    CComPtr<IHTMLSelectionObject> pSelection;
    hr = pHTMLDocument->get_selection(&pSelection);
    if (FAILED(hr) || pSelection==NULL)
            return false;

    CComPtr<IDispatch> pDispRange;
    hr = pSelection->createRange(&pDispRange);
    if (FAILED(hr) || pDispRange==NULL)
            return false;
    CComPtr<IHTMLTxtRange> pRange;
    hr = pDispRange->QueryInterface(IID_IHTMLTxtRange,
            reinterpret_cast<void**>(&pRange));
    if (FAILED(hr)|| pRange ==NULL)
            return false;
Sheng Jiang 蒋晟