Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor position in InkEdit box 1

Status
Not open for further replies.

Alt255

Programmer
May 14, 1999
1,846
US
Is it possible to retrieve the cursor position from the MouseMove event of an InkEdit control? It's easy using a Richtext box but I need to display Hebrew and Greek characters. VB6

Add water (makes its own sauce).
 
>I need to display Hebrew and Greek characters

The RichjTextbox control can display Greek and Hebrew characters. Just not though the usual interface provided to VB6 ...

What you want to do is get the Text Object Model's (TOM) ITextDocument interface from the underlying RichEdit control. See my GetFirstWords function in thread222-1383606 for a nudge in the right direction.

And, of course, once you've got that working, you can then simply use your existing RTB code to retrieve the cursor position.
 
Thanks for your reply, strongm. I see a way to set the language ID of a text selection to Hebrew or Greek but I don't see a way to display a file containing a mixture of both. The Microsoft docs at are for C++ users and I'm sure that I am missing something. How might I use TOM to display English, Hebrew and Greek in the same box?


Add water (makes its own sauce).
 
Sorry, Mike. I was looking in the wrong direction (repeatedly). I just had to open the files using the UTF-8 codepage. That was silly. :)
In the unlikely event that somebody would ever have the same problem, here's what I did (using some of your code):

Dim myIUnknown As IUnknown
Dim tomDoc As ITextDocument

SendMessage rtbText.hWnd, EM_GETOLEINTERFACE, 0&, myIUnknown
Set tomDoc = myIUnknown

tomDoc.open app.Path & "\testHebrew_Greek.txt", tomText, 65001

Thank you for pointing me in the right direction.

Add water (makes its own sauce).
 
>I see a way to set the language ID of a text selection to Hebrew or Greek

Shouldn't need to do that, necessarily. What is the source of your Greek and Hebrew? Are you reading from text files? Do those files already contain a mixture of Greek , Hebrew and English?

Here. for example, is an InkEdit control loaded from two UTF-8 text files, one Greek, one Hebrew (the Hebre files has some English text as well, just to demo we can show all three)

greekhebrewe_yppjte.png


And this is the code that does it:

Code:
[blue]Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_USER = &H400&
Private Const EM_GETOLEINTERFACE = (WM_USER + 60)

[COLOR=green]' Loads Greek and Hebrew UTF-8 text files into an InkEdit control, using the InkEdit's TOM interface[/color]
Private Sub CommandLoad_Click()
    Dim myIUnknown As IUnknown '
    Dim tomDoc As ITextDocument
    Dim myText As String
    
    SendMessage InkEdit1.hwnd, EM_GETOLEINTERFACE, 0&, myIUnknown
    Set tomDoc = myIUnknown
    
    Dim objStream, strData

    Set objStream = CreateObject("ADODB.Stream") [COLOR=green]' Needed so VB(A) can deal with UTYF-8[/color]
    objStream.Charset = "utf-8"

    objStream.Open
    objStream.LoadFromFile ("g:\downloads\hebrew.txt") 
    myText = objStream.ReadText()
    objStream.Close
    tomDoc.Selection = myText

    objStream.Open
    objStream.LoadFromFile ("g:\downloads\greek.txt")
    myText = objStream.ReadText()
    tomDoc.Selection.Collapse 0
    tomDoc.Selection = myText

    objStream.Close
    Set objStream = Nothing

End Sub[/blue]

And then it occurred to me that perhaps we don't actually need TOM at all .... So here is code that achgieves the same effect without TOM

Code:
[blue]Private Sub CommandLoad2_Click()
    Dim myText As String
    Dim objStream, strData

    Set objStream = CreateObject("ADODB.Stream")
    objStream.Charset = "utf-8"

    objStream.Open
    objStream.LoadFromFile ("g:\downloads\hebrew.txt")
    myText = objStream.ReadText()
    objStream.Close
    InkEdit1.SelText = myText

    objStream.Open
    objStream.LoadFromFile ("g:\downloads\greek.txt")
    myText = objStream.ReadText()
    InkEdit1.SelText = myText

    objStream.Close
    Set objStream = Nothing

End Sub[/blue]
 
> I just had to open the files using the UTF-8 codepage.

Yep :)

>tomDoc.open app.Path & "\testHebrew_Greek.txt", tomText, 65001


yep, that was my original thinking. But there are some issues with it - for example you cannot simply append from another file, hence my change to simply inserting the text (which as illustrated above) works fine with just an Inkedit control's normal interface.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top