in

AisNote Software

The software can improve your computer work

Great Windows Tool

RTF file research tips

  1. Convert Chinese to Ansii string

        7 int main(int argc, char* argv[])

        8 {

        9     printf("Hello World!\n");

       10 

       11     char chTest[]="电";

       12     int n1 = (unsigned char)(chTest[0]) << 8;

       13     int n2 = (unsigned char)chTest[1];

       14 

       15     int   i   =   n1+n2;  

       16     char   a[3];  

       17     a[0]   =   (char)((i   &   0xff00)   >>   8);  

       18     a[1]   =   (char)(i   &   0xff);  

       19     a[2]   =   0;  

       20     printf("%s\n",a);

       21 

       22     return 0;

       23 }

  2. Some Links:
    rtflib from www.codeproject.com
    rtfx   you can google it.
    latex2rtf from www.sourceforge.net
    gc1039.exe from www.msdn.com.  It will give you some info about how to read rtf file directly using c++.
    http://msdn.microsoft.com/en-us/library/aa140301.aspx
    abiword http://www.abisource.com/   There are a RTF importer/Exporter plugin source code.But I do not familiar with it.
    I think in Windows Platform,you can use RichEdit control to do the below actions:
    Merge 2+ rtf files to one rtf file just use copy and paste,of course you should use TOM or just create 2 hidden richEdt box to switch the data.That is easy.Also you can find the plain text from RTF use EM_GETTEXTEX and stream out a butter then go to find the string what you want catch.
    http://www.codeproject.com/KB/edit/COleRichEditCtrl.aspx?msg=2915564#xx2915564xx  Good sample for OLE such as insert PPT file etc.

  3. RTF have the advantage and disadvantage.I recommended you to use HTML,XML etc.But RTF is good supported by MS.

  4. Search Text:

      497         kREView* pRE = m_view.GetAt(m_view.Active());

      498         if ( pRE )

      499         {

      500             pRE->Load(_T("d:\\dd.rtf"));

      501 

      502             DWORD dwSize = pRE->GetTextLengthEx(GTL_NUMBYTES | GTL_CLOSE, CP_ACP);

      503 

      504             TCHAR *lpszBuffer = new TCHAR[dwSize+2];

      505             memset(lpszBuffer,0,(dwSize+2)*sizeof(TCHAR));

      506 

      507             GETTEXTEX ex = {0};

      508             ex.cb = dwSize+2;

      509             ex.codepage = CP_ACP ;

      510             ex.flags = GT_DEFAULT;

      511 

      512             pRE->GetTextEx(&ex,lpszBuffer);

      513 

      514             CString str = lpszBuffer ;

      515             int nRet = str.Find(_T("我的"));

      516             delete []lpszBuffer ;

      517         }

  5. Directly Get or Set RTF content to a RTF ediotor.Prototype code is below:
    http://www.codeproject.com/KB/edit/rulerricheditctrl.aspx 

    CString CRulerRichEditCtrl::GetRTF()
    /* ============================================================
        Function :        CRulerRichEditCtrl::GetRTF
        Description :    Returns the contents of the control as RTF.
        Access :        Public
        Return :        CString    -    The RTF-contents of the control.
        Parameters :    none

        Usage :            Call this function to get a char buffer
                        with the contents of the embedded RTF-
                        control.

       ============================================================*/
    {

        CString* str = new CString;
        EDITSTREAM    es;
        es.dwCookie = ( DWORD ) str;
        es.pfnCallback = StreamOut;
        m_rtf.StreamOut( SF_RTF, es );

        CString output( *str );
        delete str;

        return output;

    }

    void CRulerRichEditCtrl::SetRTF( const CString& rtf )
    /* ============================================================
        Function :        CRulerRichEditCtrl::SetRTF
        Description :    Set the contents of the embedded RTF-
                        control from rtf.
        Access :        Public
        Return :        void
        Parameters :    const CString& rtf    -    The rtf-contents to
                                                set.
        Usage :            Call this function to set the RTF-contents
                        of the control.

       ============================================================*/
    {

        CString* str = new CString( rtf );

        EDITSTREAM    es;
        es.dwCookie = ( DWORD ) str;
        es.pfnCallback = StreamIn;
        m_rtf.StreamIn( SF_RTF, es );

        delete str;

    }


    static DWORD CALLBACK StreamIn( DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb )

    {
          
    CString* str = ( ( CString* ) dwCookie );

    #ifdef _UNICODE
          
    // Unicode is only supported for SF_TEXT, so we need

           // to convert
           LPCTSTR ptr = str->GetBuffer( (*str).GetLength() );
           int
    length = ::WideCharToMultiByte( CP_UTF8, 0, ptr, -1, NULL, 0, NULL, NULL );
           int
    max = min( cb, length );
           if(
    length )
           {
                  char*
    buff = new char[ length ];
                  ::
    WideCharToMultiByte( CP_UTF8, 0, ptr, -1, buff, length + 1, NULL, NULL );
                 
    strncpy( (LPSTR) pbBuff, buff, max );
                  delete[]
    buff;
           }
          
    str->ReleaseBuffer();

    #else

           int
    max = min( cb, (*str).GetLength() );
          
    strncpy( ( LPSTR ) pbBuff, (*str) , max  );

    #endif

           (*
    str) = (*str).Right( (*str).GetLength() - max );
           *
    pcb = max;
           return 0;
    }



     

Comments

 

ilite said:

great article

July 30, 2008 6:53 AM

Leave a Comment

(required)  
(optional)
(required)  
Add
aisnote software
Powered by Community Server (Non-Commercial Edition), by Telligent Systems