Jump to content

WinFontDlg

From EDM2
Revision as of 21:53, 26 November 2023 by Martini (talk | contribs) (Created page with "This dialog allows the user to select a font. ==Syntax== WinFontDlg(hwndP, hwndO, pfntd) ==Parameters== ;hwndP (HWND) - input :Parent-window handle. :Parent-window handle ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This dialog allows the user to select a font.

Syntax

WinFontDlg(hwndP, hwndO, pfntd)

Parameters

hwndP (HWND) - input
Parent-window handle.
Parent-window handle of the created dialog window.
HWND_DESKTOP
The desktop window.
Other
Specified window.
hwndO (HWND) - input
Requested owner-window handle.
Requested owner-window handle of the created dialog window.
The actual owner window is calculated using the algorithm specified in the description of the WinLoadDlg function.
pfntd (PFONTDLG) - input
Pointer to an initialized FONTDLG structure.

Returns

hwnd (HWND) - returns
Font dialog window handle.
If the flag is set by the application, the return value is the window handle of the font dialog, or NULLHANDLE if the dialog cannot be created. If the flag is not set, the return value is TRUE if dialog creation is successful, or NULLHANDLE if it is unsuccessful.

Remarks

The pfntd parameter is required and the FONTDLG structure must be properly initialized.

Note: If the field in the FONTDLG structure, pfntd must be a pointer to a FONTDLG structure that is either static or allocated from the heap. This FONTDLG structure must not be allocated on the stack.

Upon return, the FONTDLG structure is updated with any user alterations and the field contains the value returned by the font dialog's WinDismissDlg function. By default this is the ID of the push button pressed to dismiss the dialog, DID_OK or DID_CANCEL, unless the application supplied additional push buttons in its template.

The pointer to the FONTDLG structure is placed in the QWL_USER field of the dialog's frame window. If in a custom font dialog procedure the pointer to the FONTDLG structure is desired, it should be queried from the frame window with WinQueryWindowULong.

To subclass the default font dialog with a new template, the application must give the module and ID of the new font dialog template and the address of a dialog procedure for message handling. Window IDs in the range 0x0000 through 0x0FFF are reserved for the font dialog controls. IDs from outside this range must be chosen for any controls added to a custom font dialog.

When a modeless dialog is dismissed, the owner of the font dialog will receive a WM_COMMAND message with the parameter equal to the ID of the font dialog.

Example Code

This example displays a font selection dialog by using WinFontDlg, which allows the user to select a font.

#define INCL_WINSTDFONT    /* Window Standard Font Functions   */
#include <os2.h>
#include <string.h>

HPS     hpsScreen;         /* Screen presentation space        */
FONTDLG pfdFontdlg;        /* Font dialog info structure       */
HWND    hwndMain;          /* Window that owns the font dialog */
HWND    hwndFontDlg;       /* Font dialog window               */

char szFamilyname[FACESIZE];

/***************************************************************/
/* Initially set all fields to 0.                              */
/***************************************************************/
memset(&pfdFontdlg,0,sizeof(FONTDLG));

/***************************************************************/
/* Get handle to presentation space.                           */
/***************************************************************/
hpsScreen=WinGetPS(hwndMain);

/***************************************************************/
/* Initialize those fields in the FONTDLG structure that are   */
/* used by the application                                     */
/***************************************************************/
pfdFontdlg.cbSize=sizeof(FONTDLG);     /* Size of structure    */
pfdFontdlg.hpsScreen=hpsScreen;        /* Screen presentation  */
                                       /* space                */
szFamilyname[0]='\0';                  /* Use default font     */
pfdFontdlg.pszFamilyname=szFamilyname; /* Provide buffer       */

pfdFontdlg.usFamilyBufLen = sizeof(szFamilyname);
                                       /* Font family name     */
pfdFontdlg.fxPointSize=MAKEFIXED(10,0);/* Font point size      */
pfdFontdlg.fl=FNTS_HELPBUTTON |
              FNTS_CENTER;             /* FNTS_* flags         */
pfdFontdlg.clrFore=CLR_BLACK;          /* Foreground color     */
pfdFontdlg.clrBack=CLR_WHITE;          /* Background color     */
pfdFontdlg.fAttrs.usCodePage=437;      /* Code page to select  */
                                       /* from                 */

/***************************************************************/
/* Display the font dialog and get the font                    */
/***************************************************************/
hwndFontDlg=WinFontDlg(HWND_DESKTOP,hwndMain,&pfdFontdlg);

if(hwndFontDlg &&(pfdFontdlg.lReturn==DID_OK))

{
   /************************************************************/
   /* Upon successful return of a font, the application can    */
   /* use font information selected by the user to create a    */
   /* font, load a font, and so forth                          */
   /************************************************************/
}

WinReleasePS(hpsScreen);

Definition

#define INCL_winstdfont
#include <os2.h>

HWND        hwndP;  /*  Parent-window handle. */
HWND        hwndO;  /*  Requested owner-window handle. */
PFONTDLG    pfntd;  /*  Pointer to an initialized FONTDLG structure. */
HWND        hwnd;   /*  Font dialog window handle. */

hwnd = WinFontDlg(hwndP, hwndO, pfntd);