Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Saving multiple RTFs to string for storage?

Saving multiple RTFs to string for storage?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++data-structureslearning
2 Posts 2 Posters 0 Views 1 Watching
  • 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.
  • K Offline
    K Offline
    Kayembi
    wrote on last edited by
    #1

    Hi, I'm writing a program that incorporates a Rich Edit control text editor containing consisting of an arbitrary number of "documents". On the left of the screen is a tree view, and on the right of the screen is a rich edit control for text editing. The user uses the tree view to create new "documents". By clicking on a tree view item, the document that that represents should appear in the rich text control on the right. All of this has to be saved to a single file (possibly using structs), and exported to an RTF. Saving to RTF is sorted (thanks to help from users here), but my problem is this: How can I save an entire "document" to a string? I have tried saving to a char*, but I haven't got it working. Note that I am using _no_ MFC, and I am not a very experienced programmer - I am still on a steep learning curve, so please forgive any idiocy in my code. This is what I tried: char* szTextTest; long nTest; static DWORD CALLBACK MyStreamInStringCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) { memcpy(pbBuff,szTextTest,nTest); *pcb = cb; return 0; } void LoadRTFFromString(HWND hWnd, int nIDDlgItem) { EDITSTREAM es; es.pfnCallback = MyStreamInStringCallback; SendDlgItemMessage(hWnd,nIDDlgItem,EM_STREAMIN,SF_RTF,(LPARAM)&es); } static DWORD CALLBACK MyStreamOutStringCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) { nTest = cb; szTextTest = new char[cb]; memcpy(szTextTest,pbBuff,cb); *pcb = cb; return 0; } void SaveRTFToString(HWND hWnd, int nIDDlgItem) { EDITSTREAM es; es.pfnCallback = MyStreamOutStringCallback; SendDlgItemMessage(hWnd,nIDDlgItem,EM_STREAMOUT,SF_RTF,(LPARAM)&es); } Even if I could get the above working, would I be able to save the character pointer, szTextText, to file using WriteFile() and have it save all the text it has been allocated? I have only ever saved structures containing chars that aren't pointers to file so far... If I can copy the whole of a formatted RTF file to a string, this is what I am thinking of doing to save the structure: For each folder, copy text into the string such as "{{folder:name_of_folder;}}" or some such, and then add to the end of that the rich text that is associated with that folder. When reloading from file, I just need to search the string for occurrences such as "{{folder::...}}" etc in order to rebuild my treeview and associate text appropriately. Thus the string created to hold the rich text needs to be infinitely long - or

    J 1 Reply Last reply
    0
    • K Kayembi

      Hi, I'm writing a program that incorporates a Rich Edit control text editor containing consisting of an arbitrary number of "documents". On the left of the screen is a tree view, and on the right of the screen is a rich edit control for text editing. The user uses the tree view to create new "documents". By clicking on a tree view item, the document that that represents should appear in the rich text control on the right. All of this has to be saved to a single file (possibly using structs), and exported to an RTF. Saving to RTF is sorted (thanks to help from users here), but my problem is this: How can I save an entire "document" to a string? I have tried saving to a char*, but I haven't got it working. Note that I am using _no_ MFC, and I am not a very experienced programmer - I am still on a steep learning curve, so please forgive any idiocy in my code. This is what I tried: char* szTextTest; long nTest; static DWORD CALLBACK MyStreamInStringCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) { memcpy(pbBuff,szTextTest,nTest); *pcb = cb; return 0; } void LoadRTFFromString(HWND hWnd, int nIDDlgItem) { EDITSTREAM es; es.pfnCallback = MyStreamInStringCallback; SendDlgItemMessage(hWnd,nIDDlgItem,EM_STREAMIN,SF_RTF,(LPARAM)&es); } static DWORD CALLBACK MyStreamOutStringCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) { nTest = cb; szTextTest = new char[cb]; memcpy(szTextTest,pbBuff,cb); *pcb = cb; return 0; } void SaveRTFToString(HWND hWnd, int nIDDlgItem) { EDITSTREAM es; es.pfnCallback = MyStreamOutStringCallback; SendDlgItemMessage(hWnd,nIDDlgItem,EM_STREAMOUT,SF_RTF,(LPARAM)&es); } Even if I could get the above working, would I be able to save the character pointer, szTextText, to file using WriteFile() and have it save all the text it has been allocated? I have only ever saved structures containing chars that aren't pointers to file so far... If I can copy the whole of a formatted RTF file to a string, this is what I am thinking of doing to save the structure: For each folder, copy text into the string such as "{{folder:name_of_folder;}}" or some such, and then add to the end of that the rich text that is associated with that folder. When reloading from file, I just need to search the string for occurrences such as "{{folder::...}}" etc in order to rebuild my treeview and associate text appropriately. Thus the string created to hold the rich text needs to be infinitely long - or

      J Offline
      J Offline
      John M Drescher
      wrote on last edited by
      #2

      Kayembi wrote: Thus the string created to hold the rich text needs to be infinitely long - or rather, it needs to be capable of holding formatted text that could run into the 100,000s of *words*. Use string or better yet use this: http://www.codeproject.com/string/stdstring.asp?target=CStdString[^] John

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups