Search code examples
visual-c++windows-8text-services-framework

how to get cursor position using GetSelection in text service framework windows8 application?


HRESULT         hr;
TF_SELECTION    tfSelection;
ULONG           uFetched;
//Obtain the default selection. 
hr = _pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &uFetched);
UINT ar=(UINT)uFetched;
if(SUCCEEDED(hr) && (uFetched > 0))
{
    UINT ar=(UINT)uFetched;
    //Work with the selection. 
    //Release the selection range object. 
    tfSelection.range->Release();
}

Hi all. I am implementing this code in the DoEditSession method. When I try to get the selection, I always get a value of 1 for uFetched. But the cursor position is not coming?

I am developing a text service for windows RT using Tsf interface. I have integrated libraries that suggests words based on letters we type in the candidate window. Now I need to get the letters before and after the Cursor Position in the Document. So here I have used GetSelection to retrieve the selected text. The problem is I am not able to retrieve the caret position in the document (notepad). Is there any specific way in which i can get the letter/text around the caret/cursor position?


Solution

  • You can shift the start/end of the selection range without actually modifying the selection.