Caret and Markup Pointer

From: harvinder singh (nospam_at_itppppps.com)
Date: 08/16/04


Date: Mon, 16 Aug 2004 16:21:43 +0530

Hi All,

    I am trying to move the cursor from one position to another, below is my
snippet of the code. The cursor moves, but comes back to its original
position again. I am puzzeled by this behaviour.

    Any clue to what is wrong here? This code is invoked when I click the
mouse.

Regards

Harvinder Singh

CComPtr<IHTMLDocument2> spDocument2;

CComPtr<IDispatch> spDisp;

spHTMLElement->get_document(&spDisp);

spDocument2 = spDisp;

CComPtr<IHTMLElement> spPointerElement;

CComPtr<IHTMLCaret> spCaret;

CComPtr<IMarkupServices> spMUService;

CComPtr<IMarkupPointer> spMUPointer;

CComPtr<IDisplayServices> spDisplayService;

CComPtr<IDisplayPointer> spDisplayPointer;

spDocument2->QueryInterface(&spDisplayService);

if(!spDisplayPointer)

spDisplayService->CreateDisplayPointer(&spDisplayPointer);

spDocument2->QueryInterface(&spMUService);

CComPtr<IMarkupPointer> spMU2;

spMUService->CreateMarkupPointer(&spMU2);

spDisplayService->GetCaret(&spCaret);

hr = spCaret->MoveMarkupPointerToCaret(spMU2);

Sleep(10);

MARKUP_CONTEXT_TYPE type;

CComPtr<IHTMLElement> spElementTemp;

long len = 5;

OLECHAR charr;

hr = spMU2->Right(TRUE,&type,&spElementTemp,&len,&charr);

spCaret = NULL;

tagPOINT point;

hr = spDisplayService->GetCaret(&spCaret);

hr = spCaret->GetLocation(&point,TRUE);

if(FAILED(hr = spDisplayPointer->MoveToMarkupPointer(spMU2,NULL)))

{

      ::AfxMessageBox("Failed to move DisplayPointer");

}

if(FAILED(hr = spCaret->MoveCaretToPointerEx(

spDisplayPointer,TRUE,TRUE,CARET_DIRECTION_INDETERMINATE)))

{

::AfxMessageBox("Failed to move Caret");

}

spCaret->GetLocation(&point,1);