Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Alternate Sample Text In ChooseFont Dialog

75 views
Skip to first unread message

Bob Smith

unread,
Jan 11, 2011, 12:14:52 PM1/11/11
to
FYI: If you have ever wanted the ChooseFont dialog to display your own
sample text, here's how to do it (but first, how not to do it):

By default, the ChooseFont dialog displays sample text of "AaBbYyZz".

E1. This text can be changed from a hook procedure during the
WM_INITDIALOG message as in

SetWindowText (GetDlgItem (hDlg, stc5), NewSampleText);

However, as soon as you select a new font (without exiting the dialog),
the old sample text reappears (displayed in the new font).

E2. If you set the template items (including CF_ENABLETEMPLATE in
cf.Flags and filling in cf.lpTemplateName and cf.hInstance) and use the
template from (say) font.dlg, you'll find that the text in the template

CTEXT "AaBbYyZz", stc5, 118, 111, 100, 23, ...

is completely ignored by ChooseFont. That is, if you replace "AaBbYyZz"
in the CTEXT stmt with your own text, the ChooseFont code rewrites the
sample text from its own hard-coded internal text of "AaBbYyZz" whenever
the text is redrawn, without regard for the CTEXT text.

E3. You might also try registering the window message LBSELCHSTRING,
but that message is sent by the Open/Save file dialog only, not by
ChooseFont.

Eventually I found two independent solutions:

S1. Reset the sample text during the WM_PAINT message in the hook
procedure, OR

S2. Subclass the stc5 window and ignore WM_SETTEXTs of the wrong sample
text.

I don't know how general the first solution is (i.e., I checked it on
Comdlg32.dll 6.1.7600.16385 only), so the second solution is likely to
be more robust.

Note that neither of these solutions works under Wine as their
ChooseFont redraws the stc5 window's border and content (sample text) in
its WM_PAINT handler *after* it calls the hook procedure, thus defeating
both of the above solutions.

Any other solutions under Windows and any solution under Wine are most
welcome.

FWIW, I'm running Win7/x64.

--
_________________________________________
Bob Smith -- bsm...@sudleydeplacespam.com

To reply to me directly, delete "despam".

0 new messages