Saving multiple RTFs to string for storage?
-
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 -
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 - orKayembi 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