Annotation of mstools/samples/cdtest/font.c, revision 1.1

1.1     ! root        1: /************************************************************************
        !             2: 
        !             3:   File: font.c
        !             4: 
        !             5:   Purpose:
        !             6: 
        !             7:     Contains all functions pertinent to CDTEST's Font dialog.
        !             8: 
        !             9:   Functions:
        !            10: 
        !            11:      DoFontDlg()          -- Creates CDTEST's font dialog.
        !            12: 
        !            13:      FontProc()           -- Callback for CDTEST's font dialog.
        !            14: 
        !            15:      InitFontStruct()     -- Fills a CHOOSEFONT structure with some defaults.
        !            16: 
        !            17:      FillFontDlg()        -- Fills CDTEST's font dialog with the contents
        !            18:                              of a CHOOSEFONT structure.
        !            19: 
        !            20:      GetFontDlg()         -- Retrieves the contents of CDTEST's font dialog
        !            21:                              and fills a CHOOSEFONT structure with them.
        !            22: 
        !            23:      GetHdc()             -- Creates and returns an HDC
        !            24: 
        !            25:      LogFontProc()        -- Callback function for the logfont dlg.
        !            26: 
        !            27:      InitLogFontStruct()  -- Fills a LOGFONT structure with some defaults.
        !            28: 
        !            29:      FillLogFontDlg()     -- Fills the LOGFONT dlg with the values in
        !            30:                              a LOGFONT structure.
        !            31: 
        !            32:      GetLogFontDlg()      -- Retrieves the user's edits in the LogFont dlg
        !            33:                              and puts them in a LOGFONT structure.
        !            34: 
        !            35:      FontHookProc()       -- Callback function for CHOOSEFONT->lpfnHook
        !            36: 
        !            37:      GetFontDlgHandle()   -- Creates a handle to the custom template and
        !            38:                              returns a handle to it.
        !            39: 
        !            40:      EnumFontsProc()      -- Callback function for EnumFontFamilies()
        !            41: 
        !            42:      FillFontsBox()       -- Fills CDTEST's font list box with requested fonts
        !            43: 
        !            44:      ResetCheckBoxes()    -- handles the font choices check box manipulations
        !            45: 
        !            46:      HandleFontCheckBox() -- Handles the WM_COMMAND messages from the font
        !            47:                              choices check boxes.
        !            48: 
        !            49:      DoChooseFontStuff()  -- Calls the ChooseFont() function.
        !            50: 
        !            51:      FontThreadProc1()    -- Starting address for the first thread.
        !            52: 
        !            53:      FontThreadProc2()    -- Starting address for the second thread.
        !            54: 
        !            55:      MultiThreadFontDlg() -- Creates two threads which each create a
        !            56:                              ChooseFont() dialog.
        !            57: 
        !            58:      FontEnableButtons()  -- Enables or disables CDTEST's font dialog buttons.
        !            59:                              Necessary for multithreading part of this app.
        !            60: 
        !            61: ************************************************************************/
        !            62: 
        !            63: 
        !            64: #include <windows.h>
        !            65: #include <commdlg.h>
        !            66: #include <stdlib.h>
        !            67: #include <winnls.h>
        !            68: #include "cdtest.h"
        !            69: #include "font.h"
        !            70: #include "logfont.h"
        !            71: 
        !            72: 
        !            73: 
        !            74: /* some definitions that will help us tell the difference between
        !            75:    screen and printer fonts */
        !            76: 
        !            77: #define FONT_TYPE_WYSIWYG 1
        !            78: BOOL bScreen ;
        !            79: 
        !            80: 
        !            81: 
        !            82: /* function prototypes and general variables */
        !            83: 
        !            84: void InitFontStruct(HWND, LPCHOOSEFONT) ;
        !            85: void FillFontDlg(HWND, LPCHOOSEFONT) ;
        !            86: void GetFontDlg(HWND, LPCHOOSEFONT) ;
        !            87: HDC  GetHdc(HWND, int) ;
        !            88: void InitLogFontStruct(HWND, LPLOGFONT) ;
        !            89: void FillLogFontDlg(HWND, LPLOGFONT) ;
        !            90: void GetLogFontDlg(HWND, LPLOGFONT) ;
        !            91: BOOL APIENTRY LogFontProc(HWND, UINT, UINT, LONG) ;
        !            92: UINT APIENTRY FontHookProc(HWND, UINT, UINT, LONG) ;
        !            93: int  CALLBACK EnumFontsProc(LPLOGFONT, LPTEXTMETRIC, DWORD, LONG) ;
        !            94: void FillFontsBox(HWND, DWORD) ;
        !            95: void ResetCheckBoxes(HWND) ;
        !            96: void HandleFontCheckBox(HWND, int) ;
        !            97: void DoChooseFontStuff(HWND, LPCHOOSEFONT) ;
        !            98: 
        !            99: 
        !           100: 
        !           101: /* Global variables and some external variables and functions */
        !           102: 
        !           103: DWORD dwFontFlag ;
        !           104: PRINTDLG pfd ;
        !           105: BOOL bLogFontParam ;
        !           106: LOGFONT lfWM_CF_LF ;                 //for the WM_CHOOSEFONT_GETLOGFONT message
        !           107: extern UINT uMode ;
        !           108: extern LONG MyAtol(LPTSTR, BOOL, LPBOOL) ;
        !           109: HANDLE hResFont, hDialogFont ;
        !           110: HANDLE GetFontDlgHandle(void) ;
        !           111: CHOOSEFONT cf ;
        !           112: LOGFONT lf ;
        !           113: HDC hdc ;
        !           114: TCHAR szFaceName[50] ;
        !           115: TCHAR szFontTemplate[50] ;
        !           116: TCHAR szFontStyle[50] ;
        !           117: #define HDCSCREEN 1
        !           118: #define HDCPRINTER 2
        !           119: #define HDCNULL 3
        !           120: #define HDCINVALID 4
        !           121: INT nHdcType ;
        !           122: 
        !           123: 
        !           124: 
        !           125: /* Multithreading stuff */
        !           126: 
        !           127: HANDLE hFontThread1 ;
        !           128: HANDLE hFontThread2 ;
        !           129: DWORD  dwFontThreadID1 ;
        !           130: DWORD  dwFontThreadID2 ;
        !           131: DWORD  dwFontThreadParm1 ;
        !           132: DWORD  dwFontThreadParm2 ;
        !           133: DWORD  FontThreadProc1(LPDWORD) ;
        !           134: DWORD  FontThreadProc2(LPDWORD) ;
        !           135: HANDLE hwndMainFont ;
        !           136: int    nOpenFontDialogCount ;
        !           137: CHOOSEFONT cfThread1 ;
        !           138: CHOOSEFONT cfThread2 ;
        !           139: void MultiThreadFontDlg(void) ;
        !           140: void EnableFontButtons(HWND, BOOL) ;
        !           141: 
        !           142: 
        !           143: 
        !           144: 
        !           145: /************************************************************************
        !           146: 
        !           147:   Function: DoFontDlg(HWND)
        !           148: 
        !           149:   Purpose:
        !           150: 
        !           151:     To create the CDTEST's font dialog
        !           152: 
        !           153:   Returns: Nothing.
        !           154: 
        !           155:   Comments:
        !           156: 
        !           157: 
        !           158: ************************************************************************/
        !           159: 
        !           160: void DoFontDialog(HWND hwnd)
        !           161: {
        !           162: 
        !           163: 
        !           164:   DialogBox(hInst, MAKEINTRESOURCE(ID_FONTDIALOG),
        !           165:             hwnd, FontProc) ;
        !           166: 
        !           167: }
        !           168: 
        !           169: 
        !           170: 
        !           171: 
        !           172: 
        !           173: 
        !           174: 
        !           175: /************************************************************************
        !           176: 
        !           177:   Function: FontProc(HWND, UINT, UINT, LONG)
        !           178: 
        !           179:   Purpose:
        !           180: 
        !           181:     Callback function for CDTEST's font dialog.
        !           182: 
        !           183:   Returns: TRUE or FALSE depending on the situation.
        !           184: 
        !           185:   Comments:
        !           186: 
        !           187: 
        !           188: ************************************************************************/
        !           189: 
        !           190: 
        !           191: BOOL APIENTRY FontProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
        !           192: {
        !           193:   BOOL b ;
        !           194:   TCHAR szNum[30] ;
        !           195: 
        !           196:   switch (msg)
        !           197:   {
        !           198:     case WM_INITDIALOG:
        !           199: 
        !           200:         InitLogFontStruct(hwnd, &lf) ;   //fill (struct lf) so the choosefont
        !           201:         InitFontStruct(hwnd, &cf) ;      //struct can use it
        !           202:         FillFontDlg(hwnd, &cf) ;
        !           203: 
        !           204:         CheckRadioButton(hwnd, ID_HDCSCREEN, ID_HDCPRINTER, ID_HDCSCREEN) ;
        !           205:         nHdcType = HDCSCREEN ;
        !           206: 
        !           207:         dwFontFlag = cf.Flags ;
        !           208: 
        !           209:         FillFontsBox(hwnd, dwFontFlag) ;
        !           210: 
        !           211:         ResetCheckBoxes(hwnd) ;
        !           212: 
        !           213:         *(&cfThread1) = *(&cfThread2) = *(&cf) ;
        !           214: 
        !           215:         hwndMainFont = hwnd ;
        !           216:         nOpenFontDialogCount = 0 ;
        !           217: 
        !           218:         SetFocus(GetDlgItem(hwnd, ID_STRUCTSIZEF)) ;
        !           219: 
        !           220:         break ;
        !           221: 
        !           222: 
        !           223:     case UMSG_DECREMENTDLGCOUNT:  // user defined message.  This is send by
        !           224:                                   // the functions that are executing when
        !           225:                                   // a new thread is created.  When these
        !           226:                                   // Thread functions end, they should send
        !           227:                                   // this message.
        !           228: 
        !           229:       nOpenFontDialogCount-- ;
        !           230: 
        !           231:       if (nOpenFontDialogCount == 0)
        !           232:         EnableFontButtons(hwnd, TRUE) ;
        !           233: 
        !           234:       break ;
        !           235: 
        !           236: 
        !           237:     case WM_CF_LF:
        !           238: 
        !           239:        /* If this message comes in, we know that the user clicked the
        !           240:           button that tells the ChooseFont() dialog to tell the parent
        !           241:           to send the WM_CHOOSEFONT_GETLOGFONT message.  So what we will
        !           242:           do is send the message and then show the user what was in the
        !           243:           logfont by calling creating the Logfont dialog box */
        !           244: 
        !           245: 
        !           246:        SendMessage((HWND) lParam, WM_CHOOSEFONT_GETLOGFONT,
        !           247:                    0, (LPARAM) &lfWM_CF_LF) ;
        !           248: 
        !           249:        bLogFontParam = TRUE ; //tells us if we are doing normal logfont
        !           250:                               //processing or answering the WM_CF_LF message.
        !           251: 
        !           252:        DialogBoxParam(hInst, MAKEINTRESOURCE(ID_LOGFONTDIALOG),
        !           253:                       (HWND) lParam, LogFontProc, (LPARAM) &lf) ;
        !           254: 
        !           255:        bLogFontParam = FALSE ;
        !           256: 
        !           257:        break ;
        !           258: 
        !           259: 
        !           260:     case WM_COMMAND:
        !           261:     {
        !           262:         switch (LOWORD(wParam))
        !           263:         {
        !           264:           case IDOK:
        !           265:             DoChooseFontStuff(hwnd, &cf) ;  //create the dialog.
        !           266:             break ;
        !           267: 
        !           268:           case IDCANCEL:
        !           269:             EndDialog(hwnd, FALSE) ;
        !           270:             break ;
        !           271: 
        !           272:           case ID_RESETFONT:
        !           273: 
        !           274:             InitLogFontStruct(hwnd, &lf) ;  //reset all the structures.
        !           275:             InitFontStruct(hwnd, &cf) ;
        !           276:             FillFontDlg(hwnd, &cf) ;        //refill the dialog.
        !           277: 
        !           278:             CheckRadioButton(hwnd, ID_HDCSCREEN, ID_HDCPRINTER, ID_HDCSCREEN) ;
        !           279:             nHdcType = HDCSCREEN ;
        !           280: 
        !           281:             SendDlgItemMessage(hwnd, ID_NULLSTRUCTFONT, BM_SETCHECK, (WPARAM) 0, (LPARAM)0) ;
        !           282:             SendDlgItemMessage(hwnd, ID_PRELOADEDFONT,  BM_SETCHECK, (WPARAM) 0, (LPARAM)0) ;
        !           283: 
        !           284:             dwFontFlag = cf.Flags ;
        !           285:             FillFontsBox(hwnd, dwFontFlag) ;
        !           286:             ResetCheckBoxes(hwnd) ;
        !           287: 
        !           288:             SetFocus(GetDlgItem(hwnd, ID_STRUCTSIZEF)) ;
        !           289: 
        !           290:             break ;
        !           291: 
        !           292: 
        !           293:           case ID_HDCSCREEN:
        !           294:             nHdcType = HDCSCREEN ;
        !           295:             break ;
        !           296: 
        !           297:           case ID_HDCPRINTER:
        !           298:             nHdcType = HDCPRINTER ;
        !           299:             break ;
        !           300: 
        !           301:           case ID_HDCNULL:
        !           302:             nHdcType = HDCNULL ;
        !           303:             break ;
        !           304: 
        !           305:           case ID_HDCINVALID:
        !           306:             nHdcType = HDCINVALID ;
        !           307:             break ;
        !           308: 
        !           309:           case ID_EDITLOGFONT:
        !           310: 
        !           311:             /* Get the address of the logfont and then show the user what
        !           312:                is in it with the Logfont dialog box */
        !           313: 
        !           314:             GetDlgItemText(hwnd, ID_LOGFONTF, szNum, 30) ;
        !           315:             cf.lpLogFont = (LPLOGFONT) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ;
        !           316: 
        !           317:             DialogBox(hInst, MAKEINTRESOURCE(ID_LOGFONTDIALOG),
        !           318:                       hwnd, LogFontProc) ;
        !           319:             break ;
        !           320: 
        !           321: 
        !           322:           case F_TTONLY:
        !           323:           case F_ANSIONLY:
        !           324:           case F_PRINTERFONTS:
        !           325:           case F_SCREENFONTS:
        !           326:           case F_FIXEDPITCHONLY:
        !           327:           case F_NOOEMFONTS:
        !           328:           case F_NOVECTORFONTS:
        !           329:           case F_SCALABLEONLY:
        !           330:           case F_WYSIWYG:
        !           331:             HandleFontCheckBox(hwnd, LOWORD(wParam)) ;
        !           332:             break ;
        !           333: 
        !           334: 
        !           335:           case ID_MULTITHREADFONT:
        !           336: 
        !           337:             /* Set the dialog count to 2, disable the buttons in CDTEST's font
        !           338:                dialog so the user can't do anything until last dialog has
        !           339:                been terminated */
        !           340: 
        !           341:             nOpenFontDialogCount = 2 ;
        !           342: 
        !           343:             EnableFontButtons(hwndMainFont, FALSE) ;
        !           344: 
        !           345:             /* And then do the multithreading */
        !           346: 
        !           347:             MultiThreadFontDlg() ;
        !           348: 
        !           349:             break ;
        !           350: 
        !           351: 
        !           352:           default: break ;
        !           353:         }
        !           354:     }
        !           355: 
        !           356:     default:
        !           357: 
        !           358:       /*
        !           359:          If the help button is pressed in the ChooseFont()
        !           360:          dialog, it will send a message Registered with RegisterWindowMessage()
        !           361:          to the parent window.  The message nHelpMessage was registered
        !           362:          at application startup
        !           363: 
        !           364:          It must be detected with an IF statement because the value
        !           365:          returned by RegisterWindowMessage() is not a constant
        !           366:       */
        !           367: 
        !           368:       if (msg == nHelpMessage)
        !           369:         MessageBox(GetForegroundWindow(), TEXT("Hello from the help button"),
        !           370:                    TEXT("Font Help Button"), MB_OK | MB_APPLMODAL) ;
        !           371:       break ;
        !           372:   }
        !           373: 
        !           374:   return FALSE ;
        !           375: }
        !           376: 
        !           377: 
        !           378: 
        !           379: 
        !           380: 
        !           381: 
        !           382: 
        !           383: 
        !           384: /************************************************************************
        !           385: 
        !           386:   Function: InitFontStruct(HWND, LPCHOOSEFONT)
        !           387: 
        !           388:   Purpose:
        !           389: 
        !           390:     Fill the CHOOSEFONT structure passed as the second parameter with
        !           391:     some default values.
        !           392: 
        !           393:   Returns: Nothing.
        !           394: 
        !           395:   Comments:
        !           396: 
        !           397: 
        !           398: ************************************************************************/
        !           399: 
        !           400: void InitFontStruct(HWND hwnd, LPCHOOSEFONT pcf)
        !           401: {
        !           402:   pcf->lStructSize = sizeof(CHOOSEFONT) ;
        !           403:   pcf->hwndOwner = hwnd ;
        !           404:   pcf->hDC = (HDC) 0 ;
        !           405:   pcf->lpLogFont = &lf ;
        !           406:   pcf->iPointSize = 24 ;
        !           407:   pcf->Flags = CF_EFFECTS | CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT | CF_SHOWHELP | CF_APPLY ;
        !           408:   pcf->rgbColors = RGB(0, 255, 0) ;
        !           409:   pcf->lCustData = 0L ;
        !           410:   pcf->lpfnHook = FontHookProc ;
        !           411: 
        !           412:   lstrcpy(szFontTemplate, TEXT("fonttemp")) ;
        !           413:   pcf->lpTemplateName = szFontTemplate ;
        !           414: 
        !           415:   pcf->hInstance = (HANDLE) hInst ;
        !           416: 
        !           417:   lstrcpy(szFontStyle, TEXT("Bold")) ;
        !           418:   pcf->lpszStyle = szFontStyle ;
        !           419: 
        !           420:   pcf->nFontType = SCREEN_FONTTYPE ;
        !           421: 
        !           422:   pcf->nSizeMin = 8 ;
        !           423:   pcf->nSizeMax = 50 ;
        !           424: }
        !           425: 
        !           426: 
        !           427: 
        !           428: 
        !           429: 
        !           430: 
        !           431: 
        !           432: 
        !           433: 
        !           434: 
        !           435: /************************************************************************
        !           436: 
        !           437:   Function: FillFontDlg(HWND, LPCHOOSEFONT)
        !           438: 
        !           439:   Purpose:
        !           440: 
        !           441:     Fill CDTEST's font dialog with the values in the CHOOSEFONT structure
        !           442:     passed via the second parameter.
        !           443: 
        !           444:   Returns: Nothing.
        !           445: 
        !           446:   Comments:
        !           447: 
        !           448: 
        !           449: ************************************************************************/
        !           450: 
        !           451: void FillFontDlg(HWND hwnd, LPCHOOSEFONT pcf)
        !           452: {
        !           453:   wsprintf(szTemp, szLongFilter, pcf->lStructSize) ;
        !           454:   SetDlgItemText(hwnd, ID_STRUCTSIZEF, szTemp) ;
        !           455: 
        !           456:   wsprintf(szTemp, szLongFilter, (DWORD) pcf->hwndOwner) ;
        !           457:   SetDlgItemText(hwnd, ID_HWNDOWNERF, szTemp) ;
        !           458: 
        !           459:   wsprintf(szTemp, szLongFilter, (DWORD) pcf->hDC) ;
        !           460:   SetDlgItemText(hwnd, ID_HDCF, szTemp) ;
        !           461: 
        !           462:   wsprintf(szTemp, szLongFilter, (DWORD) pcf->hDC) ;
        !           463:   SetDlgItemText(hwnd, ID_HDCF, szTemp) ;
        !           464: 
        !           465:   wsprintf(szTemp, szLongFilter, (DWORD) pcf->lpLogFont) ;
        !           466:   SetDlgItemText(hwnd, ID_LOGFONTF, szTemp) ;
        !           467: 
        !           468:   wsprintf(szTemp, szLongFilter, (DWORD) pcf->iPointSize) ;
        !           469:   SetDlgItemText(hwnd, ID_POINTSIZEF, szTemp) ;
        !           470: 
        !           471:   wsprintf(szTemp, szLongFilter, pcf->Flags) ;
        !           472:   SetDlgItemText(hwnd, ID_FLAGSF, szTemp) ;
        !           473: 
        !           474:   wsprintf(szTemp, szLongFilter, pcf->rgbColors) ;
        !           475:   SetDlgItemText(hwnd, ID_RGBCOLORSF, szTemp) ;
        !           476: 
        !           477:   wsprintf(szTemp, szLongFilter, pcf->lCustData) ;
        !           478:   SetDlgItemText(hwnd, ID_CUSTDATAF, szTemp) ;
        !           479: 
        !           480:   wsprintf(szTemp, szLongFilter, (DWORD) pcf->lpfnHook) ;
        !           481:   SetDlgItemText(hwnd, ID_HOOKF, szTemp) ;
        !           482: 
        !           483:   SetDlgItemText(hwnd, ID_TEMPLATEF, pcf->lpTemplateName) ;
        !           484: 
        !           485:   wsprintf(szTemp, szLongFilter, (DWORD) pcf->hInstance) ;
        !           486:   SetDlgItemText(hwnd, ID_HINSTANCEF, szTemp) ;
        !           487: 
        !           488:   SetDlgItemText(hwnd, ID_STYLEF, pcf->lpszStyle) ;
        !           489: 
        !           490:   wsprintf(szTemp, szLongFilter, (int) pcf->nFontType) ;
        !           491:   SetDlgItemText(hwnd, ID_FONTTYPEF, szTemp) ;
        !           492: 
        !           493:   wsprintf(szTemp, szLongFilter, (int) pcf->nSizeMin) ;
        !           494:   SetDlgItemText(hwnd, ID_SIZEMINF, szTemp) ;
        !           495: 
        !           496:   wsprintf(szTemp, szLongFilter, (int) pcf->nSizeMax) ;
        !           497:   SetDlgItemText(hwnd, ID_SIZEMAXF, szTemp) ;
        !           498: 
        !           499: }
        !           500: 
        !           501: 
        !           502: 
        !           503: 
        !           504: 
        !           505: 
        !           506: 
        !           507: /************************************************************************
        !           508: 
        !           509:   Function: GetFontDlg(HWND, LPCHOOSEFONT)
        !           510: 
        !           511:   Purpose:
        !           512: 
        !           513:     Retrieve the users edits from CDTEST's font dialog and put them
        !           514:     in the CHOOSEFONT structure passed in as the second parameter
        !           515: 
        !           516:   Returns: Nothing.
        !           517: 
        !           518:   Comments:
        !           519: 
        !           520: 
        !           521: ************************************************************************/
        !           522: 
        !           523: void GetFontDlg(HWND hwnd, LPCHOOSEFONT pcf)
        !           524: {
        !           525:   BOOL b ;
        !           526:   TCHAR szNum[30] ;
        !           527: 
        !           528: #define WSIZEFO 30
        !           529: 
        !           530:   GetDlgItemText(hwnd, ID_STRUCTSIZEF, szNum, WSIZEFO) ;
        !           531:   pcf->lStructSize = MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           532: 
        !           533:   GetDlgItemText(hwnd, ID_HWNDOWNERF, szNum, WSIZEFO) ;
        !           534:   pcf->hwndOwner = (HWND) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           535: 
        !           536:   GetDlgItemText(hwnd, ID_LOGFONTF, szNum, WSIZEFO) ;
        !           537:   pcf->lpLogFont = (LPLOGFONT) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           538: 
        !           539:   GetDlgItemText(hwnd, ID_POINTSIZEF, szNum, WSIZEFO) ;
        !           540:   pcf->iPointSize = (int) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           541: 
        !           542:   GetDlgItemText(hwnd, ID_FLAGSF, szNum, WSIZEFO) ;
        !           543:   pcf->Flags = MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           544: 
        !           545:   GetDlgItemText(hwnd, ID_RGBCOLORSF, szNum, WSIZEFO) ;
        !           546:   pcf->rgbColors = MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           547: 
        !           548:   GetDlgItemText(hwnd, ID_CUSTDATAF, szNum, WSIZEFO) ;
        !           549:   pcf->lCustData = MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           550: 
        !           551:   GetDlgItemText(hwnd, ID_HOOKF, szNum, WSIZEFO) ;
        !           552:   pcf->lpfnHook = (LPCFHOOKPROC) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           553: 
        !           554:   GetDlgItemText(hwnd, ID_TEMPLATEF, szFontTemplate, 50) ;
        !           555: 
        !           556:   GetDlgItemText(hwnd, ID_HINSTANCEF, szNum, WSIZEFO) ;
        !           557:   pcf->hInstance = (HANDLE) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           558: 
        !           559:   GetDlgItemText(hwnd, ID_STYLEF, szFontStyle, 50) ;
        !           560: 
        !           561:   GetDlgItemText(hwnd, ID_FONTTYPEF, szNum, WSIZEFO) ;
        !           562:   pcf->nFontType = (int) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           563: 
        !           564:   GetDlgItemText(hwnd, ID_SIZEMINF, szNum, WSIZEFO) ;
        !           565:   pcf->nSizeMin = (int) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           566: 
        !           567:   GetDlgItemText(hwnd, ID_SIZEMAXF, szNum, WSIZEFO) ;
        !           568:   pcf->nSizeMax = (int) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           569: }
        !           570: 
        !           571: 
        !           572: 
        !           573: 
        !           574: 
        !           575: 
        !           576: 
        !           577: /************************************************************************
        !           578: 
        !           579:   Function: GetHdc(HWND, int)
        !           580: 
        !           581:   Purpose:
        !           582: 
        !           583:     Creates and returns an HDC of the type specified.
        !           584: 
        !           585: 
        !           586:   Returns: The HDC that it creates.
        !           587: 
        !           588: 
        !           589:   Comments:
        !           590: 
        !           591:     The NULL and INVALID HDCs are only useful to test if the common dialogs
        !           592:     handle an HDC that is not useful, but this function is also necessary
        !           593:     in that the HDC must be a printer HDC if ChooseFont() is called
        !           594:     with the CF_PRINTERFONTS flag bit set.
        !           595: 
        !           596:     To tell ChooseFont() to list only printer fonts:
        !           597: 
        !           598:     1.  Set the HDC in CDTEST's font dialog to "Printer"
        !           599: 
        !           600:     2.  Set the "Flags" edit box CF_PRINTERFONTS
        !           601: 
        !           602: 
        !           603: ************************************************************************/
        !           604: 
        !           605: 
        !           606: 
        !           607: HDC GetHdc(HWND hwnd, int nType)
        !           608: {
        !           609:   switch (nType)
        !           610:   {
        !           611:     case HDCSCREEN:
        !           612:         return GetDC(hwnd) ;
        !           613:         break ;
        !           614: 
        !           615:     case HDCNULL:
        !           616:         return (HDC) 0 ;
        !           617:         break ;
        !           618: 
        !           619:     case HDCINVALID:
        !           620:         return (HDC) 999 ;
        !           621:         break ;
        !           622: 
        !           623:     case HDCPRINTER:
        !           624: 
        !           625:         /* To get the HDC of the current printer, fill out a PRINTDLG
        !           626:            structure, and set it's flags to (PD_RETURNDC | PD_RETURNDEFAULT).
        !           627:            This will tell PrintDlg() to create you an HDC but not show
        !           628:            the Print dialog box. */
        !           629: 
        !           630:         pfd.lStructSize = sizeof(PRINTDLG) ;
        !           631:         pfd.hwndOwner = hwnd ;
        !           632:         pfd.hDevMode = (HANDLE) 0 ;
        !           633:         pfd.hDevNames = (HANDLE) 0 ;
        !           634:         pfd.Flags = PD_RETURNDC | PD_RETURNDEFAULT ;   //just get default printer
        !           635:         pfd.nFromPage = 0 ;
        !           636:         pfd.nToPage = 0 ;
        !           637:         pfd.nMinPage = 0 ;
        !           638:         pfd.nMaxPage = 0 ;
        !           639:         pfd.nCopies = 0 ;
        !           640:         pfd.hInstance = (HANDLE) hInst ;
        !           641: 
        !           642:         if (PrintDlg(&pfd) == 0)
        !           643:             MessageBox(hwnd, TEXT("Error: Could not create a printer DC!"),
        !           644:                        (LPTSTR) NULL, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL) ;
        !           645:         else
        !           646:            return pfd.hDC ;
        !           647: 
        !           648:         break ;
        !           649: 
        !           650:     default:
        !           651:         break ;
        !           652:   }
        !           653:   return (HDC) 0 ;
        !           654: }
        !           655: 
        !           656: 
        !           657: 
        !           658: 
        !           659: 
        !           660: 
        !           661: 
        !           662: 
        !           663: 
        !           664: /************************************************************************
        !           665: 
        !           666:   Function: LogFontProc(HWND, int)
        !           667: 
        !           668:   Purpose:
        !           669: 
        !           670:     The callback proc for the LogFont dialog box
        !           671: 
        !           672: 
        !           673:   Returns: BOOL -- depending on the situation.
        !           674: 
        !           675: 
        !           676:   Comments:
        !           677: 
        !           678: ************************************************************************/
        !           679: 
        !           680: 
        !           681: BOOL APIENTRY LogFontProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
        !           682: {
        !           683:   switch (msg)
        !           684:   {
        !           685:     case WM_INITDIALOG:
        !           686:         FillLogFontDlg(hwnd, cf.lpLogFont) ;  //start off with the one that
        !           687:                                               //is returned from ChooseFont()
        !           688:         break ;
        !           689: 
        !           690:     case WM_COMMAND:
        !           691:         switch(LOWORD(wParam))
        !           692:         {
        !           693:           case IDOK:
        !           694: 
        !           695:             GetLogFontDlg(hwnd, &lf) ;
        !           696: 
        !           697:             cf.lpLogFont = &lf ;
        !           698: 
        !           699:             EndDialog(hwnd, TRUE) ;
        !           700: 
        !           701:             break ;
        !           702: 
        !           703: 
        !           704: 
        !           705:           case ID_RESETLF:
        !           706: 
        !           707:             SetFocus(GetDlgItem(hwnd, ID_LFHEIGHT)) ;
        !           708: 
        !           709:             InitLogFontStruct(hwnd, &lf) ;
        !           710: 
        !           711:             FillLogFontDlg(hwnd, &lf) ;
        !           712: 
        !           713:             break ;
        !           714: 
        !           715: 
        !           716:           case IDCANCEL:
        !           717: 
        !           718:             EndDialog(hwnd, FALSE) ;
        !           719: 
        !           720:             break ;
        !           721: 
        !           722: 
        !           723:           default:
        !           724:             break ;
        !           725:         }
        !           726: 
        !           727:     default: break ;
        !           728:   }
        !           729: 
        !           730: 
        !           731:   return FALSE ;
        !           732: }
        !           733: 
        !           734: 
        !           735: 
        !           736: 
        !           737: 
        !           738: 
        !           739: 
        !           740: /************************************************************************
        !           741: 
        !           742:   Function: InitLogFontStruct(HWND, LPLOGFONT)
        !           743: 
        !           744:   Purpose:
        !           745: 
        !           746:     Fills the LOGFONT structure passed in as the second parameter with
        !           747:     some default values.
        !           748: 
        !           749:   Returns: Nothing.
        !           750: 
        !           751:   Comments:
        !           752: 
        !           753: ************************************************************************/
        !           754: 
        !           755: void InitLogFontStruct(HWND hwnd, LPLOGFONT plf)
        !           756: {
        !           757:   plf->lfHeight = 24 ;
        !           758:   plf->lfWidth  = 20 ;
        !           759:   plf->lfEscapement = 0 ;
        !           760:   plf->lfOrientation = 10 ;
        !           761:   plf->lfWeight = 400 ;
        !           762:   plf->lfItalic = FALSE ;
        !           763:   plf->lfUnderline = FALSE ;
        !           764:   plf->lfStrikeOut = FALSE ;
        !           765:   plf->lfCharSet = ANSI_CHARSET ;
        !           766:   plf->lfOutPrecision = OUT_DEFAULT_PRECIS ;
        !           767:   plf->lfClipPrecision = CLIP_DEFAULT_PRECIS ;
        !           768:   plf->lfQuality = DEFAULT_QUALITY ;
        !           769:   plf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE ;
        !           770: 
        !           771:   szFaceName[0] = (TCHAR) 0 ;
        !           772:   lstrcpy(plf->lfFaceName, szFaceName) ;
        !           773: }
        !           774: 
        !           775: 
        !           776: 
        !           777: 
        !           778: 
        !           779: 
        !           780: /************************************************************************
        !           781: 
        !           782:   Function: FillLogFontDlg(HWND, LPLOGFONT)
        !           783: 
        !           784:   Purpose:
        !           785: 
        !           786:     Fills CDTEST's logfont dialog with the values in the logfont that
        !           787:     is passed in as the second parameter.
        !           788: 
        !           789:   Returns: Nothing.
        !           790: 
        !           791:   Comments:
        !           792: 
        !           793: ************************************************************************/
        !           794: 
        !           795: void FillLogFontDlg(HWND hwnd, LPLOGFONT plf)
        !           796: {
        !           797:   TCHAR szTemp[50] ;
        !           798: 
        !           799:   LPLOGFONT pl = plf ;
        !           800: 
        !           801:   if (bLogFontParam)    //Are creating this dialog in response to the
        !           802:     pl = &lfWM_CF_LF ;  //WM_CHOOSEFONT_GETLOGFONT message ?
        !           803: 
        !           804:   if (!pl)              //Avert a ghastly exception error
        !           805:     return ;
        !           806: 
        !           807:   wsprintf(szTemp, szLongFilter, pl->lfHeight) ;
        !           808:   SetDlgItemText(hwnd, ID_LFHEIGHT, szTemp) ;
        !           809: 
        !           810:   wsprintf(szTemp, szLongFilter, pl->lfWidth) ;
        !           811:   SetDlgItemText(hwnd, ID_LFWIDTH, szTemp) ;
        !           812: 
        !           813:   wsprintf(szTemp, szLongFilter, pl->lfEscapement) ;
        !           814:   SetDlgItemText(hwnd, ID_LFESCAPEMENT, szTemp) ;
        !           815: 
        !           816:   wsprintf(szTemp, szLongFilter, pl->lfOrientation) ;
        !           817:   SetDlgItemText(hwnd, ID_LFORIENTATION, szTemp) ;
        !           818: 
        !           819:   wsprintf(szTemp, szLongFilter, pl->lfWeight) ;
        !           820:   SetDlgItemText(hwnd, ID_LFWEIGHT, szTemp) ;
        !           821: 
        !           822:   wsprintf(szTemp, szShortFilter, pl->lfItalic) ;
        !           823:   SetDlgItemText(hwnd, ID_LFITALIC, szTemp) ;
        !           824: 
        !           825:   wsprintf(szTemp, szShortFilter, pl->lfUnderline) ;
        !           826:   SetDlgItemText(hwnd, ID_LFUNDERLINE, szTemp) ;
        !           827: 
        !           828:   wsprintf(szTemp, szShortFilter, pl->lfStrikeOut) ;
        !           829:   SetDlgItemText(hwnd, ID_LFSTRIKEOUT, szTemp) ;
        !           830: 
        !           831:   wsprintf(szTemp, szShortFilter, pl->lfCharSet) ;
        !           832:   SetDlgItemText(hwnd, ID_LFCHARSET, szTemp) ;
        !           833: 
        !           834:   wsprintf(szTemp, szShortFilter, pl->lfOutPrecision) ;
        !           835:   SetDlgItemText(hwnd, ID_LFOUTP, szTemp) ;
        !           836: 
        !           837:   wsprintf(szTemp, szShortFilter, pl->lfClipPrecision) ;
        !           838:   SetDlgItemText(hwnd, ID_LFCLIPP, szTemp) ;
        !           839: 
        !           840:   wsprintf(szTemp, szShortFilter, pl->lfQuality) ;
        !           841:   SetDlgItemText(hwnd, ID_LFQUALITY, szTemp) ;
        !           842: 
        !           843:   wsprintf(szTemp, szShortFilter, pl->lfPitchAndFamily) ;
        !           844:   SetDlgItemText(hwnd, ID_LFPITCHANDFAM, szTemp) ;
        !           845: 
        !           846:   SetDlgItemText(hwnd, ID_LFFACENAME, (LPTSTR) pl->lfFaceName) ;
        !           847: }
        !           848: 
        !           849: 
        !           850: 
        !           851: 
        !           852: 
        !           853: 
        !           854: /************************************************************************
        !           855: 
        !           856:   Function: GetLogFontDlg(HWND, LPLOGFONT)
        !           857: 
        !           858:   Purpose:
        !           859: 
        !           860:     Retrieves the users edits in CDTEST's Logfont dialog and puts them
        !           861:     into the LOGFONT struct that is passed as the second parameter.
        !           862: 
        !           863:   Returns: Nothing.
        !           864: 
        !           865:   Comments:
        !           866: 
        !           867: ************************************************************************/
        !           868: 
        !           869: void GetLogFontDlg(HWND hwnd, LPLOGFONT plf)
        !           870: {
        !           871:   BOOL b ;
        !           872:   TCHAR szNum[30] ;
        !           873: 
        !           874:   if (bLogFontParam)  //if we are just viewing the logfont because we sent a
        !           875:     return ;          //WM_CHOOSEFONT_GETLOGFONT message, don't change the Logfont Struct
        !           876:                       //that ChooseFont() gives us...
        !           877: 
        !           878:   #define LFSIZE 30
        !           879: 
        !           880:   GetDlgItemText(hwnd, ID_LFHEIGHT, szNum, LFSIZE) ;
        !           881:   plf->lfHeight = MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           882: 
        !           883:   GetDlgItemText(hwnd, ID_LFWIDTH, szNum, LFSIZE) ;
        !           884:   plf->lfWidth = MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           885: 
        !           886:   GetDlgItemText(hwnd, ID_LFESCAPEMENT, szNum, LFSIZE) ;
        !           887:   plf->lfEscapement = MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           888: 
        !           889:   GetDlgItemText(hwnd, ID_LFORIENTATION, szNum, LFSIZE) ;
        !           890:   plf->lfOrientation = MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           891: 
        !           892:   GetDlgItemText(hwnd, ID_LFWEIGHT, szNum, LFSIZE) ;
        !           893:   plf->lfWeight = MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           894: 
        !           895:   GetDlgItemText(hwnd, ID_LFITALIC, szNum, LFSIZE) ;
        !           896:   plf->lfItalic = (BYTE) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           897: 
        !           898:   GetDlgItemText(hwnd, ID_LFUNDERLINE, szNum, LFSIZE) ;
        !           899:   plf->lfUnderline = (BYTE) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           900: 
        !           901:   GetDlgItemText(hwnd, ID_LFSTRIKEOUT, szNum, LFSIZE) ;
        !           902:   plf->lfStrikeOut = (BYTE) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           903: 
        !           904:   GetDlgItemText(hwnd, ID_LFCHARSET, szNum, LFSIZE) ;
        !           905:   plf->lfCharSet = (BYTE) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           906: 
        !           907:   GetDlgItemText(hwnd, ID_LFOUTP, szNum, LFSIZE) ;
        !           908:   plf->lfOutPrecision = (BYTE) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           909: 
        !           910:   GetDlgItemText(hwnd, ID_LFCLIPP, szNum, LFSIZE) ;
        !           911:   plf->lfClipPrecision = (BYTE) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           912: 
        !           913:   GetDlgItemText(hwnd, ID_LFQUALITY, szNum, LFSIZE) ;
        !           914:   plf->lfQuality = (BYTE) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           915: 
        !           916:   GetDlgItemText(hwnd, ID_LFPITCHANDFAM, szNum, LFSIZE) ;
        !           917:   plf->lfPitchAndFamily = (BYTE) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ;
        !           918: 
        !           919:   GetDlgItemText(hwnd, ID_LFFACENAME, (LPTSTR) plf->lfFaceName, 32) ;
        !           920: }
        !           921: 
        !           922: 
        !           923: 
        !           924: 
        !           925: 
        !           926: 
        !           927: 
        !           928: 
        !           929: /************************************************************************
        !           930: 
        !           931:   Function: FontHookProc(HWND, UINT, UINT, LONG)
        !           932: 
        !           933:   Purpose: The callback function that acts as the hook proc for
        !           934:            the ChooseFont() dialog.
        !           935: 
        !           936: 
        !           937:   Returns: TRUE to discard the message.  FALSE to send the message on
        !           938:            to the normal dialog processing done by the ChooseFont()
        !           939:            function.
        !           940: 
        !           941:   Comments:
        !           942: 
        !           943: ************************************************************************/
        !           944: 
        !           945: UINT APIENTRY FontHookProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
        !           946: {
        !           947:   LPCHOOSEFONT pCf ;
        !           948:   TCHAR szMsg[50] ;
        !           949: 
        !           950:   switch(msg)
        !           951:   {
        !           952:     case WM_INITDIALOG:
        !           953: 
        !           954:       pCf = (LPCHOOSEFONT) lParam ;
        !           955: 
        !           956:       if (pCf->lCustData != 0L)
        !           957:       {
        !           958:         wsprintf(szMsg, TEXT("CHOOSEFONT->lCustData is: %ld"), pCf->lCustData) ;
        !           959:         MessageBox(hwnd, szMsg, TEXT("lCustData Sent!"), MB_OK) ;
        !           960:       }
        !           961: 
        !           962:       SetWindowText(hwnd, TEXT("Font Hook Proc Dialog")) ;
        !           963: 
        !           964:       break ;
        !           965: 
        !           966:     case WM_COMMAND:
        !           967: 
        !           968:         /* NOTE: This button will only be available if the user creates the
        !           969:            ChooseFont() dialog with the CF_ENABLETEMPLATE or CF_ENABLETEMPLATEHANDLE
        !           970:            flag.
        !           971: 
        !           972:            This button will only work if the ChooseFont() dialog is created
        !           973:            with the CF_ENABLEHOOK flag.  So, to get full functionality from
        !           974:            this button:
        !           975: 
        !           976:            1.  Enter (CF_ENABLEHOOK | CF_ENABLETEMPLATE | CF_SCREENFONTS)
        !           977:                in the "Flags" edit box of CDTEST'S Font dialog.
        !           978: 
        !           979:            2.  Click OK
        !           980:         */
        !           981: 
        !           982: 
        !           983: 
        !           984:         /* The parent will send the WM_CHOOSEFONT_GETLOGFONT message and
        !           985:            display it's findings in a LogFont dialog if it gets this message */
        !           986: 
        !           987:         if (LOWORD(wParam) == ID_SEND_WM_CF_LF_MSG)
        !           988:           SendMessage(GetParent(hwnd), WM_CF_LF, 0, (LPARAM) hwnd) ;
        !           989: 
        !           990:         break ;
        !           991: 
        !           992: 
        !           993:     default:
        !           994:       break ;
        !           995:   }
        !           996: 
        !           997:   return FALSE ;   //send msg to the common dialog code
        !           998: }
        !           999: 
        !          1000: 
        !          1001: 
        !          1002: 
        !          1003: 
        !          1004: 
        !          1005: 
        !          1006: 
        !          1007: 
        !          1008: /************************************************************************
        !          1009: 
        !          1010:   Function: GetFontDlgHandle(void)
        !          1011: 
        !          1012:   Purpose:  Finds and loads the custom template resource and returns a
        !          1013:             handle to it.
        !          1014: 
        !          1015: 
        !          1016:   Returns: A handle to the custom template resource.
        !          1017: 
        !          1018:   Comments:
        !          1019: 
        !          1020: ************************************************************************/
        !          1021: 
        !          1022: HANDLE GetFontDlgHandle(void)
        !          1023: {
        !          1024: 
        !          1025:   hResFont = FindResource(hInst, TEXT("fonttemp"), RT_DIALOG) ;
        !          1026: 
        !          1027:   hDialogFont = LoadResource(hInst, hResFont) ;
        !          1028: 
        !          1029: 
        !          1030:   return hDialogFont ;
        !          1031: }
        !          1032: 
        !          1033: 
        !          1034: 
        !          1035: 
        !          1036: 
        !          1037: 
        !          1038: 
        !          1039: 
        !          1040: /************************************************************************
        !          1041: 
        !          1042:   Function: EnumFontsProc(LPLOGFONT, LPTEXTMETRIC, DWORD, LONG)
        !          1043: 
        !          1044:   Purpose: Acts as a callback function for the EnumFontFamilies()
        !          1045:            function.
        !          1046: 
        !          1047:   Returns: 0 if the font enumeration should stop.  1 to ask for the
        !          1048:            next font.
        !          1049: 
        !          1050:   Comments:
        !          1051: 
        !          1052:     EnumFontFamilies will find the fonts on the system and call this
        !          1053:     function each time it finds a font.  Pointers to the LOGFONT and
        !          1054:     TEXTMETRIC structures the describe the font are passed as the first
        !          1055:     and second arguments, so we can determine if the fonts we get
        !          1056:     meet the specs we want.  If they do, we can add them to the font
        !          1057:     list box in CDTEST's Font dialog.
        !          1058: 
        !          1059:     NOTE:
        !          1060: 
        !          1061:     None of this affects the performance of ChooseFont().  This serves
        !          1062:     only to illustrate how ChooseFont() finds the fonts you request based
        !          1063:     on the flags you pass to the ChooseFont() function.
        !          1064: 
        !          1065:     The fonts found with this function should be the same as the ones
        !          1066:     found by ChooseFont() for any flag combination.
        !          1067: 
        !          1068: 
        !          1069: ************************************************************************/
        !          1070: 
        !          1071: 
        !          1072: int CALLBACK EnumFontsProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
        !          1073:                            DWORD dwStyle, LONG lParam)
        !          1074: {
        !          1075:   UINT i ;
        !          1076: 
        !          1077:   /* check to see if the font is already there right off the bat
        !          1078:      and just continue the enumeration if it is...        */
        !          1079: 
        !          1080: 
        !          1081:   i = SendDlgItemMessage((HWND) lParam, ID_FONTLIST, LB_FINDSTRINGEXACT, (WPARAM) 0,
        !          1082:                          (LONG) (LPTSTR) lplf->lfFaceName) ;
        !          1083: 
        !          1084:   if (i != LB_ERR)
        !          1085:   {
        !          1086:     if (bScreen)     //if we are adding it for the first time
        !          1087:       return 1 ;
        !          1088: 
        !          1089:     //else, we are adding printer fonts, so if we find one that is already there
        !          1090:     //it must be available for both the printer and the screen...
        !          1091: 
        !          1092:     else
        !          1093:     {
        !          1094:       SendDlgItemMessage((HWND) lParam, ID_FONTLIST, LB_SETITEMDATA, i,
        !          1095:                           FONT_TYPE_WYSIWYG) ;
        !          1096:       return 1 ;
        !          1097:     }
        !          1098:   }
        !          1099: 
        !          1100: 
        !          1101:   //Get rid of any fonts that we don't want...
        !          1102: 
        !          1103:   if ((dwFontFlag & CF_TTONLY) && (!(dwStyle & TRUETYPE_FONTTYPE)))
        !          1104:     return 1 ;
        !          1105: 
        !          1106:   if ((dwFontFlag & CF_SCALABLEONLY) && (dwStyle & RASTER_FONTTYPE))
        !          1107:     return 1 ;
        !          1108: 
        !          1109:   if ((dwFontFlag & CF_ANSIONLY) && (lplf->lfCharSet != ANSI_CHARSET))
        !          1110:     return 1 ;
        !          1111: 
        !          1112:   if ((dwFontFlag & CF_FIXEDPITCHONLY) && (lplf->lfPitchAndFamily & VARIABLE_PITCH))
        !          1113:     return 1 ;
        !          1114: 
        !          1115:   if ((dwFontFlag & CF_NOVECTORFONTS) && (lplf->lfCharSet == OEM_CHARSET))
        !          1116:     return 1 ;
        !          1117: 
        !          1118: 
        !          1119:   //if there is a font to be added, add it.
        !          1120: 
        !          1121:   if (*(lplf->lfFaceName))
        !          1122:     SendDlgItemMessage((HWND) lParam, ID_FONTLIST, LB_ADDSTRING,
        !          1123:                      (WPARAM) 0, (LONG) (LPTSTR) lplf->lfFaceName) ;
        !          1124: 
        !          1125:   return 1 ;
        !          1126: }
        !          1127: 
        !          1128: 
        !          1129: 
        !          1130: 
        !          1131: 
        !          1132: 
        !          1133: 
        !          1134: 
        !          1135: /************************************************************************
        !          1136: 
        !          1137:   Function: FillFontsBox(HWND, DWORD)
        !          1138: 
        !          1139:   Purpose: Enumerates all fonts on the system and sends the ones that
        !          1140:            meet the criteria of the dwFlags parameter (CF_SCREENFONTS,
        !          1141:            CF_SCALABLEONLY, etc).
        !          1142: 
        !          1143:   Returns: Nothing.
        !          1144: 
        !          1145:   Comments:
        !          1146: 
        !          1147: 
        !          1148: ************************************************************************/
        !          1149: 
        !          1150: void FillFontsBox(HWND hwnd, DWORD dwFlags)
        !          1151: {
        !          1152:   HDC hdc ;
        !          1153:   HWND hwndControl ;
        !          1154:   DWORD dwData ;
        !          1155:   int nItemCount ;
        !          1156: 
        !          1157: 
        !          1158:   /* Empty the list box, and turn of the redraw because we may need
        !          1159:      to remove some fonts after they are added if the user calls this
        !          1160:      function with the CF_WYSIWYG flag bit set. */
        !          1161: 
        !          1162:   SendDlgItemMessage(hwnd, ID_FONTLIST, LB_RESETCONTENT, (WPARAM)0, (LPARAM) 0) ;
        !          1163: 
        !          1164:   hwndControl = GetDlgItem(hwnd, ID_FONTLIST) ;
        !          1165: 
        !          1166:   SendMessage(hwndControl, WM_SETREDRAW, FALSE, 0L) ;
        !          1167: 
        !          1168: 
        !          1169:   /* Now call EnumFontFamilies() for each type of HDC requested */
        !          1170: 
        !          1171:   if (dwFlags & CF_SCREENFONTS)
        !          1172:   {
        !          1173:     bScreen = TRUE ;
        !          1174:     hdc = GetHdc(hwnd, HDCSCREEN) ;
        !          1175:     EnumFontFamilies(hdc, (LPTSTR) NULL, (FONTENUMPROC) EnumFontsProc, (LONG) hwnd) ;
        !          1176:     ReleaseDC(hwnd, hdc) ;
        !          1177:   }
        !          1178: 
        !          1179:   if (dwFlags & CF_PRINTERFONTS)
        !          1180:   {
        !          1181:     bScreen = FALSE ;
        !          1182:     hdc = GetHdc(hwnd, HDCPRINTER) ;
        !          1183:     EnumFontFamilies(hdc, (LPTSTR) NULL, (FONTENUMPROC) EnumFontsProc, (LONG) hwnd) ;
        !          1184:     ReleaseDC(hwnd, hdc) ;
        !          1185:   }
        !          1186: 
        !          1187: 
        !          1188:   /* Special case:  If the CF_WYSIWYG flag is used, we have to enumerate
        !          1189:      the fonts in both HDCs and then remove all the ones that are not
        !          1190:      both printer fonts and screen fonts. */
        !          1191: 
        !          1192:   if (dwFontFlag & CF_WYSIWYG)
        !          1193:   {
        !          1194:     nItemCount = SendDlgItemMessage(hwnd, ID_FONTLIST, LB_GETCOUNT, 0, 0L) ;
        !          1195: 
        !          1196:     nItemCount-- ;   //the list is zero based
        !          1197: 
        !          1198:     while (nItemCount >= 0)
        !          1199:     {
        !          1200:       dwData = SendDlgItemMessage(hwnd, ID_FONTLIST, LB_GETITEMDATA, nItemCount, 0L) ;
        !          1201: 
        !          1202:       if (dwData != FONT_TYPE_WYSIWYG)
        !          1203:       {
        !          1204:         SendDlgItemMessage(hwnd, ID_FONTLIST, LB_DELETESTRING, nItemCount, 0L) ;
        !          1205:       }
        !          1206: 
        !          1207:       nItemCount-- ;
        !          1208:     }
        !          1209:   }
        !          1210: 
        !          1211: 
        !          1212:   /* Now redraw the font list */
        !          1213: 
        !          1214:   SendMessage(hwndControl, WM_SETREDRAW, TRUE, 0L) ;
        !          1215:   InvalidateRect(hwndControl, NULL, FALSE) ;
        !          1216: 
        !          1217:   return ;
        !          1218: }
        !          1219: 
        !          1220: 
        !          1221: 
        !          1222: 
        !          1223: 
        !          1224: 
        !          1225: /************************************************************************
        !          1226: 
        !          1227:   Function: ResetCheckBoxes(HWND)
        !          1228: 
        !          1229:   Purpose: Checks the checkboxes that control what fonts are listed in
        !          1230:            CDTEST's font list box.
        !          1231: 
        !          1232:   Returns: Nothing.
        !          1233: 
        !          1234:   Comments:
        !          1235: 
        !          1236: 
        !          1237: ************************************************************************/
        !          1238: 
        !          1239: void ResetCheckBoxes(HWND hwnd)
        !          1240: {
        !          1241: 
        !          1242:   SendDlgItemMessage(hwnd, F_TTONLY,          BM_SETCHECK, dwFontFlag & CF_TTONLY         ? 1 : 0, (LPARAM)0) ;
        !          1243:   SendDlgItemMessage(hwnd, F_ANSIONLY,        BM_SETCHECK, dwFontFlag & CF_ANSIONLY       ? 1 : 0, (LPARAM)0) ;
        !          1244:   SendDlgItemMessage(hwnd, F_SCREENFONTS,     BM_SETCHECK, dwFontFlag & CF_SCREENFONTS    ? 1 : 0, (LPARAM)0) ;
        !          1245:   SendDlgItemMessage(hwnd, F_PRINTERFONTS,    BM_SETCHECK, dwFontFlag & CF_PRINTERFONTS   ? 1 : 0, (LPARAM)0) ;
        !          1246:   SendDlgItemMessage(hwnd, F_NOOEMFONTS,      BM_SETCHECK, dwFontFlag & CF_NOOEMFONTS     ? 1 : 0, (LPARAM)0) ;
        !          1247:   SendDlgItemMessage(hwnd, F_NOVECTORFONTS,   BM_SETCHECK, dwFontFlag & CF_NOVECTORFONTS  ? 1 : 0, (LPARAM)0) ;
        !          1248:   SendDlgItemMessage(hwnd, F_SCALABLEONLY,    BM_SETCHECK, dwFontFlag & CF_SCALABLEONLY   ? 1 : 0, (LPARAM)0) ;
        !          1249:   SendDlgItemMessage(hwnd, F_WYSIWYG,         BM_SETCHECK, dwFontFlag & CF_WYSIWYG        ? 1 : 0, (LPARAM)0) ;
        !          1250:   SendDlgItemMessage(hwnd, F_FIXEDPITCHONLY,  BM_SETCHECK, dwFontFlag & CF_FIXEDPITCHONLY ? 1 : 0, (LPARAM)0) ;
        !          1251: 
        !          1252: }
        !          1253: 
        !          1254: 
        !          1255: 
        !          1256: 
        !          1257: 
        !          1258: 
        !          1259: /************************************************************************
        !          1260: 
        !          1261:   Function: HandleFontCheckBox(HWND)
        !          1262: 
        !          1263:   Purpose: If the user clicks one of the fonts in the CDTEST's list of
        !          1264:            valid font types, this function will check the correct boxes
        !          1265:            and set the correct values in the flag which keeps track of
        !          1266:            which fonts are to be enumerated and added to CDTEST's font
        !          1267:            list box.
        !          1268: 
        !          1269: 
        !          1270:   Returns: Nothing.
        !          1271: 
        !          1272:   Comments:
        !          1273: 
        !          1274:     CF_NOOEMFONTS and CF_NOVECTORFONTS are identical.
        !          1275: 
        !          1276: 
        !          1277: ************************************************************************/
        !          1278: 
        !          1279: void HandleFontCheckBox(HWND hwnd, int nID)
        !          1280: {
        !          1281:   DWORD dwTemp ;
        !          1282: 
        !          1283:   dwTemp = dwFontFlag ;
        !          1284: 
        !          1285:   switch (nID)
        !          1286:   {
        !          1287:     case F_TTONLY:
        !          1288: 
        !          1289:       /* TTONLY is a special case.  If we only want Truetype fonts,
        !          1290:          turn off irrelevant flags */
        !          1291: 
        !          1292:       if (!(dwFontFlag & CF_TTONLY)) //if we're turning this flag on...
        !          1293:       {
        !          1294:         dwFontFlag = 0L ;  //turn everyone off but the following:
        !          1295: 
        !          1296:         dwFontFlag |= CF_TTONLY ;
        !          1297: 
        !          1298:         if (dwTemp & CF_ANSIONLY)
        !          1299:           dwFontFlag |= CF_ANSIONLY ;
        !          1300: 
        !          1301:         if (dwTemp & CF_FIXEDPITCHONLY)
        !          1302:           dwFontFlag |= CF_FIXEDPITCHONLY ;
        !          1303: 
        !          1304:         if (dwTemp & CF_SCREENFONTS)
        !          1305:           dwFontFlag |= CF_SCREENFONTS ;
        !          1306: 
        !          1307:         if (dwTemp & CF_PRINTERFONTS)
        !          1308:           dwFontFlag |= CF_PRINTERFONTS ;
        !          1309:       }
        !          1310:       else
        !          1311:       {
        !          1312:         dwFontFlag ^= CF_TTONLY ;
        !          1313:       }
        !          1314: 
        !          1315: 
        !          1316:       break ;
        !          1317: 
        !          1318:     case F_ANSIONLY:
        !          1319:       dwFontFlag ^= CF_ANSIONLY ;        //otherwise toggle the bit.
        !          1320:       dwFontFlag &= ~CF_WYSIWYG ;
        !          1321: 
        !          1322:       break ;
        !          1323: 
        !          1324:     case F_PRINTERFONTS:
        !          1325:       dwFontFlag ^= CF_PRINTERFONTS ;
        !          1326: 
        !          1327:       break ;
        !          1328: 
        !          1329:     case F_SCREENFONTS:
        !          1330:       dwFontFlag ^= CF_SCREENFONTS ;
        !          1331: 
        !          1332:       break ;
        !          1333: 
        !          1334:     case F_FIXEDPITCHONLY:
        !          1335:       dwFontFlag ^= CF_FIXEDPITCHONLY ;
        !          1336: 
        !          1337:       break ;
        !          1338: 
        !          1339:     case F_NOOEMFONTS:
        !          1340:       dwFontFlag ^= CF_NOOEMFONTS ;
        !          1341: 
        !          1342:       break ;
        !          1343: 
        !          1344:     case F_NOVECTORFONTS:
        !          1345:       dwFontFlag ^= CF_NOVECTORFONTS ;
        !          1346: 
        !          1347:       break ;
        !          1348: 
        !          1349:     case F_SCALABLEONLY:
        !          1350:       dwFontFlag ^= CF_SCALABLEONLY ;
        !          1351: 
        !          1352:       break ;
        !          1353: 
        !          1354:     case F_WYSIWYG:                        //We want fonts for both the
        !          1355:                                            //screen and the printer...
        !          1356:       dwFontFlag ^= CF_WYSIWYG ;
        !          1357: 
        !          1358:       if (dwFontFlag & CF_WYSIWYG)
        !          1359:         dwFontFlag |= (CF_SCREENFONTS | CF_PRINTERFONTS | CF_SCALABLEONLY) ;
        !          1360: 
        !          1361:       break ;
        !          1362: 
        !          1363:     default: break ;
        !          1364:   }
        !          1365: 
        !          1366:   ResetCheckBoxes(hwnd) ;
        !          1367:   FillFontsBox(hwnd, dwFontFlag) ;
        !          1368: }
        !          1369: 
        !          1370: 
        !          1371: 
        !          1372: 
        !          1373: 
        !          1374: 
        !          1375: 
        !          1376: /************************************************************************
        !          1377: 
        !          1378:   Function: DoChooseFontStuff(HWND, LPCHOOSEFONT)
        !          1379: 
        !          1380:   Purpose:
        !          1381: 
        !          1382:     Calls the ChooseFont() function.
        !          1383: 
        !          1384:   Returns: Nothing.
        !          1385: 
        !          1386:   Comments:
        !          1387: 
        !          1388: 
        !          1389: ************************************************************************/
        !          1390: 
        !          1391: 
        !          1392: void DoChooseFontStuff(HWND hwnd, LPCHOOSEFONT pcf)
        !          1393: {
        !          1394:   BOOL bRet = FALSE ;
        !          1395: 
        !          1396:   if (IsDlgButtonChecked(hwnd, ID_PRELOADEDFONT) == 1)
        !          1397:   {
        !          1398:     pcf->hInstance = GetFontDlgHandle() ;
        !          1399:     wsprintf(szTemp, szLongFilter, pcf->hInstance) ;
        !          1400:     SetDlgItemText(hwnd, ID_HINSTANCEF, szTemp) ;
        !          1401:   }
        !          1402: 
        !          1403:   pcf->hDC = GetHdc(hwnd, nHdcType) ;
        !          1404: 
        !          1405:   wsprintf(szTemp, szLongFilter, pcf->hDC) ;
        !          1406:   SetDlgItemText(hwnd, ID_HDCF, szTemp) ;
        !          1407: 
        !          1408: 
        !          1409:   GetFontDlg(hwnd, pcf) ;
        !          1410: 
        !          1411: 
        !          1412:   if (IsDlgButtonChecked(hwnd, ID_NULLSTRUCTFONT) == 1)
        !          1413:     bRet = ChooseFont((LPCHOOSEFONT)NULL) ;
        !          1414:   else
        !          1415:     bRet = ChooseFont(pcf) ;
        !          1416: 
        !          1417:   wsprintf(szTemp, szLongFilter, CommDlgExtendedError()) ;
        !          1418:   SetDlgItemText(hwnd, ID_ERRORF, szTemp) ;
        !          1419: 
        !          1420:   if (pcf->hDC)
        !          1421:   {
        !          1422:     ReleaseDC(hwnd, pcf->hDC) ;   //free the HDC that we used if we called
        !          1423:     pcf->hDC = (HDC) 0 ;          //the function with a valid HDC.
        !          1424:   }
        !          1425: 
        !          1426:   if (hDialogFont)
        !          1427:   {
        !          1428:     FreeResource(hDialogFont) ;
        !          1429:     hDialogFont = (HANDLE) 0 ;
        !          1430:     hResFont = (HANDLE) 0 ;
        !          1431:   }
        !          1432: 
        !          1433:   wsprintf(szTemp, szShortFilter, bRet) ;     //fill results into the Font dlg
        !          1434:   SetDlgItemText(hwnd, ID_RETURNF, szTemp) ;
        !          1435: 
        !          1436:   FillFontDlg(hwnd, pcf) ;
        !          1437: }
        !          1438: 
        !          1439: 
        !          1440: 
        !          1441: 
        !          1442: 
        !          1443: 
        !          1444: /************************************************************************
        !          1445: 
        !          1446:   Function: FontThreadProc1(LPDWORD)
        !          1447: 
        !          1448:   Purpose:
        !          1449: 
        !          1450:     Acts as the starting address for thread 1
        !          1451: 
        !          1452:   Returns: Any DWORD value.
        !          1453: 
        !          1454:   Comments:
        !          1455: 
        !          1456: 
        !          1457: ************************************************************************/
        !          1458: 
        !          1459: DWORD FontThreadProc1(LPDWORD pdw)
        !          1460: {
        !          1461:   DoChooseFontStuff(hwndMainFont, &cfThread1) ;
        !          1462: 
        !          1463:   PostMessage(hwndMainFont, UMSG_DECREMENTDLGCOUNT, 0, 0L ) ;
        !          1464: 
        !          1465:   return 0L ;
        !          1466: }
        !          1467: 
        !          1468: 
        !          1469: 
        !          1470: 
        !          1471: 
        !          1472: 
        !          1473: 
        !          1474: /************************************************************************
        !          1475: 
        !          1476:   Function: FontThreadProc2(LPDWORD)
        !          1477: 
        !          1478:   Purpose:
        !          1479: 
        !          1480:     Acts as the starting address for thread 2
        !          1481: 
        !          1482:   Returns: Any DWORD value.
        !          1483: 
        !          1484:   Comments:
        !          1485: 
        !          1486: 
        !          1487: ************************************************************************/
        !          1488: 
        !          1489: 
        !          1490: DWORD FontThreadProc2(LPDWORD pdw)
        !          1491: {
        !          1492:   DoChooseFontStuff(hwndMainFont, &cfThread2) ;
        !          1493: 
        !          1494:   PostMessage(hwndMainFont, UMSG_DECREMENTDLGCOUNT, 0, 0L ) ;
        !          1495: 
        !          1496:   return 0L ;
        !          1497: }
        !          1498: 
        !          1499: 
        !          1500: 
        !          1501: 
        !          1502: 
        !          1503: 
        !          1504: 
        !          1505: /************************************************************************
        !          1506: 
        !          1507:   Function: MultiThreadFontDlg(void)
        !          1508: 
        !          1509:   Purpose:
        !          1510: 
        !          1511:     Create the two threads that will in turn create two ChooseFont()
        !          1512:     dialogs.
        !          1513: 
        !          1514:   Returns: Nothing.
        !          1515: 
        !          1516:   Comments:
        !          1517: 
        !          1518:     Multithreading note:
        !          1519: 
        !          1520:     This function will return before the common dialog functions return.
        !          1521:     Therefore, do not pass any parameters to this function that will be
        !          1522:     referenced by the common dialogs because as soon as this function
        !          1523:     ends those parameters will be gone.
        !          1524: 
        !          1525: ************************************************************************/
        !          1526: 
        !          1527: void MultiThreadFontDlg(void)
        !          1528: {
        !          1529: 
        !          1530:   dwFontThreadParm1 = dwFontThreadParm2 = 0L ;
        !          1531: 
        !          1532:   if (!(hFontThread1 = CreateThread((LPSECURITY_ATTRIBUTES) NULL, 0,
        !          1533:                                      (LPTHREAD_START_ROUTINE) FontThreadProc1,
        !          1534:                                      &dwFontThreadParm1, CREATE_SUSPENDED, &dwFontThreadID1)))
        !          1535: 
        !          1536:   {
        !          1537:     MessageBox(GetForegroundWindow(), TEXT("Error creating thread 1"), NULL,
        !          1538:                MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL) ;
        !          1539: 
        !          1540:     nOpenFontDialogCount = 0 ;
        !          1541: 
        !          1542:     EnableFontButtons(hwndMainFont, TRUE) ;
        !          1543: 
        !          1544:     return ;
        !          1545:   }
        !          1546: 
        !          1547: 
        !          1548:   if (!(hFontThread2 = CreateThread((LPSECURITY_ATTRIBUTES) NULL, 0,
        !          1549:                                      (LPTHREAD_START_ROUTINE) FontThreadProc2,
        !          1550:                                      &dwFontThreadParm2, CREATE_SUSPENDED, &dwFontThreadID2)))
        !          1551:   {
        !          1552:     MessageBox(GetForegroundWindow(), TEXT("Error creating thread 2"), NULL,
        !          1553:                MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL) ;
        !          1554: 
        !          1555:     nOpenFontDialogCount = 0 ;
        !          1556: 
        !          1557:     EnableFontButtons(hwndMainFont, TRUE) ;
        !          1558: 
        !          1559:     return ;
        !          1560:   }
        !          1561: 
        !          1562:   ResumeThread(hFontThread1) ;
        !          1563:   ResumeThread(hFontThread2) ;
        !          1564: 
        !          1565:   return ;
        !          1566: }
        !          1567: 
        !          1568: 
        !          1569: 
        !          1570: 
        !          1571: 
        !          1572: 
        !          1573: /************************************************************************
        !          1574: 
        !          1575:   Function: EnableFontButtons(HWND, BOOL)
        !          1576: 
        !          1577:   Purpose:
        !          1578: 
        !          1579:     Enables or disables CDTEST's font dialogs buttons based on the
        !          1580:     status of the second parameter.
        !          1581: 
        !          1582: 
        !          1583:   Returns: Nothing.
        !          1584: 
        !          1585:   Comments:
        !          1586: 
        !          1587:     This is necessary when multithreading in the case of this application.
        !          1588: 
        !          1589: ************************************************************************/
        !          1590: 
        !          1591: void EnableFontButtons(HWND hwnd, BOOL bEnable)
        !          1592: {
        !          1593:   EnableWindow(GetDlgItem(hwnd, IDOK), bEnable) ;
        !          1594:   EnableWindow(GetDlgItem(hwnd, IDCANCEL), bEnable) ;
        !          1595:   EnableWindow(GetDlgItem(hwnd, ID_RESETFONT), bEnable) ;
        !          1596:   EnableWindow(GetDlgItem(hwnd, ID_MULTITHREADFONT), bEnable) ;
        !          1597:   EnableWindow(GetDlgItem(hwnd, ID_EDITLOGFONT), bEnable) ;
        !          1598: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.