Jump to content

PMGuide - Font Dialog Controls: Difference between revisions

From EDM2
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{IBM-Reprint}}
{{PMGuide}}
Font dialog controls provide basic functions that give users the ability to display and select from a list of:
Font dialog controls provide basic functions that give users the ability to display and select from a list of:
* Font family names installed on the system
* Font family names installed on the system
Line 72: Line 74:
|}
|}
The following code fragment shows how to set the fields in the FONTDLG structure:
The following code fragment shows how to set the fields in the FONTDLG structure:
{| class="mw-geshi" style="white-space:pre;"
<pre>
|
FONTDLG fd;                     /* Font dialog structure     */
FONTDLG fd; /* Font dialog structure */
strcpy(szCurrentFont,"Tms Rmn"); /* Times Roman font     */
strcpy(szCurrentFont,"Tms Rmn"); /* Times Roman font */
memset(&fd,                     /* Storage of the */
memset(&fd, /* Storage of the */
0,                         /* FONTDLG structure */
0, /* FONTDLG structure */
sizeof(FONTDLG));
sizeof(FONTDLG));


fd.cbSize=sizeof(FONTDLG); /* Size of structure */
fd.cbSize=sizeof(FONTDLG);     /* Size of structure */
fd.pszFamilyname=szCurrentFont; /* Initial font type */
fd.pszFamilyname=szCurrentFont; /* Initial font type */
fd.fxPointSize=MAKEFIXED(24,0); /* Initial font to 24 point */
fd.fxPointSize=MAKEFIXED(24,0); /* Initial font to 24 point */
fd.usFamilyBufLen=FACESIZE; /* Family buffer length */
fd.usFamilyBufLen=FACESIZE;     /* Family buffer length */
fd.clrFore=SYSCLR_WINDOWTEXT; /* Foreground color */
fd.clrFore=SYSCLR_WINDOWTEXT; /* Foreground color     */
fd.clrBack=SYSCLR_WINDOW; /* Background color */
fd.clrBack=SYSCLR_WINDOW;     /* Background color     */
fd.fl=FNTS_CENTER | /* Font flags */
fd.fl=FNTS_CENTER |         /* Font flags     */
FNTS_INITFROMATTRS;
FNTS_INITFROMATTRS;
|}
</pre>
# Invoke the font dialog. Call WinFontDlg and pass the dialog's parent window handle, owner window handle, and a pointer to the initialized FONTDLG data structure.
# Invoke the font dialog. Call WinFontDlg and pass the dialog's parent window handle, owner window handle, and a pointer to the initialized FONTDLG data structure.
# Check the return value from WinFontDlg. If it is successful, the selected font can be used by the application. The information returned in the '''fAttrs''' field of the FONTDLG data structure is used.
# Check the return value from WinFontDlg. If it is successful, the selected font can be used by the application. The information returned in the '''fAttrs''' field of the FONTDLG data structure is used.

Latest revision as of 01:42, 25 April 2025

Reprint Courtesy of International Business Machines Corporation, © International Business Machines Corporation

Presentation Manager Programming Guide and Reference
  1. How to Use this Book
  2. Device Functions
  3. Direct Manipulation Functions
  4. Dynamic Data Formatting Functions
  5. Hooks and Procedures
  6. Profile Functions
  7. Spooler Functions
  8. Window Functions
  9. Message Processing
  10. Data Types
  11. Errors
  12. Atom Tables
  13. Button Controls
  14. Clipboards
  15. Combination Box
  16. Container Controls
  17. Control Windows
  18. Cursors
  19. Dialog Windows
  20. Direct Manipulation
  21. Drawing in Windows
  22. Dynamic Data Exchange
  23. Entry-Field Controls
  24. File Dialog Controls
  25. Font Dialog Controls
  26. Frame Windows
  27. Hooks
  28. Initialization Files
  29. Keyboard Accelerators
  30. List-Box Controls
  31. Menus
  32. Messages and Message Queues
  33. Multiple-Line Entry Field Controls
  34. Mouse and Keyboard Input
  35. Mouse Pointers and Icons
  36. Notebook Controls
  37. Painting and Drawing
  38. Presentation Parameters
  39. Resource Files
  40. Scroll-Bar Controls
  41. Slider Controls
  42. Spin Button Controls
  43. Static Controls
  44. Title-Bar Controls
  45. Value Set Controls
  46. Windows
  47. Window Classes
  48. Window Procedures
  49. Window Timers
  50. Appendices
  51. Notices
  52. Glossary

