From: Joseph M. Newcomer on
I just converted my Font Explorer to work in Unicode. This was a program originally
written in 1996 for the Win32 Programming book. I wrote it "Unicode-aware", or so I
thought.

When I converted it, I had to deal with the fact that I had *not* successfully created a
Unicode-aware program. Here's some data I gathered

Unicode conversion

Earliest file in project: 2-13-1996
Latest file in project: 11-07-1996
Total source lines 17,036
Total source files 106

LPCSTR/char => LPCTSTR/TCHAR/CString 11
_T() 12
_atoi=>_ttoi 1
misc 17
====
Total 41
.23%

The misc lines were involved in making sure that the edit controls and static controls use
Arial MS Unicode for display of text.
Many of the changes were in two files that were copied directly from Win16:

LPCSTR/char => LPCTSTR/TCHAR/CString 4
_T() 9
====
13 Legacy Win16 subroutine
Add to that feature enhancement to support Arial MS Unicode:
17 Upgrade to edit/static controls
====
30 Total lines from Win16 upgrade or enhanced
feature
11 Total lines erroneously using 8-bit characters

This leaves 11 lines that were erroneous.

Not bad, given how new I was to the 32-bit environment in 1996. The whole conversion took
considerably less than an hour, *including* adding Arial MS Unicode to the input and
output displays. I didn't track it very carefully, but about 20 minutes was spent on
everything but the font enhancement, and the font enhancement might have taken another 20
minutes. Intermixed in this was dealing with UINT_PTR types of enhancements so I would be
64-bit compatible as well (I've not moved it to 64 bits yet, but I needed the Unicode
version for the paper I'm writing; once I get that paper submitted, I'll worry about the
full 64-bit build). I know it took less than an hour because I was sort-of-listening to a
TV program, started the conversion during the first ad, and I finished the conversion
before the program ended. Then used my DVR to replay the entire program because I hadn't
been paying much attention to it.

The lesson here is for those who are still using antiquated concepts like 'char': if you
do the job as right as you can at the start, the conversion effort is going to be
substantially lower if you have to convert everything.
joe




Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Gert on
Joseph,

You say:

> The misc lines were involved in making sure that the edit controls and static controls use
> Arial MS Unicode for display of text.

What exactly do you mean here? Any web references to this issue?

I will be converting an application to Unicode in a few months - the
original was not written Unicode-aware. I understand the other changes I
need to make, but not the above.

Thanks,
Gert
From: Mihai N. on
> I just converted my Font Explorer to work in Unicode.
....
> substantially lower if you have to convert everything.


I have tried to look it up and see if the sources are
available somewhere. But not luck.
I wanted to try my tool here:
http://www.mihai-nita.net/article.php?artID=tounicode

Are you curious to give it a try and see if it saves you some time?

Thanks
Mihai

--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
From: Joseph M. Newcomer on
The sources for the Font Explorer can be downloaded from my site as part of the Win32 book
CD download. The code size will be a bit smaller because I've added a lot of code in the
last few weeks, probably about 3K lines. Since I'm bringing the whole Font Explorer up to
VS2003 or better, I've got a lot left to do (I want to add new functionality to it, and
make some dialogs be MDI pages) but these are not in the critical path of getting my
research paper out (forensic examination of computer-generated documents), so they will
wait until the paper is finished.
joe

On Mon, 12 May 2008 23:15:46 -0700, "Mihai N." <nmihai_year_2000(a)yahoo.com> wrote:

>> I just converted my Font Explorer to work in Unicode.
>...
>> substantially lower if you have to convert everything.
>
>
>I have tried to look it up and see if the sources are
>available somewhere. But not luck.
>I wanted to try my tool here:
> http://www.mihai-nita.net/article.php?artID=tounicode
>
>Are you curious to give it a try and see if it saves you some time?
>
>Thanks
>Mihai
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on
Dialogs typically use a "default dialog font", which either has ONLY characters
U0020..U00FF or has only a tiny subset of the Unicode fonts (usually, just enough to
handle central European, Cyrillic, Hebrew and Arabic...check out Character Map). I wanted
to be able to display as many Unicode characters as possible, and in fact in my first
test, the fraction 7/8 would not display in the input controls (although it was actually
in the font I was using for other display). So I added the following lines.

The way this works is that I zero out the LOGFONT structure in the dialog constructor. If
the caller has a known font it wants to use in the dialog, it fills in the LOGFONT
structure with the information about this font. If the height field is 0, there is no
font being requested. I didn't bother to check CreateFont here because that has already
been checked before the dialog is called.

if(lf.lfHeight != 0)
{ /* has font */
CFont * dlgfont = GetFont();
LOGFONT dlglf;
dlgfont->GetLogFont(&dlglf);

int h = dlglf.lfHeight;
dlglf = lf;
lf.lfHeight = h;
font.CreateFontIndirect(&dlglf);
c_Sample.SetFont(&font);
c_SmallSample.SetFont(&font);
} /* has font */

The two edit controls are called c_Sample and c_SmallSample. The caller has some static
controls which are set as well.

Note that not all machines have Arial MS Unicode installed (it is part of the Office
install, and can be downloaded separately from Microsoft) so it could not be set as the
default dialog font.
joe


On Tue, 13 May 2008 06:46:58 +0200, Gert <dont(a)want.no.spam> wrote:

>Joseph,
>
>You say:
>
>> The misc lines were involved in making sure that the edit controls and static controls use
>> Arial MS Unicode for display of text.
>
>What exactly do you mean here? Any web references to this issue?
>
>I will be converting an application to Unicode in a few months - the
>original was not written Unicode-aware. I understand the other changes I
>need to make, but not the above.
>
>Thanks,
>Gert
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm