Save formatted text from RichEdit control to rtf-file

Hi ,

How can I save the text from Rich edit control (2.0) to *.rtf , *.txt ,
*.doc

I tried to get the buffer and putting the buffer to file, then saving
the file

but the text in the file is something different.

Please let me know what to do?

Here is the Code I ma using:
	mFile.Seek( 0, CFile::begin );
	CString cBuffer2;
	int	 iTotalTextLength = m_oChatMessageControl.GetWindowTextLength();
	HWND focusWnd = ::GetFocus();
	m_oChatMessageControl.HideSelection(TRUE, TRUE);
	m_oChatMessageControl.SetSel(iTotalTextLength, iTotalTextLength);
	cBuffer2 = m_oChatMessageControl.GetSelText();
	LPTSTR mChatText = cBuffer2.GetBuffer();
	mFile.Write(mChatText,sizeof(mChatText));
	cBuffer2.ReleaseBuffer();

0
8/12/2006 10:21:23 AM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
846 Views

Similar Articles

[PageSpeed] 3

It's a lot more complicated than this.  You have to look at the StreamIn and StreamOut
methods of the control.

Observations about the code below...

You can't save formatted text as shown, see above comment

Showing/Hiding the selection is irrelevant.

Setting the selection is irrelevant

You can only stream the entire text in StreamOut.

Look at the examples in the MSDN for CRichEditCtrl::StreamOut.
					joe

On 12 Aug 2006 03:21:23 -0700, anup.kataria@gmail.com wrote:

>Hi ,
>
>How can I save the text from Rich edit control (2.0) to *.rtf , *.txt ,
>*.doc
>
>I tried to get the buffer and putting the buffer to file, then saving
>the file
>
>but the text in the file is something different.
>
>Please let me know what to do?
>
>Here is the Code I ma using:
>	mFile.Seek( 0, CFile::begin );
>	CString cBuffer2;
>	int	 iTotalTextLength = m_oChatMessageControl.GetWindowTextLength();
>	HWND focusWnd = ::GetFocus();
>	m_oChatMessageControl.HideSelection(TRUE, TRUE);
>	m_oChatMessageControl.SetSel(iTotalTextLength, iTotalTextLength);
>	cBuffer2 = m_oChatMessageControl.GetSelText();
>	LPTSTR mChatText = cBuffer2.GetBuffer();
>	mFile.Write(mChatText,sizeof(mChatText));
>	cBuffer2.ReleaseBuffer();
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
8/13/2006 3:48:38 AM
Reply:

Similar Artilces:

ActiveX Control: Calendar
I am using the Calendar Control 11.0 on a form to allow a user to 'pick' a date. How can i have the selected date automatically update a field where its Control Source is set to the Calendar, without having to have a intermediate step such as an update button. I can see the 'Value' changing in the Properties for the Calendar as soon as a new date is selected but the related field does not update. You don't set the texbox Control Source to the calendar, you set it to whatever field you want the date saved in in the underlying table. Then use code like this, re...

Control Source for text box on a report
I have a table with only 2 fields. One is the name of Department and the other is the total number of positions in that department. On my report I have a label for every department. Next to that label I have a text box that counts every record on my report for each department. Next to that I want to add another text box that contains the corresponding number in the table for that department. How can I easily do this? Thank You, CEV I forgot to mention that I would also like to add yet another text box that adds the total of all the other text boxes that contain the total number of ...

PDF file #7
I have Publisher 2002 and would like to insert a .pdf file into a document I am working on. How do / Can I do this? Many thanks, Ger ...

backing up files
Does anyone know if it is possible to back up my money files to a CD RW disc. Please e-mail an answer to me. Why should I email you an answer when the answer to this question has already been posted three or four times already this week? Please read the posts. "John Koegel" <bigjohn1016@mns.com> wrote in message news:044501c348bf$62e760b0$a001280a@phx.gbl... > Does anyone know if it is possible to back up my money > files to a CD RW disc. Please e-mail an answer to me. ...

No date fields appear when exporting/importing CSV file?
Hello All, I need to convert some legacy emails from another system to a format that can be read by Outlook. The preferred format is CSV text, which we plan to import into Outlook. I noticed when playing with the export/import that the following seem to be the standard fields that get exported into an Outlook generated CSV file: "Subject", "Body (text)", "From: (Name)", "From: (Address)", "From: (Type)", "To:(Name)", "To: (Address)", "To: (Type)", "CC: (Name)", "CC: (Address)", "CC: (...

