RTF to HTML converter in C++

14/09/2009

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.


Serialize and deserialize BITMAP object in MFC/Win32

09/07/2009

Download the source code

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 the rest of this entry »


Easily way to make transparent picture control in MFC

28/01/2009

I’m going to describe the way to make a transparent picture box control in MFC (Smart Device application). It worked well on Windows CE, and it should be fine on Win32 application.

The key function is TransparentImage. Using it, you will see that the job is pretty simple…

Read the rest of this entry »


What can you do with MS SmallBasic

11/01/2009

I spent my rarely free time before the Lunar New Year holiday by playing with SmallBasic – one of more interesting tools introduced by Microsoft. Just another easy tool for newbies, but I wonder if “what can I do with it?”. It’s just has less than 15 keywords, and at the 1st sight, I can’t imagine anything I can do with it…

Read the rest of this entry »


10 Useful Techniques To Improve Your User Interface Designs

17/12/2008

Lại thêm 1 bài báo nữa về UI design, nhưng h thì lười wá, không copy nữa (mà cũng chưa đọc hết dc nó), nên đặt tạm cái link đây vậy:

http://www.smashingmagazine.com/2008/12/15/10-useful-techniques-to-improve-your-user-interface-designs/


Colors and the UI: another good article for UI designers

27/11/2008

As the name suggests, GUIs (Graphical User Interfaces) present their features and functions visually. The human-computer interaction is heavily based on seeing things, looking for things and interacting with graphical UI elements. Color is a main characteristic of any visual scene, not only on computer screens, but in any situation where we see something. Because most of what we see and interact with in our everyday life is colored (as opposed to shades of white-gray-black), we are very familiar with colors – maybe so much that we don’t think about them a lot. On the other hand, it does bother us when we need to read a dark-gray label on a black button. So colors have the potential to boost or wreck the user experience. This article will introduce the concept of user experience and highlight some aspects of colors and color perception together with recommendations for UI design.

Read the rest of this entry »


Here’s Why It’s Windows 7

15/10/2008

Đọc cái này nghe nhảm ko chịu dc :) )

The mystery of Microsoft’s Windows version count has been solved. A day after announcing (in the Windows Vista blog) that the next release of Windows will be called Windows 7, Mike Nash (Microsoft Corporate VP, Windows Product Management) added a post laying out Microsoft’s Windows version numbers since Windows 3.x.

Basically, they go like this:

Version 4: Windows 95

Version 4 point releases: Windows 98, 98SE, and ME (4.0.1998, 4.10.2222 and 4.90.3000, respectively).

Version 5: Windows 2000

Version 5 point releases: Windows XP (5.1)

Version 6: Windows Vista

I was surprised to realize that Windows XP (in which Microsoft unified the code bases for Windows 9x and NT/2000) was only a point release. But at least we now know how they got to Windows 7.

Source: http://www.pcworld.com/article/152261/Windows_7_naming.html?tk=rss_news


Microsoft’s new ‘M’ programming language

14/10/2008

In a software-centric world where we already have many, many languages to program in, from scripting to bytecode compiled languages, to frameworks on top of languages and embedded languages, now Redmond wants to bring ANOTHER language to the table, titled ‘M’ (for Microsoft?).

Read the rest of this entry »


Another trick with System.Net.Sockets.NetworkStream class

04/10/2008

Để hiểu dc cái trick này, người viết đã phải mất vài ngày… Hix…

Bình thường thì một ứng dụng mạng .NET sẽ có thread mạng được bọc trong vòng lặp như sau:

NetworkStream s = m_TcpClnt.GetStream();
while (s.DataAvailable)
{
//read mess
s.Read(aLen, 0, MSG_LEN);
// ……………
}

Ở đây ta dùng thuộc tính DataAvailable của lớp NetworkStream để xác định khi nào trong stream còn dữ liệu. Tuy nhiên vấn đề là nếu ta vừa đọc lên 1 lượng dữ liệu khá lớn (tầm 2KB) trong vòng while thì ngay sau đó, mặc dù phía server ko truyền gì nữa, nhưng DataAvaiible vẫn có giá trị TRUE, và vòng lặp tiếp tục, ta sẽ đọc được toàn là rác…

Để hạn chế điều này, ta có thể viết như sau:

while(true)

{

NetworkStream s = m_TcpClnt.GetStream();
if(s.Read(aLen, 0, MSG_LEN) > 0)
{
// ……………
}

}

Hàm Read() sẽ block đến khi nào có dữ liệu mới thoát, trả về số byte mà nó nhận được. Mặc dù không triệt tiêu 100% (nhất là khi truyền qua môi trường WiFi, GPRS v.v…) nhưng có lẽ đây cũng là cách hiệu quả.


Windows Server 2008 and FreeBSD 7.0 RELEASE dual boot

24/08/2008

I want to put both WinServer 2008 and FreeBSD 7.0 on my laptop. In my first try, I installed WinServer 2k8 first, then installed FreeBSD with the option that let the FreeBSD edit Master Boot Record. After that stupid choice, I lost my Win Server partition. When boot up, Windows said that the winload was fail. Well…

The solution is:

1. Install WinServer 2008.

2. Install FreeBSD with the option that untouch the MBR.

3. After that, your computer eill reboot into FreeBSD. Not straight, ’cause the FreeBSD’s partition is active now. You have to reboot by a boot CD and use a Disk Partition tool (e.g. PQMagic …) to set the WinServer partiton to Active.

4. After reboot into WinServer, use EasyBCD and add a new entry into the BCD:
EasyBCD with FreeBSD
5. Reboot. All done. You will have two among the most powerful Server OSs on your PC.