Font dialog controls provide basic functions that give users the ability to display and select from a list of:

  • Font family names installed on the system
  • Available styles for each font
  • Available sizes for each font
  • Emphasis styles available for each font

Users can view their selections, using a sample character string in a preview area, and interact with a modal or modeless font dialog. This chapter explains how font dialog controls can be extended to meet the requirements of PM applications.

About Font Dialog Controls

In the font dialog control, family face is defined as the name of the typeface. Courier, Times New Roman, and Helvetica are examples of commonly used family faces. Type styles include normal, bold, italic, and bold italic. Size is the point size, or vertical measurement, of the type. Font emphasis styles include outline, underline, and strikeout.

Customizing the Font Dialog

You can create a font dialog by customizing the font dialog control, using the standard controls and adding any controls of your own design. Specify a standard control by including a control of the same class, ID, and style as in the font dialog. The minimum set of controls required for the font dialog are:

  • DID_CANCEL_BUTTON
  • DID_DISPLAY_FILTER
  • DID_NAME
  • DID_OK_BUTTON
  • DID_OUTLINE
  • DID_PRINTER_FILTER
  • DID_SAMPLE
  • DID_SIZE
  • DID_STRIKEOUT
  • DID_STYLE
  • DID_UNDERSCORE

Even if your dialog does not use all of the required controls, you must include them. You can make the unused controls invisible so that your application users are not confused.

Using Font Dialog Controls

This section describes how to create a font dialog.

Creating a Font Dialog

To present a font dialog to users, your application must do the following:

  1. Allocate storage for a FONTDLG data structure and set all fields to NULL.
  2. Initialize the fields in the FONTDLG data structure.

The application must do the following:

  1. Set the cbSize field to the size of the data structure.
  2. Set either the hpsScreen or the hpsPrinter presentation space field, or both. You must have a valid presentation space from which to query fonts.
  3. Pass the pointer to a buffer in which to return the family name selected (pszFamilyname) and the size of the buffer (usFamilyBufLen). If the application requires a default font, pass the family name of the font in this buffer. When the first character in pszFamilyName is NULL, no family name is initially selected and the dialog defaults to the system font.

The application can choose to set the following:

  1. An application-specific title. Pass the pointer to a null-terminated string in the pszTitle field.
  2. An application-specific preview string. Pass the pointer to a null-terminated string in the pszPreview field.
  3. Application-specific available font sizes for outline fonts. Pass the pointer to a null-terminated string containing point sizes, separated by spaces in the pszPtSizeList field.
  4. A custom dialog procedure to provide application-specific function. Pass the pointer to a window procedure in the pfnDlgProc field.
  5. Set the appropriate FNTS_* flags in the fl field to customize the dialog style.
  6. Set the FNTF_NOVIEWPRINTERFONTS or FNTF_NOVIEWSCREENFONTS flags to customize the dialog style when working with printer fonts in the flFlags field. These filter flags should be initialized only when both the hpsScreen and the hpsPrinter presentation space fields are non-NULL.
  7. Pass the initial position of the dialog in the x and y fields.
  8. Initialize the FONTDLG data structure with any values that users should see when they invoke the dialog for the first time.

For example, you can pass the following information about the font in these fields of the FONTDLG structure:

