I am trying to convert the following code to VB .Net, I still have some
gaps (the lines that are marked with (*))
and also I need an ending condition for the while loop.
any help would be appreciated.
Thanks. Atara.
-------------------------
Original code:
-------------------------
void highLight(IHTMLDocumentPtr doc, const CString& highlightText, bool
bHighLight, const CString& highlightAttr)
{
//Usage: highLight(pHTMLDoc, _T("google"), _T("COLOR=#0000ff "));
CComQIPtr<IMarkupServices> pMS;
CComQIPtr<IMarkupContainer> pMC;
CComPtr<IMarkupPointer> ptrBegin, ptrEnd;
_bstr_t attr(highlightAttr);
_bstr_t textToFind(highlightText);
pMS = doc;
pMC = doc;
if(pMS && pMC)
{
pMS->CreateMarkupPointer(&ptrBegin);
pMS->CreateMarkupPointer(&ptrEnd);
ptrBegin->SetGravity(POINTER_GRAVITY_Right);
ptrEnd->SetGravity(POINTER_GRAVITY_Left); // by default
ptrBegin->MoveToContainer(pMC, TRUE);
ptrEnd->MoveToContainer(pMC, FALSE);
while(TRUE)
{ // Find text
HRESULT hr = ptrBegin->FindText(textToFind, 0, ptrEnd, NULL);
if (S_FALSE == hr) break; // did not find the text
IHTMLElementPtr pFontEl;
hr = pMS->CreateElement(TAGID_FONT, attr, &pFontEl); // create
FONT element with attributes for selection
hr = pMS->InsertElement(pFontEl, ptrBegin, ptrEnd); // Insert
created element to context
ptrBegin->MoveToPointer(ptrEnd); // Continue
searching
}
}
}
-------------------------
Original code till here.
-------------------------
-------------------------
VB .Net code:
-------------------------
Dim pMS As mshtml.IMarkupServices = CType(Me.Document,
mshtml.IMarkupServices)
Dim pMC As mshtml.IMarkupContainer = CType(Me.Document,
mshtml.IMarkupContainer)
Dim ptrBegin, ptrEnd As mshtml.IMarkupPointer
Dim flags As UInt32 = Convert.ToUInt32(0)
Dim newAttr As String = " COLOR=#0000ff "
If (Not (pMS Is Nothing) And Not (pMC Is Nothing)) Then
pMS.CreateMarkupPointer(ptrBegin)
pMS.CreateMarkupPointer(ptrEnd)
ptrBegin.SetGravity(mshtml._POINTER_GRAVITY.POINTE R_GRAVITY_Right)
ptrEnd.SetGravity(mshtml._POINTER_GRAVITY.POINTER_ GRAVITY_Left)
ptrBegin.MoveToContainer(pMC, True) ' (*) Option Strict On
disallows implicit conversions from 'Boolean' to 'Integer'.
ptrEnd.MoveToContainer(pMC, False) ' (*) Option Strict On
disallows implicit conversions from 'Boolean' to 'Integer'.
Dim hr As IntPtr ' HRESULT
Dim pNewElem As mshtml.IHTMLElement ' IHTMLElementPtr
While (True) ' (*) needs break condition instead of hr, since
findText does not return value!
hr = ptrBegin.findText(searchStr, flags, ptrEnd, Nothing)
' (*) searchStr: Value of type 'String' cannot be converted to
'System.UInt16'
If (hr = S_FALSE) Then Exit While
' (*) S_FALSE is not declared,
hr = pMS.createElement(mshtml._ELEMENT_TAG_ID.TAGID_FON T,
newAttr, pNewElem) ' (*) newAttr: Value of type 'String' cannot be
converted to 'System.UInt16'
pMS.InsertElement(pNewElem, ptrBegin, ptrEnd)
ptrBegin.MoveToPointer(ptrEnd)
End While
End If
-------------------------
VB .Net code till here.
-------------------------
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!