My Product Manager didn't like Effects, Font Style, or Script
controls, since our
app used only Font and Font Size values. I was starting to feel a little
apprehensive (since I had never once won an argument with him),
so I pointed out that we could easily eliminate some of the unnecessary controls.
I asked him to come back tomorrow for a demonstration. For the rest of day,
I tried to figure out how to remove controls he didn't like. I was
only partially successful, because
CFontDialog
provides very little
in its API to facilitate customizing user interface.
When the Product Manager came by next day, this is what
I showed him:
He thought it looked really lame, and I had to agree. The Font Style
combo was still there, and getting rid of Effects controls
only left a big hole in the dialog - the Sample control had
not even been resized to take advantage of free space on left.
Finally, the best I could do was to disable Script combo.
Butmember that allows you to set your hook proc, and the
lpTemplateNameand
hInstancemembers, which must be set in order to load the customized template. What MSDN doesn't tell you is where to find the default template. For VS 6.0, I found it in C:\Program Files\Microsoft Visual Studio\VC98\Include\Font.Dlg. For Visual Studio 8 and 9, it's located in the Platform SDK's Include directory. After I found it, next step was to set up a separate XFontDialog.rc file, and cut and paste the template from Font.Dlg. To set up XFontDialog.rc, I used the techniques I describe in my article XDialogImport - How to share dialogs between projects.
IDD_XFONTDIALOG, the Class Wizard will treat
IDD_XFONTDIALOGas a string. The advantage of this is that there is no possibility of conflicts with any other dialog resource ids in your project..
To integrate
CXFontDialog into your app, you first need
to add following files to your project:
You also need to add XFontDialog.rc to project rc file - go to
View | Resource Includes... and in the bottom listbox,
scroll down to the end. Insert
#include "XFontDialog.rc" right before the
#endif:
Next, include header file XFontDialog.h in
appropriate project files.
Now you are ready to start using
CXFontDialog.
CXFontDialog:
bIsMonoSpaced = (tm.tmPitchAndFamily & TMPF_FIXED_PITCH) == 0;but I discovered that some monospaced fonts (such as the excellent Pragmata font by Fabrizio Schiavi) did not mark the font in this way. So I resorted to the simpler, but more reliable method of comparing the widths of the '!' and 'W' characters. If they're the same, that means the font is monospaced.