Wednesday, 3 September 2008

Making Visual C++ 6 apps look cool

Visual C++ 6 is what, 10 years old now? But there are a lot of good reasons to still develop software in Visual Studio 6 because it lets you do things that Visual Studio 2005 et al. cannot do. Or perhaps you just have an existing project you do not want to convert.

But one of the drawbacks to VS6 is the programs frankly look ugly. Sure you can still add a manifest if you like, but the default dialog font is MS Sans Serif (at least on US/English systems) which is hideous and doesn't lend itself well to supporting wide character sets. See, this looks gash. It works well enough for standard English programs but won't work if you try to use a non Roman character set (e.g. Kanji or Chinese). Sadly to fix this you need to edit the resources manually.

There are three main things to check and possibly change. First you need to load your resource script (.rc file) into your favourite text editor. Notepad works fine. Find the dialog resources. They should read something like this:
IDD_DIALOG1 DIALOG DISCARDABLE  0, 0, 186, 90
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Sans Serif"

The first things you need to do is change the dialog font from MS Sans Serif to MS Shell Dlg. MS Shell Dlg isn't a font, it's a mapping to the system font which is probably Tahoma. Now this value will actually be ignored unless two other conditions are met. Firstly, the dialog template must be DIALOGEX instead of DIALOG. Secondly, the dialog must have two additional styles, so you should add DS_FIXEDSYS which will include them both. So you should end up with:
IDD_DIALOG1 DIALOGEX DISCARDABLE  0, 0, 186, 90
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_FIXEDSYS
CAPTION "Dialog"
FONT 8, "MS Shell Dlg"

Note that if you edit a dialog in the IDE it might lose the DIALOGEX template. It will keep the font and the styles, but you may need to re-edit the resources by hand then have the IDE reload them if you want to move controls about. Also the IDE won't render the font correctly so sometimes you have to "guess" how big a control needs to be to contain the text you need.

Then you can add your Common Control 6 manifest and your program will now look cool. Goodbye 1998, Hello 2008.

There are still sometimes that dialogs will look wrong, especially related to property sheets. Some types of MFC property sheets (and other MFC dialogs) use DIALOG templates so property pages may not always display correctly. And by using DIALOGEX you are effectively preventing your software from running on Win32s on Windows 3.x. But I think the benefits outweigh those limitations.

No comments: