How do I use the Font dialog (WinFontDlg)?

FIRST: make your stack huge (>32K) It is sparsely allocated and you only use what you need. Here's some code:

 FONTDLG fontdlg ;
 FONTMETRICS fm ;
 CHAR            szBuf [200] ;
 CHAR            szFamily [CCHMAXPATH] ;
 static CHAR     szTitle [] = "Fonts Dialog" ;
 static CHAR     szMsgBoxTitle [] = "Result from 'WinFontDlg ()'" ;
 static CHAR     szPreview [] = "We hold these truths to be self-evident ..." ;

 // Here, get an HPS and then do a WinQueryFontMetrics.
 // Continuing ...

 memset ((void *) &fontdlg, 0, sizeof (FONTDLG)) ;
 fontdlg.cbSize = sizeof (FONTDLG) ;
 fontdlg.hpsScreen = WinGetScreenPS (HWND_DESKTOP) ;
 fontdlg.hpsPrinter = NULLHANDLE ;
 fontdlg.pszTitle = szTitle ;
 fontdlg.pszPreview = szPreview ;
 fontdlg.pfnDlgProc = NULL ;
 strcpy (szFamily, fm.szFamilyname) ;
 fontdlg.pszFamilyname = szFamily ;
 fontdlg.usFamilyBufLen = sizeof (szFamily) ;
 fontdlg.fxPointSize = MAKEFIXED (fm.sNominalPointSize / 10, 0) ;
 fontdlg.fl = FNTS_CENTER | FNTS_HELPBUTTON |
     FNTS_INITFROMFATTRS | FNTS_NOSYNTHESIZEDFONTS |
     FNTS_RESETBUTTON ;
 fontdlg.sNominalPointSize = fm.sNominalPointSize ;
 fontdlg.flType = (LONG) fm.fsType ;
 fontdlg.clrFore = CLR_NEUTRAL ;
 fontdlg.clrBack = CLR_BACKGROUND ;
 fontdlg.usWeight = fm.usWeightClass ;
 fontdlg.usWidth = fm.usWidthClass ;

 hwndDlg = WinFontDlg (HWND_DESKTOP, hwnd, &fontdlg) ;

Credit: Wayne Kovsky


[Back: How do I do it in REXX?]
[Next: How do I take control of frame sizing?]