🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #1418

DISPID_HTMLELEMENTEVENTS2_ONFOCUS :: How to force text insertion point(caret position) of a input text box

#1418
From: James O'Brien
Date: Fri, 11 Feb 2005 21:09
91 lines
4176 bytes
Hello,

I'm new to programming DHTML, so pardon my  ignorance.   I'm using 
TCppWebBrowser control to display HTML which contains a number of <input 
type=text> elements.  My program loads the HTML page, searches for all 
<input type=text> elements and then attaches an EventDispatcher based on 
DIID_HTMLInputTextElementEvents2 to each of the InputText elements.  All 
this is working fine now.

With the EventDispatcher, I'm able to track the cursor/caret location as the 
user types into each of the InputText elements.  What I'm ultimately trying 
to do is to maintain the curser/caret position for each of the InputText 
elements as they go in and out of focus, just as with standard WIN32 edit 
boxes.  Try as I might, I can't get this to happen.  Below is the ONFOCUS 
event handler used for the InputText elements.  The "CaretPos" value that is 
passed in is unique to whatever InputText element fired the event(I've 
verified this).

After this event handler executes and indicates that the cursor/caret has 
infact been moved, the text in the InputText element is fully selected 
(default behavior).

What am I missing? or is this not Possible?

Thanks
James O'Brien





//---------------------------------------------------------------------------
void TDHTMLForm::ElementCTRL_OnFocus(T_IHTMLElement &pElement, 
T_IHTMLEventObj &pElementEvent, long *CaretPos)
{
           BSTR  bstr;

            long  pos;

             T_IDispatch  Dispatch;
             T_IDispatch  Range;

        T_IHTMLDocument2  Doc;

 T_IHTMLInputTextElement  InputText;

  T_IHTMLSelectionObject  Selection;
         T_IHTMLTxtRange  TextRange;


  //get IHTMLInputTextElement interface
  if(SUCCEEDED(pElement->QueryInterface(IID_IHTMLInputTextElement,(LPVOID*)&InputText))){


      //get IID_IHTMLDocument2 interface
      pElement->get_document(&Dispatch);
      if(SUCCEEDED(Dispatch->QueryInterface(IID_IHTMLDocument2, 
(LPVOID*)&Doc))){

         //get IID_IHTMLTxtRange interface
         Doc->get_selection(&Selection);
         Selection->createRange(&Range);
         if(SUCCEEDED(Range->QueryInterface(IID_IHTMLTxtRange, 
(LPVOID*)&TextRange))){

            //get existing select text and display main window's statusbar
            if(SUCCEEDED(TextRange->get_text(&bstr))){
               INPUT_Status->Panels->Items[1]->Text=bstr;
               ::SysFreeString(bstr);
            }

            //attempt to create empty slection and move to location secified 
by CaretPos
            if(SUCCEEDED(TextRange->move(WideString("character"), *CaretPos, 
&pos))){

               //Display where the cursor now be, into main window's 
statusbar
               A.sprintf("Cursor should be at position %d.", pos);
               INPUT_Status->Panels->Items[2]->Text = A;
               INPUT_Status->Refresh();

            }

         }
      }

  }
  return;
}
//---------------------------------------------------------------------------
Technical Details
Message-ID: <420d1f09@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,b4f655a4eb3bf0d7,start
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "James O'Brien" <obrien@niscnet.com>
From: "James O'Brien" <obrien@niscnet.com>
Newsgroups: borland.public.cppbuilder.internet.web
Subject: DISPID_HTMLELEMENTEVENTS2_ONFOCUS :: How to force text insertion point(caret position) of a input text box
Date: Fri, 11 Feb 2005 16:09:29 -0500
Lines: 97
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 66.134.39.197
Message-ID: <420d1f09@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1108156169 66.134.39.197 (11 Feb 2005 13:09:29 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail