CEdit::CharFromPos 
Author Message
 CEdit::CharFromPos

Did anyone ever use CEdit::CharFromPos(CPoint pt)?  Is it only supported
in Window95?

I'm doing deveopment in NT4.0/VC5.0.  In the current project, I need to
drag an item from a list control to a edit contrl.  In the
CListControl::OnLButtonUp(), (CListControl is a derived class based on
CListCtrl), I called DropItemOnEdit() to determine where should I insert
the item into the edit control.

Even though, I'm pretty sure that the cursor (pt) is within the
edit control rectangle, however, when I used pDropEdit->CharFromPos(pt),
I keep on getting return code = -1.

Here is the example code of DropItemOnEdit()....

void CListControl::DropItemOnEdit(CEdit *pDropEdit, CPoint pt)
{
        .....
        CRect rect;
        CPoint winpt(pt);

        pDropEdit->GetWindowRect(&rect);
        ClientToScreen(&winpt);
        // Make sure the point is not outside the rectangle of
        // edit control
        ASSET(rect.PtInRect(winpt)!= 0);
        ret = pDropEdit->CharFromPos(pt);
        ...

Quote:
}

Thanks in advance for any advice.

Joyce



Sat, 04 Dec 1999 03:00:00 GMT  
 CEdit::CharFromPos


Quote:
>Did anyone ever use CEdit::CharFromPos(CPoint pt)?  Is it only supported
>in Window95?

Your fears are correct, it _is_ only implemented in Windows 95.

In VC 4.x, the help for the message in question (EM_CHARFROMPOS) actually
documented this limitation (allbeit tucked away in a little popup window),
but the VC5 help appears to have removed this window, but I don't suppose
that it's removed the limitation.

You'll just have to implement it manually for NT.

Tedious, huh?

Cheers

Keith
O----------------oOo----------------O

| Analyst/Programmer                |
| Pathtrace Engineering Systems Ltd |
| http://www.pathtrace.com          |
O----------------oOo----------------O



Mon, 06 Dec 1999 03:00:00 GMT  
 CEdit::CharFromPos

Joyce,

You've converted from client to screen, but do you need to re-convert
back to the client area of the edit control? CharFromPos implies that
the point is relative to the edit control's client area. If you run
through your code with the de{*filter*} and check the co-ordinate values
it might make more sense.

Dave
----
Address is altered to discourage junk mail.
Remove ".---" for the real address.
http://www.*-*-*.com/



Mon, 06 Dec 1999 03:00:00 GMT  
 CEdit::CharFromPos

I've got a CEdit::CharFromPos() that I wrote to work in Win 3.1 and Mac
that may
well work in NT.  Here it is:

int CEditXXX::CharFromPos(CPoint pt)
{
#ifndef _MAC
        if (!Win32sLoaded())
                return CEdit::CharFromPos(pt);
#endif
        //      Win32s and Mac don't have CharFromPos().  So we do our own.
        //      Find the line that the point pt is in.
        int             iLine = 0;
        int             iLineCount = GetLineCount();
        int             iOneLineHeight = theApp.m_iEditControlLineHeight;
        BOOL    bFound = FALSE;
        while (iLine < iLineCount) {
                int i = iLine * iOneLineHeight;
                if (i == pt.y) {
                        bFound = TRUE;
                        break;
                }
                ++iLine;
        }
        if (!bFound)
                return 0;       //      In case we didn't find the line.

        //      We've found the line belonging to pt.y, not find
        //      the offset within the line that belongs to pt.x
        int iLineIndex = LineIndex(iLine);
        if (iLineIndex == -1)
                return 0;       //      In case of error.
        char    buffer[1000];
        int             iCharsInLine = GetLine(iLine, buffer, 999);
        if (iCharsInLine == 0)
                return 0;       //      In case of error.
        int             index = 0;
        int             iLastCX = 0;
        CSize   szSize;
        if (pt.x != 0) {
                CDC*    pDC = GetDC();
                pDC->SelectObject(theApp.m_pEditControlFont);
                do {
                        szSize = pDC->GetTextExtent(buffer, index+1);
                        if (szSize.cx >= pt.x) {
                                //      We are past the point.  Find out which is
                                //      closer to pt.x.  If iLastCX is closer, then
                                //      we want the previous index.  If szSize.cx
                                //      is closer, then we want the current index.
                                if (pt.x-iLastCX+2 < szSize.cx-pt.x)
                                        --index;
                                break;
                        }
                        iLastCX = szSize.cx;
                        ++index;
                } while (index < iCharsInLine);
                ++index;
                ReleaseDC(pDC);
        }
        index += iLineIndex;
        return index;

Quote:
}

--
Paul Jakoubek
Information Transform Inc.



Quote:

> >Did anyone ever use CEdit::CharFromPos(CPoint pt)?  Is it only supported
> >in Window95?

> Your fears are correct, it _is_ only implemented in Windows 95.

> In VC 4.x, the help for the message in question (EM_CHARFROMPOS) actually
> documented this limitation (allbeit tucked away in a little popup
window),
> but the VC5 help appears to have removed this window, but I don't suppose
> that it's removed the limitation.

> You'll just have to implement it manually for NT.

> Tedious, huh?

> Cheers

> Keith
> O----------------oOo----------------O

> | Analyst/Programmer                |
> | Pathtrace Engineering Systems Ltd |
> | http://www.pathtrace.com          |
> O----------------oOo----------------O



Tue, 07 Dec 1999 03:00:00 GMT  
 CEdit::CharFromPos

Quote:
>Your fears are correct, it _is_ only implemented in Windows 95.

Keith,

I've not tested this myself, are you sure?

I'd have thought that the docs for VC4 mentioned this because it
wasn't in NT3.5x, but perhaps the docs for 5 have been changed because
it is available under NT4.

Dave
----
Address is altered to discourage junk mail.
Remove ".---" for the real address.
http://www.bj.co.uk



Tue, 07 Dec 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Workaround for CEdit::CharFromPos (final!)

2. CEdit::CharFromPos workaround: almost there ... one more problem

3. CEdit::CharFromPos -- trying to write a bugfix, please help (having problems with tabs)

4. CEdit::CharFromPos failing for large text, need help

5. CRichEditCtrl & CharFromPos

6. CharFromPos and GetCaretPos usage

7. CEdit box ** CEdit box ** CEdit box

8. Default CEdit::OnPaint () and CEdit's Parent Window

9. CEdit on top of another CEdit control

10. CEdit - How do I turn OFF word wrapping on a multi-line CEdit?

11. CEdit: How do you detect cursor movement when a CEdit has focus?

12. Overriding CEdit default behavior

 

 
Powered by phpBB® Forum Software