| May 1998: Changing Font Size on a Dialog
Macro dialogs can really make your macro work well; gathering
information from the user, displaying information, and so on.
Generally, the text displayed on a dialog uses the system default
font. But you don't have to be stuck with the system font.
Changing the Font in DE Dialogs
In WordPerfect 8, you can change the font that the dialog uses to
display text in the Macro Dialog Editor. To change the font, click
Dialog on the Dialog Editor menu, then choose Font. In the Font
dialog select the type style and size you want, then choose OK.
The font you select will affect the entire dialog.
Changing the Font in Old Style Dialogs
If you are using old style dialog commands, you can use the
DialogSetProperties command.
DialogSetProperties("MyDialog"; "MS Sans Serif"; 8p)
You can specify the font name and point size that you desire with this command.
Generally, this command should appear directly after your DialogDefine
command.
Changing the Font with Windows Calls
Windows includes commands that allow you to use other fonts in your
macro dialogs. The sample macro from last month's issue uses these
commands to display the dialog text in a large font on the dialog.
We won't go into the details of those commands here. Instead, I'll share
with you some subroutines you can use to change the display font in your
own dialogs.
Here's a sample where I create a dialog with two text controls, set new
fonts and apply them to the text, then display the dialog:
//*************************************************************
// Font Size Test
// Developer: J. Jeppson
// Date: 5/11/1998
//*************************************************************
Application (A1; "PerfectScript"; default; "EN")
// Create the dialog but don't display it yet.
DialogDefine ("Fonts"; 50; 50; 375; 180; OK!+Percent!; "Font Demo")
DialogAddText ("Fonts"; "Text1"; 10; 10; 355; 59; RecessBox!+Center!;
"This is a larger font.")
DialogAddText ("Fonts"; "Text2"; 10; 74; 355; 59; RecessBox!+Center!;
"This is a smaller font.")
//Set the fonts for the desired controls using Region Names
hFont:=SelectFont("Arial"; 60)
SetCtrlFont("Fonts.Text1"; hFont)
hTFont:=SelectFont("Arial"; 10)
SetCtrlFont("Fonts.Text2"; hTFont)
//Display the dialog
DialogShow (Dialog:"Fonts")
//Free the font objects from memory
FreeFont(hFont)
FreeFont(hTFont)
Quit
//The functions that create the font object and assign them to the controls
//Copy to your own macros if desired
FUNCTION SelectFont(FontName; FontSize)
GLink:=DLLLoad("GDI")
DLLCall(GLink; "CreateFontA"; hFont; DWORD;
{FontSize; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; FontName})
DLLFree(GLink)
Return(hFont)
ENDFUNC
PROCEDURE SetCtrlFont(NamedRegion; hFont)
ULink:=DLLLoad("User")
hWnd:=RegionGetHandle(NamedRegion)
DLLCall(ULink; "SendMessageA"; ret; DWORD; {hwnd; 48; hFont; 1})
DLLFree(ULink)
ENDPROC
PROCEDURE FreeFont(hFont)
GLink:=DLLLoad("GDI")
DLLCall(GLink; "DeleteObject"; ret; DWORD; {hFont})
DLLFree(GLink)
ENDPROC
I've used three Windows commands as DLL calls to change the font size:
<-
CreateFontA
- This command creates a font object in memory
- SendMessageA
- This command sends a message to a particular dialog control telling
it to change to a new font
- DeleteObject
- This command removes the new font object from memory
For convenience, I've created a FUNCTION and two PROCEDURES
to invoke these commands and take all the dirty work out of changing
the fonts for you. You can copy these three subroutines use in your
own macros if you'd like. These are listed at the bottom of the
sample code above.
Once this code is in your macro, you can change the font by calling
these subroutines with the following two commands:
// specify font & size, and create font object in memory
hFont:=SelectFont("Arial"; 60)
// apply the font object to a particular dialog region
SetCtrlFont("Fonts.Text1"; hFont)
You can even use the same font on multiple dialog controls by just
including separate SetCtrlFont commands for additional
dialog controls.
The SelectFont command
creates a font object, whose identity is
assigned to hFont. (This name can be any valid
variable name.) You
specify a font face and size as the two parameters of the command.
Make sure you spell the font name exactly as it appears in your font
list, and that the size you select is valid for that font.
Then, with SetCtrlFont, you specify which control
you wish to use the
new font.
Next, display the dialog with the DialogShow
command.
Once you are through using the fonts (i.e., the dialog is dismissed), it is
always a good idea to free up memory resources, so use the command
FreeFont(hFont) to take care of this for you.
For more information on advanced macros, including DLL calls
and region names, see my book. Ordering info is available on
my web page.
Copyright Notice: The information included in the PerfectScript Journal is protected
by US Copyright. The author grants you the right to use the routines in your own macros as
needed. You may not sell, distribute, or publish them in any form.
If you choose to use the information here, you do so entirely at your own risk. No
representations are made regarding the fitness of this information for your
particular purpose, or for your ability or inability to use the information. You
are advised to make backups of all relevant files before implementing any suggestion
or technique.
© Copyright 1998 by J. Jeppson.
|