Archive

Posts Tagged ‘convert’

RTF to HTML converter in C++

14/09/2009 1 comment

Download source code (9KB)

Nearly, I used RichEditCtrl in a MFC project, and I want to take formatted RTF text in that control to display on a HTML control. I searched through CodeGuru and found this one. It’s a nice job, but it leaks 2 things:

  • Doesn’t work well with unicode. In fact, it can’t recognize unicode characters.
  • A minor error when calculating font size.

As you maybe known, in RTF format, an unicode character is encoded in two ways:

  • \u6884: 6884 is character code (in decimal) of this letter (it’s “Ấ“) .
  • \’1EA4: 1EA4 is character code (in hexadecimal) of this letter (it’s “Ấ“) .

So I slightly modified Daniel Beutler’s code in order to work around these problems. You can found my code in the following functions: CRTF_HTMLConverter::R2H_CreateHTMLElements and Util::StringToLong.

Advertisements

Serialize and deserialize BITMAP object in MFC/Win32

09/07/2009 5 comments

Download the source code for various platforms: WinCE/WinMobile, Win32 API

Update Feb 10, 2011: The source code I uploaded is for WinMobile platform. Today I have modified and upload the Win32 version. All the source code inside this post is also changed to Win32 version.

Lately, in one of my project, I have to save an BITMAP object into an XML document. The problem is I can only save an CString into the XML document. So I have to find a way to convert BITMAP data (in a HBITMAP) into CString.

It’s pretty easy if I serialize the BITMAP to an byte[] array, and then convert the result byte[] array into CString format. So I will consequently discuss on these 2 problems.

Read more…