Japanese text entry broken
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel Hi, <br><br>I saw an unresolved exchange about an issue that I'm now encountering. A few days ago I became unable to enter Japanese properly in Word documents. When I type in a Japanese word, the selection of kanji that match the input kana no longer comes up with the space bar. If I hit the space bar within a few hundred milliseconds of entering the text, it sometimes comes up with the correct kanji, but more often the entered text is deselected before conversion. <br><br>For instance, t...

Exchange/Outlook 2003
In an effort to make sure we never reach the 16GB threshold for the SBS 2003 Exchange Info Store, I'm looking to setup a GPO to give everyone consistent AutoArchive settings as well as a common location for the PST file. I have already downloaded the Office Administrative Templates for Outlook 2003, so I already have found the settings I want to modify and have made the changes, I just haven't made them live on the domain yet. My thoughts to date: * create two GPOs, one for the PST location, one for the autoarchive settings themselves * set PST location to local drive, or common netw...

How do I list more opened Word docs under the File menu
Word 2003 displays the last 4 Word files opened on clicking the File menu. I would like to increase this to about 20. Can this be done, and if so, how? In Word 2003, the maximum number that can be shown is 9 and it can be set via Tools>Options>General -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "Wellington" <Wellington@discussions.microsoft.com> wrote in message news:A9B8C9D4-4F78-4A92-94C6-8DC0D41388...

? Multi-Coloring Edit Controls
Hi, I need a way of placing colored text in an edit control. Currently I am doing this by handling WM_CTLCOLOR except that this allows only a single foreground and background color. I need a way of putting multiple colors in the CEdit, not just on different lines but on the same line. I checked and it seems that CEdits don't support CustomDraw. So, how can I do this? -- Alec S. alec <@> synetech <.> cjb <.> net Have you looked at CRichEditCtrl ? "Alec S." <a@a.com> wrote in message news:OjusBmpwEHA.1452@TK2MSFTNGP11.phx.gbl... >...

Excel formatting #3
Could someone please help with a macro or any other suggestion to format an Excel sheet. Basically data is downloaded from a bank every week and the size of the file can vary but the formatting is constant. That is each record is 7 lines. So first record is line1-7, second record is line 8-14, third record is line 15-21 and so on. I need to format this data and basically I can record a macro for one data set that is for the record on line 1 to 7. My question is how can I set it to replicate so that it replicates for line 8-14 and then 15-21 and so on. The source formatting remains the same...

create chart /table excel-save, close & reopen colors change? Why
When I create a chart/table in Excel - save, close & reopen to use again, the colors have changed for my formating. How do I set the formating so that the colors stay the same - I have tried styles with no luck. The colors need to be the company approved. Thank you, Anne, I am unable to reproduce yr problem. Excel should NOT override yr manual settings. However,you can set yr company colours as default under Tools/Options/[Color tab]. Here are the colours Excel uses by default for the workbook. (Under that thin line you see the defaults for fill and line colours.) Hope this...

Change Folder List Text Color (2002)
Is there anyway to change the color of the text listed in the folder view? ie - "Inbox" text color from black to red, "Sent" from black to blue" No. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without reading. After searching google.groups.com and finding no answer, jsonne@verizon.net asked: | Is there anyway to change the color of the text listed in | the folder view? ie - "Inbox" text color from b...

overlapped controls in grphical editor
Hi, I wrote a graphical editor. I have a problem with overlapped control. The user can update the control properties by double clicking on it. When the user puts a control Image(i.e.) and on that controls a Button is added, the user cannot update the button properties cause whenever it double click on the button the Image (which "contains" the button) properties is shown ... Is there any solution to that problem ? 10x, janiv. Janiv, Basically, you'll want to handle z-order. You don't describe how you implement the "buttons", if they are controls, the top-most on...

No text converter is installed for ppt
My computer is running Windows XP SP3 with Office 2007. When I try to open a PPT I get, No text converter is installed for this file type. I am sure power point is installed and was able to open and run presentations. Any help would be appreciated Thank you Regards Raj In article <195F8B98-7016-4346-A33D-91BC75E07DAE@microsoft.com>, Raj wrote: > My computer is running Windows XP SP3 with Office 2007. When I try to open a > PPT I get, No text converter is installed for this file type. I am sure power > point is installed and was able to open and run presentat...

Formula to find text and count it within an entire workbook
I have a workbook where there is nothing consistent or any named ranges. I need to make a summary sheet and count everytime I have the word cable in the entire workbook in column B. I have tried different variations of countif, lookups and find but have not come up with a combination that works. My restraint is that I can't have a macro for this workbook. I really need some help, example below. A B 1 Cable 2 FSR 3 FRK 4 Wind Meter 5 Laptop Thanks in advance, Carrie -- Message posted via http://www.officekb.com Hi, =COUNTIF($a$1:$H$5000,"*Cable*&q...

