Database4YoU

Home ] Up ] News ] Applications ] YU applications ]

 

 

 

TMSysFonts v 1.0

E-mailware ( freeware ) without the source!

I have made and published several freeware components so far, but there are so little feedback that I decided to make them "e-mailware"! Send me an e-mail and I will send you the component without the nug screen if you want to use it in your non commercial applications!

TMSysFonts is component which might be useful if you want to change the font appearance of your forms caption , menus and messages. One can also change width and height for forms caption buttons, manu & scroll bar buttons!

It is TComponent descendant (TFrmComponent) not allowed to be created more then once per form. I use this object as a common ancestor for all my components that require such a behavior.

Properties Events Download Feedback

Description

TMSysFonts and it's demo should show how it can be easy to change some system fonts!

I was interested in forms Caption, Menu and Message fonts but one can change SmCapton and Status as well.

The TMSysFonts component is built around the only one relevant code line:

SystemParametersInfo(SPI_SETNONCLIENTMETRICS, SizeOf(FNCMetrics), @FNCMetrics, SPIF_SENDCHANGE);

Beside that, there are about 700 lines of component code I had to write to make it work as supposed! 

You may want to read associated Delphi help for the SystemParametersInfo. It will help you a lot to understand the properties and behavior of this component too.

NOTE: Changing system fonts influences all windows, not only your application. So be aware that in case of an exception in your application, the settings might not be restored as supposed! I have taken all measures I was aware of to prevent that but, you have been warned, use it at your own risk!

How it works

While in the design time, select the appropriate fonts for Caption, Menu , Message etc. and run the application! That's all. TMSysFonts will do the rest for you.

It will save system fonts and restore them back when your application terminates or when it is deactivated (if you set RestoreOnDeactivate to true). Appropriate system fonts will be restored in the case of an exception during the events fired by TMSysFonts and also when the application is terminated abnormally but TMSysFonts object is freed.

If your application is halted or TMSysFonts object is not released from memory, you will have to restore windows defaults from the Control panel.

You may mass up the system fonts if you start several applications of a kind at the same time but don't terminate them in the exact opposite order of appearance. Why? Each instance will save and restore fonts used by the system at the time they were started! If the first application is terminated before the second one, it will restore original fonts while the second application is still running. When you terminate the second one, it will restore the fonts that were applied to the system while the first one was running, not the original ones. You may want to prevent multiple instances of your application from running at the same time or you may use memory mapped files and restore original settings when the last application is about to terminate or simply set RestoreOnDeactivate to true.  When the second app. is activated, the first one will be deactivated and original fonts will be restored so everything will work as one may expect! May be I should change the default for this property to true?

TMSysFonts hooks into Application OnActivate and OnDeactivate events! The same problem exists (as with saving & restoring system fonts) when several objects hooks into the same event handler and save & restore them. The order of creating and destroying such objects in an application is critical for well designed applications. If RestoreOnDeactivate is false, these events are not hooked at all! Changing this property during the runtime is possible but irrelevant and not recommended at all! It might be considered as "design time only" property!

Description  Events Download Feedback

Properties

Please read associated Delphi help for the SystemParametersInfo to understand sub properties better!

CaptionFont : TFontParams
SmCaptionFont: TFontParams
MenuFont: TFontParams
StatusFont: TFontParams
MessageFont: TFontParams
CBtnHeight, CBtnWidth: integer
SmCBtnHeight, SmCBtnWidth: integer
ScrollBtnHeight, ScrollBtnWidth: integer
MenuBtnHeight, MenuBtnWidth: integer

TFontParams is persistent property containing two major font representations.

1) TFont object you are already familiar with and

2) LOGFONT record actually used by windows.

When you change TFont, TMSysFonts component converts it's properties to LOGFONT structure. When you ApplyToSystem, LOGFONT structure is sent to windows API to change the fonts.

RestoreOnDeactivate: Boolean; default false;
When you change the focus from your application to another, you may find inappropriate to work with fonts and sizes you just have changed, inside foreign application. The reason you changed them at all is that their fonts were not appropriate for your application at the first place.

You may want to set this property to true and all windows will work as supposed.

I have made the default to false because if your changes  are significant, you'll probably want to take the whole screen and forbid the user to switch to another application without closing yours. On the other hand, hooking into application events can have it's drawbacks, too.

Methods

LoadFromSystem;
ApplyToSystem;

These methods have appropriate and self explaining names. After  you change some font properties you should apply them to the system only if you don't have to change anything else. Applying to the system as soon as you change any sub property wouldn't be convenient as it takes some time to broadcast the message and force all windows to redraw themselves.

Description Properties  Download Feedback

Events

There are only two events! They are declared as:

type TNotifyNCMetricsChange = procedure(Sender: TObject; NCMetrics: TNonClientMetrics) of object;

OnBeforeChange:TNotifyNCMetricsChange
OnAfterChange: TNotifyNCMetricsChange

Before and after this component applies your settings to the system, you will have actual settings available through NCMetrics record. That might be the appropriate time for some other actions like resizing your components etc. 

If another application changes the system fonts and you want to trap that changes, you may want to create WM_SETTINGCHANGE message handler.


Description Properties Events  Feedback

Demo

Demo project is included in the archive! You don't have to install the component at all! Just open the demo project and run it. If you like it, you can install it later. You may want to read how to install components without the source code !

Whether you find the component interesting or not, I would appreciate your comments by e-mail. I gave you this component for free so, don't hesitate,  waste an e-mail with a few words!

Download  TMSysFontsDemo.zip ~15 Kb

Source available on purchase Price: US $ 30.
Back to top

Copyright © 2001 Database4YoU                 Last modified: October 26, 2001