FONTDLG Structure Fields
Field Font characteristic
clrBack Font background color.
clrFore Font foreground color.
fl Font flags.
flStyle Style bits.
fxPointSize Point size of the font.
flType Selected type bits.
pszFamilyname Family name of the font.
usWeight Font weight.
usWidth Font width.

The following code fragment shows how to set the fields in the FONTDLG structure:

 
FONTDLG fd;		                    /* Font dialog structure     */
strcpy(szCurrentFont,"Tms Rmn");	/* Times Roman font		     */
memset(&fd,		                    /* Storage of the			 */
	 0,		                        /* FONTDLG structure		 */
	 sizeof(FONTDLG));

fd.cbSize=sizeof(FONTDLG);		    /* Size of structure		 */
fd.pszFamilyname=szCurrentFont;		/* Initial font type		 */
fd.fxPointSize=MAKEFIXED(24,0);		/* Initial font to 24 point	 */
fd.usFamilyBufLen=FACESIZE;		    /* Family buffer length		 */
fd.clrFore=SYSCLR_WINDOWTEXT;		/* Foreground color		     */
fd.clrBack=SYSCLR_WINDOW;		    /* Background color		     */
fd.fl=FNTS_CENTER |			        /* Font flags			     */
	 FNTS_INITFROMATTRS;
  1. Invoke the font dialog. Call WinFontDlg and pass the dialog's parent window handle, owner window handle, and a pointer to the initialized FONTDLG data structure.
  2. Check the return value from WinFontDlg. If it is successful, the selected font can be used by the application. The information returned in the fAttrs field of the FONTDLG data structure is used.

Graphical User Interface Support for Font Dialog Controls

This section contains information about the graphical user interface support.

Name Field

The Name field is a drop-down list that displays a font family name. When the font dialog is invoked, the value displayed in this field is either an application-supplied family name or the default system font. When users select a family name from the drop-down list, the Name field display is refreshed with the selected family name. The preview area is updated to show the sample character string in the selected family face, using the font style, size, and emphasis currently in effect.

Style Field

The Style field is a drop-down list that displays a font style. When the font dialog is invoked, the value displayed in this field is either an application-specified font style or the system default. When users select a font style from the drop-down list, the Style field display is refreshed with the selected style name. The preview area is updated to show the sample character string in the selected font style, using the family name, size, and emphasis currently in effect.

Size Field

The Size field is a drop-down combination box that displays available font sizes. Users can display and select from a list of available sizes for a font, or they can type a font size directly into the entry field. When users select a font size from the drop-down list, the Size field display is refreshed with the selected size. The preview area is updated to show the character string in the selected font size, using the family name, font style, and emphasis currently in effect. The font sizes included in the drop-down list are dependent on the character definition of the font. For image or raster fonts, all available sizes are listed. For outline fonts, the default sizes are 8, 10, 12, 14, 18, and 24 points. If required, the application can specify the available sizes for outline fonts. When users type a font size in the entry field, the preview area is updated immediately. The Size field will accept a fixed point number, such as 24.25, with up to four places saved after the decimal.

Emphasis Group Box

The Emphasis group box is a multiple-selection field that contains a list of emphasis styles (Outline, Underline, Strikeout) available for each font. When users select an emphasis style, the preview area is updated immediately. The Outline selection is not available for image fonts.

Preview Area

The Preview area enables users to view their font family, style, size and emphasis selections as they make them. It contains a sample character string that is defined by the application. The default character string is abcdABCD. The Preview area displays font sizes as large as 48 points. As the size of the font increases, the sample displayed is clipped by the borders of the area.

Filter Check Box

The Filter check box enables users to limit the font family name drop-down list to select from fonts that are displayable only, printable only, or a merged list. The initial setting of the Filter check box is specified by the application.

Standard Push Button and Default Action

The dialog can be dismissed with either the OK or Cancel push buttons.

Subclassing the Default Font Dialog Procedure

The name of the dialog procedure is assigned to the pfnDlgProc field of the FONTDLG data structure.