data error while opening files
when i open excel or word existing file i getting contents as "DATAError [47 0F 94 93 F4 K5]" instead of my saved data. pls help me solving. My all word & excel files are have same problem. ...

RichEdit font size.
I have a windowless rich edit and am streaming in some RTF from the clipboard. Word stores the font sizes as half point units whereas the ITextDocument seems to treat them as full point units. The result is that my pasted text is twice as big as it should be. Is this a bug in RichEdit20.dll and does anyone know how to fix it?? Cheers, MATT I have never seen this before! Are you sure that your zoom in Word is set to 100%?? Ali R. "MattDodd" <m_j_dodd_work@hotmail.com> wrote in message news:08d301c3d912$47cad620$a301280a@phx.gbl... > I have a windowless rich edit ...

Adding an Active X control to a cell
I would like to add a drop down lists to a bunch of cells. The control adds a box over the top of all the cells, trying to size it so that it fits over the top of the cell seems to be a rather inaccurate method of doing it. Hold down alt while you place it in the cell and it will fit the cell -- Regards, Peo Sjoblom "Rick" <rstenson@qualnetics.com> wrote in message news:317AA5B4-7970-45B2-8497-556670E48018@microsoft.com... > I would like to add a drop down lists to a bunch of cells. The control adds a box over the top of all the cells, trying to size it so that it f...

Cannot open Publisher File
I'm using Publisher 2003 and have a 100 MB (66 MB Compressed) publisher file that consitently hangs up publisher when trying to open it. Once in a while, the first page will load, but when you try to switch to another page, the program hangs up again. I've tried several PCs to open the file with including a P4 file server with 2 GB of RAM. nothing seems to make a difference. I can tell through the Task Manager that the app is doing some sort of processor work, but no disk access is being performed. I tried opening the file in Safe Mode and it make some slight improvements w...

integrate my vendor/supplier files from RMS and SBF into Outlook
I want to be able to see my vendor/supplier the same info in outlook, RMS and SBF I hate having to rekey the same information over and over. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGroups/dgbrowser/en-...

Long URL hard wrap in plain text e-mails in Outlook 2003
When I send an plain text e-mail in Outlook 2003 containing a long URL (beyond 76 characters), this breaks the long URL where users cannot click on the complete URL. In Outlook Express 6 SP1 I could change the plain text to Quote Printable to avoid this issue. How can I do this in Outlook 2003? I do not want to change the text format from plain text to HTML or Rich Text, I need to use plain text. Thanks. I found my answer and this solves the problem for me in Outlook 2003: Line Wrapping Does Not Appear As Expected When You Send E-Mail Messages in Outlook 2003 http://support.microsoft.c...

%s in Accounting Format
I am using Excel 2007. I want to have a column that lists percentages - but to still be able to use the accounting single underline correctly. When I manipulate the accounting format to _(*#,##0.00%_) the underlining is not correct. If I use the accounting format I cannot get "%" signs. Thanks. Does this work? _(* 0.00%_);_(* (0.00%) -- Regards, Peo Sjoblom "jadeB" <jbschipper@gmail.com> wrote in message news:a9dfe12b-3c2f-4302-ba49-2c2dd39240c2@33g2000yqm.googlegroups.com... >I am using Excel 2007. > > I want to have a column that lists percen...

combine hide row macro with conditional formatting
I'm sure one of you gurus can solve this in a flash. I've recorded a simple macro to hide a row (Alt O, Alt R, Alt H) but I want it to run automatically based on a cell value. For example: If cell value "A1" is "x" then I want the macro to run, and repeat itself down the column "A2, A3" etcetera until it reaches a blank cell. Is there a way to plug my existing macro "hiderow" into Conditional Formatting for a column; or is there a simpler solution? ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.c...

Publisher 2007 not opening saved projects.......
I have Publisher 2007, and I was wanting to open a previous project that I had done before, and it wouldn't work and it would say "Microsoft Office 2007 has stopped working. Click to find online solutions or click to close." It doesn'y do that with any other of the Microsoft Products. Can anyone help? Did you try Office Diagnostics in the Help menu? Did you "click" for online solutions? Can you open other Publisher files? -- Mary Sauer http://msauer.mvps.org/ "Joe" <Joe@discussions.microsoft.com> wrote in message news:C158393B-46...

Lost File #2
I have accidently saved over a publisher file and lost all my work. I am aware that I have temp files that may have the data in it but I cannot access any of them. I get an error message saying it is locked or in use by another person but they are not. Can anyone help >-----Original Message----- >I have accidently saved over a publisher file and lost all my work. I am >aware that I have temp files that may have the data in it but I cannot access >any of them. I get an error message saying it is locked or in use by another >person but they are not. > >Can anyon...