Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How using code from MSVC C++
Forum Updated to NodeBB v4.3 + New Features

How using code from MSVC C++

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 637 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on 22 Jan 2019, 08:06 last edited by
    #1

    Hi!
    I have this code [this code(https://www.experts-exchange.com/articles/3096/Convert-RTF-to-HTML-and-HTML-to-RTF.html).
    How I con using this code in QT?

    // Rtf2Html.cpp : Defines the entry point for the console application. 
    // 
    #include "stdafx.h" 
    #include "Rtf2Html2.h" 
    #include "afxhtml.h" 
     
    CWinApp theApp;  // Win32 App with MFC support 
     
    CRichEditCtrl g_ctlRichEdit;  // the two controls 
    CHtmlEditCtrl g_ctlEditHtml; 
     
    // This is needed to load the RichEdit control from a file 
    static DWORD CALLBACK  
    MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) 
    { 
       CFile* pFile = (CFile*) dwCookie; 
       *pcb = pFile->Read(pbBuff, cb); 
       return 0; 
    } 
     
    void LoadRtfFile( LPCTSTR pszFilename ) 
    { 
        wchar_t szFilter[] = L"RTF files (*.rtf)|*.rtf;|" 
                             L"All Files (*.*)|*.*||"; 
        CFileDialog dlg(TRUE,0,pszFilename,6,szFilter ); 
        if ( dlg.DoModal()!=IDOK ) { 
            return; 
        } 
        CFile cf( dlg.GetPathName(),CFile::modeRead ); 
     
        // CFile cf( pszFilename,CFile::modeRead ); 
        EDITSTREAM es; 
        es.dwCookie = (DWORD)&cf; 
        es.pfnCallback = MyStreamInCallback;  
        g_ctlRichEdit.StreamIn( SF_RTF, es ); // load from the file 
    } 
     
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) 
    { 
        AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0); 
        AfxInitRichEdit2(); // needed for using CRichEditCtrl 
     
        CWnd* pWnd = CWnd::GetDesktopWindow(); 
        CRect r(0,0,200,200); 
     
        g_ctlRichEdit.Create( ES_MULTILINE, r, pWnd, 1111); 
        g_ctlEditHtml.Create( 0,0, r, pWnd, 2222 ); 
     
        LoadRtfFile( argv[1] );     // read the RTF file into the ctrl  
        g_ctlRichEdit.SetSel(0,-1); // select all in the RTF ctrl 
        g_ctlRichEdit.Copy();       // copy to clipboard 
        g_ctlEditHtml.Paste();      // paste into the Html Edit ctrl 
        g_ctlEditHtml.SaveAs( L"C:\\temp\\test.html");  // save HTML 
     
        return 0; 
    }
    
    J 1 Reply Last reply 22 Jan 2019, 08:50
    0
    • M Mikeeeeee
      22 Jan 2019, 08:06

      Hi!
      I have this code [this code(https://www.experts-exchange.com/articles/3096/Convert-RTF-to-HTML-and-HTML-to-RTF.html).
      How I con using this code in QT?

      // Rtf2Html.cpp : Defines the entry point for the console application. 
      // 
      #include "stdafx.h" 
      #include "Rtf2Html2.h" 
      #include "afxhtml.h" 
       
      CWinApp theApp;  // Win32 App with MFC support 
       
      CRichEditCtrl g_ctlRichEdit;  // the two controls 
      CHtmlEditCtrl g_ctlEditHtml; 
       
      // This is needed to load the RichEdit control from a file 
      static DWORD CALLBACK  
      MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) 
      { 
         CFile* pFile = (CFile*) dwCookie; 
         *pcb = pFile->Read(pbBuff, cb); 
         return 0; 
      } 
       
      void LoadRtfFile( LPCTSTR pszFilename ) 
      { 
          wchar_t szFilter[] = L"RTF files (*.rtf)|*.rtf;|" 
                               L"All Files (*.*)|*.*||"; 
          CFileDialog dlg(TRUE,0,pszFilename,6,szFilter ); 
          if ( dlg.DoModal()!=IDOK ) { 
              return; 
          } 
          CFile cf( dlg.GetPathName(),CFile::modeRead ); 
       
          // CFile cf( pszFilename,CFile::modeRead ); 
          EDITSTREAM es; 
          es.dwCookie = (DWORD)&cf; 
          es.pfnCallback = MyStreamInCallback;  
          g_ctlRichEdit.StreamIn( SF_RTF, es ); // load from the file 
      } 
       
      int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) 
      { 
          AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0); 
          AfxInitRichEdit2(); // needed for using CRichEditCtrl 
       
          CWnd* pWnd = CWnd::GetDesktopWindow(); 
          CRect r(0,0,200,200); 
       
          g_ctlRichEdit.Create( ES_MULTILINE, r, pWnd, 1111); 
          g_ctlEditHtml.Create( 0,0, r, pWnd, 2222 ); 
       
          LoadRtfFile( argv[1] );     // read the RTF file into the ctrl  
          g_ctlRichEdit.SetSel(0,-1); // select all in the RTF ctrl 
          g_ctlRichEdit.Copy();       // copy to clipboard 
          g_ctlEditHtml.Paste();      // paste into the Html Edit ctrl 
          g_ctlEditHtml.SaveAs( L"C:\\temp\\test.html");  // save HTML 
       
          return 0; 
      }
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 22 Jan 2019, 08:50 last edited by
      #2

      @Mikeeeeee said in How using code from MSVC C++:

      How I con using this code in QT?

      Well, copy paste and change what needs to be changed.
      Your question is too generic.
      For example remove this CWinApp thing and use QApplication instead.
      This code uses some libraries (Rtf2Html2, afxhtml) you will need to add them to your project if there is no replacement in Qt.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3

      1/2

      22 Jan 2019, 08:06

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved