Print Page | Close Window

CRichEditCtrl - RTF - BIG - Help

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=12197
Printed Date: 26 May 2025 at 12:57am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CRichEditCtrl - RTF - BIG - Help
Posted By: barobax
Subject: CRichEditCtrl - RTF - BIG - Help
Date Posted: 18 September 2008 at 2:46pm
Hi,
I have a problem with CRichEditCtrl in MFC. I want to get char under mouse cursor.I use charFrompos but when I set a RTF format to RE this will not work.

    int nPos = CRichEditCtrl::CharFromPos(point);
    int nLine = HIWORD(nPos);// it's zero always when I set an RTF string. RTF replace \par with \n
    int nIndex = LOWORD(nPos);
    CString sText;
    CRichEditCtrl::GetWindowText(sText);
    char pChar1 = sText[nIndex]; //it's not char under mouse cursor.
    char pChar2 = m_RTFText[nIndex]; //it's not char under mouse cursor too.

The codejock have a subclass from CRichEditCtrl ?!? or any other help at your experience ?!?

Thanks,
Best Regards,



Replies:
Posted By: znakeeye
Date Posted: 19 September 2008 at 5:55am
Not sure, but beware of "\r\n" for linebreaks. CharFromPos is not dependent of the underlying RTF.


Posted By: barobax
Date Posted: 19 September 2008 at 9:48am
Hi,
Thank you very much for your answer but my problem not solved


Posted By: barobax
Date Posted: 20 September 2008 at 4:34pm
Hi,This is my Method.
EDITSTREAM EnEnWriter::GetRTF()
{
    CTime time;
    int sec1 = time.GetSecond();
    m_sRTF = L"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharset0 Arial;}}{\\colortbl ;\\red0\\green0\\blue128;\\red0\\green0\\blue255;\\red0\\green128\\blue0;\\red128\\green0\\blue0;}{\\*\\generator Msftedit 5.41.21.2508;}\\viewkind4\\uc1\\pard\\f0\\fs20" + m_sRTF;
    m_sRTF.Replace(L"\r\n", L"\\par"); // If this line is commented, charfrompos work correctly else wrong.
    int nLength = m_sRTF.GetLength();
    /////////////////////////Etymology///////////////////////////
    int nIndex = 0;
    nIndex = m_sRTF.Find(L"Etymology", nIndex);
    while (nIndex != -1)
    {
        m_sRTF.Insert(nIndex, L"\\cf1");
        nIndex += 13;
        m_sRTF.Insert(nIndex, L"\\cf0");
        nIndex = m_sRTF.Find(L"Etymology", nIndex);
    }
    ////////////////////////Functions////////////////////////////
    nIndex = 0;
    nIndex = m_sRTF.Find(L"transitive verb", nIndex);
    while (nIndex != -1)
    {
        m_sRTF.Insert(nIndex, L"\\cf2");
        nIndex += 19;
        m_sRTF.Insert(nIndex, L"\\cf0");
        nIndex = m_sRTF.Find(L"transitive verb", nIndex);
    }
    ////////////////////////Comments////////////////////////////
    nIndex = 0;
    nIndex = m_sRTF.Find(L"<", nIndex);
    while (nIndex != -1)
    {
        m_sRTF.Insert(nIndex, L"\\cf3");
        nIndex = m_sRTF.Find(L">", nIndex);;
        if (nIndex != -1)
        {
            m_sRTF.Insert(nIndex + 1, L"\\cf0");
            nIndex = m_sRTF.Find(L"<", nIndex);
        }
    }
    int final = (time.GetSecond() - sec1);
    EDITSTREAM pStream;
    pStream.dwCookie = (DWORD)&m_sRTF; // Pass a pointer to the CString to the callback function
    pStream.pfnCallback = StreamInCallback; // Specify the pointer to the callback function
    return pStream;
}


-------------
(Farsi IS WRONG you must say [PARSI])



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net