Announcement

Collapse
No announcement yet.

GetCharacterPlacement and GetCaretPos

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GetCharacterPlacement and GetCaretPos

    Has anyone ever used GetCharacterPlacement? It could be very useful
    in text processing or a pseudo-word processing operation. Searching the
    PowerBasic forums yielded nothing.

    I have tried all sorts of things, but not having any Windows books
    doesn't help a lot. For the same reason, this first bit of code is a
    tortured version of getting the caret position (it works). All this code
    is in the subclassed procedure for the dialog's edit controls.


    Static Cpos As POINTAPI
    Local bfx As Asciiz * 100
    Local Xcp As GCP_RESULTS

    In the Case %WM_KEYUP, this is in a piece which handles text input,
    excluding ENTER/TAB and the like, to get the caret position:

    Control Get Text sDlg&, CurrLine& To s$
    GetCaretPos Cpos
    Cp&=Cpos.x
    Xp&=Cp&
    Xy&=Cpos.y
    If Cp&>cxChar&/4 Then Cp&=Cp&-(cxChar&/4)
    x&=SendMessage (hWnd&, %EM_CHARFROMPOS, 0, Cp&)
    SetCaret&=x&
    n&=Len(s$) 'gets the right character, too!
    key$=Mid$(s$,x&,1) '(but NOT with 10 i's in front ... )

    This bit is the GetCharacterPlacement effort.

    hdc& = GetDC (hWnd&)
    nct&=Len(s$)

    Dim gcr&(nct&), crp&(nct&)

    ' Type GCP_RESULTS
    ' lStructSize As Long
    ' lpOutString As Asciiz Ptr
    ' lpOrder As Long
    ' lpDX As Long
    ' lpCaretPos As Long
    ' lpClass As Asciiz Ptr
    ' lpGlyphs As Asciiz Ptr
    ' nGlyphs As Long
    ' nMaxFit As Long
    ' End Type

    xcp.lStructSize = SizeOf(xcp)
    xcp.lpOutString = %NULL
    xcp.lpOrder = %NULL
    xcp.lpDX = VarPtr(gcr&(1))
    xcp.lpCaretPos = VarPtr(crp&(1))
    xcp.lpClass = %NULL
    xcp.lpGlyphs = %NULL
    bfx=s$ '(same s$ as above, i.e., text from edit control)

    Call GetCharacterPlacement(hdc&, bfx, nct&, 0, xcp, 0)
    Call ReleaseDC (hWnd&, hdc&)
    pn& = crp&(10)

    MsgBox(Str$(nct&)+Str$(pn&)+Str$(hWnd&)+Str$(gcr&(11))+Str$(crp&(11))+Str$(xcp.nMaxFit)+" / "+bfx)

    ' call GetCharacterPlacement(HDC hdc, _ 'Handle To device context
    ' LPCTSTR lpString, 'pointer To String
    ' Int nCount, 'number of characters In ' 'String
    ' Int nMaxExtent, 'maximum extent For 'displayed String
    ' LPGCP_RESULTS *lpResults, 'pointer To 'buffer For placement result
    ' Dword dwFlags 'placement flags

    The two arrays (gcr&() for character placement and crp&() for caret
    position) show nothing.

    Any suggestions would be greatly appreciated.


    ------------------
Working...
X