Annotation of mstools/samples/fontview/dialogs.c, revision 1.1.1.1

1.1       root        1: #include "firstaid.h"
                      2: #define NOMINMAX
                      3: #include <windows.h>
                      4: #include "FontView.h"
                      5: 
                      6: #include <stdlib.h>
                      7: 
                      8: #if defined (WIN16)
                      9: typedef LONG (APIENTRY *WNDPROC)(HWND, UINT, WORD, LONG);
                     10: #endif
                     11: 
                     12: BOOL CenterWindow (HWND, HWND);
                     13: 
                     14: 
                     15: typedef struct FONTENUM {
                     16:        short       ft;
                     17:        TEXTMETRIC  tm;
                     18:        LOGFONT     lf;
                     19: } FONTSTRUCT;
                     20: typedef FONTSTRUCT      *PFONTSTRUCT;
                     21: typedef FONTSTRUCT NEAR *NPFONTSTRUCT;
                     22: typedef FONTSTRUCT FAR  *LPFONTSTRUCT;
                     23: 
                     24: typedef struct FONTLIST {
                     25:        int     count;
                     26:        HANDLE  hList;
                     27: } FONTLIST;
                     28: typedef FONTLIST        *PFONTLIST;
                     29: typedef FONTLIST NEAR   *NPFONTLIST;
                     30: typedef FONTLIST FAR    *LPFONTLIST;
                     31: 
                     32: 
                     33: void SetDlgItemValue (HWND hDlg, int nIDDlgItem, int wValue, BOOL bSigned, int nBase)
                     34: {
                     35:        char szValue[20];
                     36: 
                     37:        switch (nBase) {
                     38:                case 8:
                     39:                        wsprintf (szValue, "0o%o", wValue);
                     40:                        SetDlgItemText (hDlg, nIDDlgItem, szValue);
                     41:                        break;
                     42:                case 16:
                     43:                        wsprintf (szValue, "0x%x", wValue);
                     44:                        SetDlgItemText (hDlg, nIDDlgItem, szValue);
                     45:                        break;
                     46:                default:
                     47:                        SetDlgItemInt (hDlg, nIDDlgItem, wValue, bSigned);
                     48:                        break;
                     49:        }
                     50: }
                     51: 
                     52: int FAR PASCAL DlgEnumFontSizes (lpLogFont, lpTextMetric, nFontType, lpData)
                     53:        LPLOGFONT lpLogFont;
                     54:        LPTEXTMETRIC lpTextMetric;
                     55:        short nFontType;
                     56:        LPHANDLE lpData;
                     57: {
                     58:        LPSTR lpFaces ;
                     59:        HANDLE hFonts;
                     60:        LPFONTSTRUCT pFS;
                     61:        LPFONTLIST pFL;
                     62: 
                     63:        lpFaces; // unreferenced
                     64: 
                     65:        /*
                     66:                This function will lock down the incoming handle, properly alloc, and realloc the
                     67:                handle within it to hold the data of the fonts enumerated, then unlock the handle.
                     68:        */
                     69:        hFonts = *lpData;
                     70:        pFL = (LPFONTLIST)GlobalLock (hFonts);
                     71:        if (!pFL) {
                     72:                return FALSE;
                     73:        } else if (pFL->count == 0) {
                     74:                pFL->hList = GlobalAlloc (GHND, sizeof(FONTSTRUCT));
                     75:        } else {
                     76:                pFL->hList = GlobalReAlloc (pFL->hList, sizeof(FONTSTRUCT)*(1+pFL->count), GMEM_MOVEABLE);
                     77:        }
                     78: 
                     79:        if (pFL->hList) {
                     80:                pFS = (LPFONTSTRUCT)GlobalLock (pFL->hList);
                     81:                if (pFS) {
                     82:                        pFS[pFL->count].ft = nFontType;
                     83:                        pFS[pFL->count].tm = *lpTextMetric;
                     84:                        pFS[pFL->count].lf = *lpLogFont;
                     85:                        GlobalUnlock (pFL->hList);
                     86:                        pFL->count++;
                     87:                }
                     88:                GlobalUnlock (hFonts);
                     89: 
                     90:        } else {
                     91:                GlobalUnlock (hFonts);
                     92:                return FALSE;
                     93:        }
                     94: 
                     95:        return TRUE;
                     96: }
                     97: 
                     98: int FAR PASCAL DlgEnumFontNames (lpLogFont, lpTextMetric, nFontType, lpData)
                     99:        LPLOGFONT lpLogFont;
                    100:        LPTEXTMETRIC lpTextMetric;
                    101:        short nFontType;
                    102:        LPHANDLE lpData;
                    103: {
                    104:        HDC  hdc;
                    105:        HWND hwnd;
                    106:        HANDLE hInst;
                    107:        FARPROC lpFontEnumProc;
                    108:        extern HANDLE hwndMain;
                    109: 
                    110: /*
                    111:    This function is just a pass through. For each face encountered, it will in turn enumerate all
                    112:    sizes available. the lpData, which is a FAR * to a FONTSTRUCT structure will simply be passed
                    113:    on to the second enumeration procedure which will fill it in.
                    114:  */
                    115:        lpTextMetric;      // unreferenced
                    116:        nFontType;         // unreferenced
                    117: 
                    118:        hwnd = GetFocus();
                    119: #if defined (NT)
                    120:        hInst = (HANDLE)GetWindowLong (hwndMain, GWL_HINSTANCE);
                    121: #elif defined (WIN16)
                    122:        hInst = (HANDLE)GetWindowWord (hwnd, GWW_HINSTANCE);
                    123: #endif
                    124: 
                    125:        lpFontEnumProc = MakeProcInstance(DlgEnumFontSizes, hInst);
                    126:        if (lpFontEnumProc) {
                    127:                hdc  = GetDC(hwnd);
                    128:                EnumFonts (hdc, lpLogFont->lfFaceName, lpFontEnumProc, (LPSTR)lpData);
                    129:                ReleaseDC(hwnd, hdc);
                    130:                FreeProcInstance (lpFontEnumProc);
                    131:        } else {
                    132:                MessageBox (GetFocus(), "Couldn't create a proc instance", "FontView", MB_OK);
                    133:                return FALSE;
                    134:        }
                    135:        return TRUE;
                    136: }
                    137: 
                    138: 
                    139: 
                    140: BOOL APIENTRY SimpleDlgProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
                    141: {
                    142:        INT wmId;
                    143: 
                    144:        switch (msg) {
                    145:                case WM_INITDIALOG:
                    146:                        CenterWindow (hwnd, GetWindow (hwnd, GW_OWNER));
                    147:                        return (TRUE);
                    148: 
                    149:                case WM_COMMAND:
                    150: #if defined (NT)
                    151:                        wmId = LOWORD(wParam);
                    152: #elif defined (WIN16)
                    153:                        wmId = wParam;
                    154: #endif
                    155:                        switch (wmId) {
                    156: 
                    157:                                case IDOK:
                    158:                                        EndDialog(hwnd, TRUE);
                    159:                                        return (TRUE);
                    160: 
                    161:                                case IDCANCEL:
                    162:                                        EndDialog(hwnd, TRUE);
                    163:                                        return (TRUE);
                    164:                        }
                    165:                        break;
                    166:        }
                    167:        return (FALSE);
                    168: 
                    169:        /* Just For Reference */
                    170:        lParam;
                    171: }
                    172: 
                    173: BOOL APIENTRY CreateDlgProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
                    174: {
                    175:        INT wmId, i;
                    176:        BOOL bDone;
                    177: static LOGFONT lfDlg;
                    178: static LPLOGFONT lplf;
                    179: 
                    180:        switch (msg) {
                    181:                case WM_INITDIALOG:
                    182:                        CenterWindow (hwnd, GetWindow (hwnd, GW_OWNER));
                    183:                        lplf = (LOGFONT *)lParam;
                    184:                        lfDlg = *lplf;
                    185:                        SetDlgItemInt (hwnd, CFD_HEIGHT, (int)lfDlg.lfHeight, TRUE);
                    186:                        SetDlgItemInt (hwnd, CFD_WIDTH, (int)lfDlg.lfWidth, TRUE);
                    187:                        SetDlgItemInt (hwnd, CFD_ESCAPEMENT, (int)lfDlg.lfEscapement, TRUE);
                    188:                        SetDlgItemInt (hwnd, CFD_ORIENTATION, (int)lfDlg.lfOrientation, TRUE);
                    189:                        SetDlgItemInt (hwnd, CFD_WEIGHT, (int)lfDlg.lfWeight, FALSE);
                    190:                        SetDlgItemInt (hwnd, CFD_ITALIC, (int)lfDlg.lfItalic, FALSE);
                    191:                        SetDlgItemInt (hwnd, CFD_UNDERLINE, (int)lfDlg.lfUnderline, FALSE);
                    192:                        SetDlgItemInt (hwnd, CFD_STRIKEOUT, (int)lfDlg.lfStrikeOut, FALSE);
                    193:                        SetDlgItemInt (hwnd, CFD_CHARSET, (int)lfDlg.lfCharSet, FALSE);
                    194:                        SetDlgItemInt (hwnd, CFD_OUTPUTPRECISION, (int)lfDlg.lfOutPrecision, FALSE);
                    195:                        SetDlgItemInt (hwnd, CFD_CLIPPRECISION, (int)lfDlg.lfClipPrecision, FALSE);
                    196:                        SetDlgItemInt (hwnd, CFD_QUALITY, (int)lfDlg.lfQuality, FALSE);
                    197:                        SetDlgItemInt (hwnd, CFD_PITCHANDFAMILY, (int)lfDlg.lfPitchAndFamily, FALSE);
                    198:                        SetDlgItemText(hwnd, CFD_FACENAME, lfDlg.lfFaceName);
                    199: 
                    200:                        return (TRUE);
                    201: 
                    202:                case WM_COMMAND:
                    203: #if defined (NT)
                    204:                        wmId = LOWORD(wParam);
                    205: #elif defined (WIN16)
                    206:                        wmId = wParam;
                    207: #endif
                    208:                        switch (wmId) {
                    209:                                case CFD_DEFAULT:
                    210:                                        for (i=CFD_BASE; i<=CFD_PITCHANDFAMILY; i++) {
                    211:                                                SetDlgItemInt (hwnd, i, 0, FALSE);
                    212:                                        }
                    213:                                        SetDlgItemText (hwnd, CFD_FACENAME, "");
                    214:                                        break;
                    215: 
                    216:                                case IDOK:
                    217:                                        lfDlg.lfHeight = GetDlgItemInt (hwnd, CFD_HEIGHT, &bDone, TRUE);
                    218:                                        lfDlg.lfWidth = GetDlgItemInt (hwnd, CFD_WIDTH, &bDone, TRUE);
                    219:                                        lfDlg.lfEscapement = GetDlgItemInt (hwnd, CFD_ESCAPEMENT, &bDone, TRUE);
                    220:                                        lfDlg.lfOrientation = GetDlgItemInt (hwnd, CFD_ORIENTATION, &bDone, TRUE);
                    221:                                        lfDlg.lfWeight = GetDlgItemInt (hwnd, CFD_WEIGHT, &bDone, FALSE);
                    222:                                        lfDlg.lfItalic = (BYTE)GetDlgItemInt (hwnd, CFD_ITALIC, &bDone, FALSE);
                    223:                                        lfDlg.lfUnderline = (BYTE)GetDlgItemInt (hwnd, CFD_UNDERLINE, &bDone, FALSE);
                    224:                                        lfDlg.lfStrikeOut = (BYTE)GetDlgItemInt (hwnd, CFD_STRIKEOUT, &bDone, FALSE);
                    225:                                        lfDlg.lfCharSet = (BYTE)GetDlgItemInt (hwnd, CFD_CHARSET, &bDone, FALSE);
                    226:                                        lfDlg.lfOutPrecision = (BYTE)GetDlgItemInt (hwnd, CFD_OUTPUTPRECISION, &bDone, FALSE);
                    227:                                        lfDlg.lfClipPrecision = (BYTE)GetDlgItemInt (hwnd, CFD_CLIPPRECISION, &bDone, FALSE);
                    228:                                        lfDlg.lfQuality = (BYTE)GetDlgItemInt (hwnd, CFD_QUALITY, &bDone, FALSE);
                    229:                                        lfDlg.lfPitchAndFamily = (BYTE)GetDlgItemInt (hwnd, CFD_PITCHANDFAMILY, &bDone, FALSE);
                    230:                                        GetDlgItemText(hwnd, CFD_FACENAME, lfDlg.lfFaceName,20);
                    231: 
                    232:                                        *lplf = lfDlg;
                    233:                                        EndDialog(hwnd, TRUE);
                    234:                                        return (TRUE);
                    235: 
                    236:                                case IDCANCEL:
                    237:                                        EndDialog(hwnd, TRUE);
                    238:                                        return (TRUE);
                    239: 
                    240:                        }
                    241:                        break;
                    242:        }
                    243:        return (FALSE);
                    244: 
                    245:        /* Just For Reference */
                    246:        lParam;
                    247: }
                    248: 
                    249: /*
                    250: typedef struct tagTEXTMETRIC {
                    251:    short int tmHeight;
                    252:    short int tmAscent;
                    253:    short int tmDescent;
                    254:    short int tmInternalLeading;
                    255:    short int tmExternalLeading;
                    256:    short int tmAveCharWidth;
                    257:    short int tmMaxCharWidth;
                    258:    short int tmWeight;
                    259:    BYTE      tmItalic;
                    260:    BYTE      tmUnderlined;
                    261:    BYTE      tmStruckOut;
                    262:    BYTE      tmFirstChar;
                    263:    BYTE      tmLastChar;
                    264:    BYTE      tmDefaultChar;
                    265:    BYTE      tmBreakChar;
                    266:    BYTE      tmPitchAndFamily;
                    267:    BYTE      tmCharSet;
                    268: 
                    269:    short int tmOverhang;
                    270:    short int tmDigitizedAspectX;
                    271:    short int tmDigitizedAspectY;
                    272: 
                    273: } TEXTMETRIC;
                    274: 
                    275: tmHeight
                    276: tmAscent
                    277: tmDescent
                    278: tmInternalLeading
                    279: tmExternalLeading
                    280: tmAveCharWidth
                    281: tmMaxCharWidth
                    282: tmWeight
                    283: tmItalic
                    284: tmUnderlined
                    285: tmStruckOut
                    286: tmFirstChar
                    287: tmLastChar
                    288: tmDefaultChar
                    289: tmBreakChar
                    290: tmPitchAndFamily
                    291: tmCharSet
                    292: 
                    293: typedef struct tagLOGFONT {
                    294:    short int lfHeight;
                    295:    short int lfWidth;
                    296:    short int lfEscapement;
                    297:    short int lfOrientation;
                    298:    short int lfWeight;
                    299:    BYTE      lfItalic;
                    300:    BYTE      lfUnderline;
                    301:    BYTE      lfStrikeOut;
                    302:    BYTE      lfCharSet;
                    303:    BYTE      lfOutPrecision;
                    304:    BYTE      lfClipPrecision;
                    305:    BYTE      lfQuality;
                    306:    BYTE      lfPitchAndFamily;
                    307:    BYTE      lfFaceName[LF_FACESIZE];
                    308: 
                    309: } LOGFONT;
                    310: 
                    311: lfHeight
                    312: lfWidth
                    313: lfEscapement
                    314: lfOrientation
                    315: lfWeight
                    316: lfItalic
                    317: lfUnderline
                    318: lfStrikeOut
                    319: lfCharSet
                    320: lfOutPrecision
                    321: lfClipPrecision
                    322: lfQuality
                    323: lfPitchAndFamily
                    324: lfFaceName
                    325: 
                    326: */
                    327: 
                    328: BOOL APIENTRY MetricsDlgProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
                    329: {
                    330: static LOGFONT lfDlg;
                    331: static LPLOGFONT lplf;
                    332: static TEXTMETRIC tm;
                    333: static char szFacename[LF_FACESIZE];
                    334:        INT wmId;
                    335:        BOOL bDone;
                    336:        TEXTMETRIC tmTmp;
                    337:        HFONT hfont, hfontPrev;
                    338:        HDC   hdc;
                    339:        char szBuffer[LF_FACESIZE+15];
                    340: 
                    341: 
                    342:        switch (msg) {
                    343:                case WM_INITDIALOG:
                    344:                        CenterWindow (hwnd, GetWindow (hwnd, GW_OWNER));
                    345:                        lplf = (LOGFONT *)lParam;
                    346:                        lfDlg = *lplf;
                    347: 
                    348:                        hfont = CreateFontIndirect (&lfDlg);
                    349:                        hdc = GetDC (hwnd);
                    350:                        hfontPrev = SelectObject (hdc, hfont);
                    351:                        GetTextMetrics (hdc, &tm);
                    352:                        GetTextFace    (hdc, sizeof(szFacename), szFacename);
                    353:                        SelectObject (hdc, hfontPrev);
                    354:                        DeleteObject (hfont);
                    355:                        ReleaseDC (hwnd, hdc);
                    356: 
                    357:                        wsprintf (szBuffer, "TextMetrics: %s", (LPSTR)szFacename);
                    358:                        SetWindowText (hwnd, szBuffer);
                    359: 
                    360:                        SetDlgItemInt (hwnd, TMD_HEIGHT, (int)tm.tmHeight, TRUE);
                    361:                        SetDlgItemInt (hwnd, TMD_ASCENT, (int)tm.tmAscent, TRUE);
                    362:                        SetDlgItemInt (hwnd, TMD_DESCENT, (int)tm.tmDescent, TRUE);
                    363:                        SetDlgItemInt (hwnd, TMD_INTERNAL, (int)tm.tmInternalLeading, TRUE);
                    364:                        SetDlgItemInt (hwnd, TMD_EXTERNAL, (int)tm.tmExternalLeading, TRUE);
                    365:                        SetDlgItemInt (hwnd, TMD_AVEWIDTH, (int)tm.tmAveCharWidth, TRUE);
                    366:                        SetDlgItemInt (hwnd, TMD_MAXWIDTH, (int)tm.tmMaxCharWidth, TRUE);
                    367:                        SetDlgItemInt (hwnd, TMD_WEIGHT, (int)tm.tmWeight, TRUE);
                    368:                        SetDlgItemInt (hwnd, TMD_ITALIC, (int)tm.tmItalic, FALSE);
                    369:                        SetDlgItemInt (hwnd, TMD_UNDERLINE, (int)tm.tmUnderlined, FALSE);
                    370:                        SetDlgItemInt (hwnd, TMD_STRUCKOUT, (int)tm.tmStruckOut, FALSE);
                    371:                        SetDlgItemInt (hwnd, TMD_FIRSTCHAR, (int)tm.tmFirstChar, FALSE);
                    372:                        SetDlgItemInt (hwnd, TMD_LASTCHAR, (int)tm.tmLastChar, FALSE);
                    373:                        SetDlgItemInt (hwnd, TMD_DEFAULTCHAR, (int)tm.tmDefaultChar, FALSE);
                    374:                        SetDlgItemInt (hwnd, TMD_BREAKCHAR, (int)tm.tmBreakChar, FALSE);
                    375:                        SetDlgItemInt (hwnd, TMD_PITCHANDFAMILY, (int)tm.tmPitchAndFamily, FALSE);
                    376:                        SetDlgItemInt (hwnd, TMD_CHARSET, (int)tm.tmCharSet, FALSE);
                    377:                        SetDlgItemInt (hwnd, TMD_OVERHANG, (int)tm.tmOverhang, TRUE);
                    378:                        SetDlgItemInt (hwnd, TMD_DIGITIZEDASPECTX, (int)tm.tmDigitizedAspectX, TRUE);
                    379:                        SetDlgItemInt (hwnd, TMD_DIGITIZEDASPECTY, (int)tm.tmDigitizedAspectY, TRUE);
                    380: 
                    381:                        return (TRUE);
                    382: 
                    383:                case WM_COMMAND:
                    384: #if defined (NT)
                    385:                        wmId = LOWORD(wParam);
                    386: #elif defined (WIN16)
                    387:                        wmId = wParam;
                    388: #endif
                    389:                        switch (wmId) {
                    390:                                case IDOK:
                    391: 
                    392:                                        lfDlg.lfHeight         = tm.tmHeight;
                    393:                                        lfDlg.lfWidth          = tm.tmAveCharWidth;
                    394:                                        //lfDlg.lfEscapement
                    395:                                        //lfDlg.lfOrientation
                    396:                                        lfDlg.lfWeight         = tm.tmWeight;
                    397:                                        lfDlg.lfItalic         = tm.tmItalic;
                    398:                                        lfDlg.lfUnderline      = tm.tmUnderlined;
                    399:                                        lfDlg.lfStrikeOut      = tm.tmStruckOut;
                    400:                                        lfDlg.lfCharSet        = tm.tmCharSet;
                    401:                                        //lfDlg.lfOutPrecision
                    402:                                        //lfDlg.lfClipPrecision
                    403:                                        //lfDlg.lfQuality
                    404:                                        lfDlg.lfPitchAndFamily = tm.tmPitchAndFamily;
                    405:                                        lstrcpy(lfDlg.lfFaceName, szFacename);
                    406: 
                    407:                                        hfont = CreateFontIndirect (&lfDlg);
                    408:                                        hdc = GetDC (hwnd);
                    409:                                        hfontPrev = SelectObject (hdc, hfont);
                    410:                                        GetTextMetrics (hdc, &tmTmp);
                    411:                                        GetTextFace    (hdc, sizeof(szBuffer), szBuffer);
                    412:                                        SelectObject (hdc, hfontPrev);
                    413:                                        DeleteObject (hfont);
                    414:                                        ReleaseDC (hwnd, hdc);
                    415: 
                    416:                                        bDone = TRUE;
                    417:                                        bDone = bDone && (tm.tmHeight==tmTmp.tmHeight);
                    418:                                        bDone = bDone && (tm.tmAscent==tmTmp.tmAscent);
                    419:                                        bDone = bDone && (tm.tmDescent==tmTmp.tmDescent);
                    420:                                        bDone = bDone && (tm.tmInternalLeading==tmTmp.tmInternalLeading);
                    421:                                        bDone = bDone && (tm.tmExternalLeading==tmTmp.tmExternalLeading);
                    422:                                        bDone = bDone && (tm.tmAveCharWidth==tmTmp.tmAveCharWidth);
                    423:                                        bDone = bDone && (tm.tmMaxCharWidth==tmTmp.tmMaxCharWidth);
                    424:                                        bDone = bDone && (tm.tmWeight==tmTmp.tmWeight);
                    425:                                        bDone = bDone && (tm.tmItalic==tmTmp.tmItalic);
                    426:                                        bDone = bDone && (tm.tmUnderlined==tmTmp.tmUnderlined);
                    427:                                        bDone = bDone && (tm.tmStruckOut==tmTmp.tmStruckOut);
                    428:                                        bDone = bDone && (tm.tmFirstChar==tmTmp.tmFirstChar);
                    429:                                        bDone = bDone && (tm.tmLastChar==tmTmp.tmLastChar);
                    430:                                        bDone = bDone && (tm.tmDefaultChar==tmTmp.tmDefaultChar);
                    431:                                        bDone = bDone && (tm.tmBreakChar==tmTmp.tmBreakChar);
                    432:                                        bDone = bDone && (tm.tmPitchAndFamily==tmTmp.tmPitchAndFamily);
                    433:                                        bDone = bDone && (tm.tmCharSet==tmTmp.tmCharSet);
                    434:                                        if (bDone) {
                    435:                                                *lplf = lfDlg;
                    436:                                                EndDialog(hwnd, TRUE);
                    437:                                                return (TRUE);
                    438:                                        } else {
                    439:                                                lfDlg = *lplf;
                    440:                                                MessageBox (GetFocus(),
                    441:                                                        "Unable to re-create font from TextMetrics",
                    442:                                                        "FontView", MB_OK);
                    443:                                        }
                    444:                                        break;
                    445: 
                    446:                                case IDCANCEL:
                    447:                                        EndDialog(hwnd, TRUE);
                    448:                                        return (TRUE);
                    449: 
                    450:                        }
                    451:                        break;
                    452:        }
                    453:        return (FALSE);
                    454: 
                    455:        /* Just For Reference */
                    456:        lParam;
                    457: }
                    458: 
                    459: 
                    460: BOOL FillEnumFields (HWND hwnd, int iType, LPTEXTMETRIC ptm, LPLOGFONT plf, int nBase)
                    461: {
                    462:                        SetDlgItemValue (hwnd, TMD_HEIGHT, (int)ptm->tmHeight, TRUE, nBase);
                    463:                        SetDlgItemValue (hwnd, TMD_ASCENT, (int)ptm->tmAscent, TRUE, nBase);
                    464:                        SetDlgItemValue (hwnd, TMD_DESCENT, (int)ptm->tmDescent, TRUE, nBase);
                    465:                        SetDlgItemValue (hwnd, TMD_INTERNAL, (int)ptm->tmInternalLeading, TRUE, nBase);
                    466:                        SetDlgItemValue (hwnd, TMD_EXTERNAL, (int)ptm->tmExternalLeading, TRUE, nBase);
                    467:                        SetDlgItemValue (hwnd, TMD_AVEWIDTH, (int)ptm->tmAveCharWidth, TRUE, nBase);
                    468:                        SetDlgItemValue (hwnd, TMD_MAXWIDTH, (int)ptm->tmMaxCharWidth, TRUE, nBase);
                    469:                        SetDlgItemValue (hwnd, TMD_WEIGHT, (int)ptm->tmWeight, TRUE, nBase);
                    470:                        SetDlgItemValue (hwnd, TMD_ITALIC, (int)ptm->tmItalic, FALSE, nBase);
                    471:                        SetDlgItemValue (hwnd, TMD_UNDERLINE, (int)ptm->tmUnderlined, FALSE, nBase);
                    472:                        SetDlgItemValue (hwnd, TMD_STRUCKOUT, (int)ptm->tmStruckOut, FALSE, nBase);
                    473:                        SetDlgItemValue (hwnd, TMD_FIRSTCHAR, (int)ptm->tmFirstChar, FALSE, nBase);
                    474:                        SetDlgItemValue (hwnd, TMD_LASTCHAR, (int)ptm->tmLastChar, FALSE, nBase);
                    475:                        SetDlgItemValue (hwnd, TMD_DEFAULTCHAR, (int)ptm->tmDefaultChar, FALSE, nBase);
                    476:                        SetDlgItemValue (hwnd, TMD_BREAKCHAR, (int)ptm->tmBreakChar, FALSE, nBase);
                    477:                        SetDlgItemValue (hwnd, TMD_PITCHANDFAMILY, (int)ptm->tmPitchAndFamily, FALSE, nBase);
                    478:                        SetDlgItemValue (hwnd, TMD_CHARSET, (int)ptm->tmCharSet, FALSE, nBase);
                    479:                        SetDlgItemValue (hwnd, TMD_OVERHANG, (int)ptm->tmOverhang, TRUE, nBase);
                    480:                        SetDlgItemValue (hwnd, TMD_DIGITIZEDASPECTX, (int)ptm->tmDigitizedAspectX, TRUE, nBase);
                    481:                        SetDlgItemValue (hwnd, TMD_DIGITIZEDASPECTY, (int)ptm->tmDigitizedAspectY, TRUE, nBase);
                    482: 
                    483:                        SetDlgItemValue (hwnd, CFD_HEIGHT, (int)plf->lfHeight, TRUE, nBase);
                    484:                        SetDlgItemValue (hwnd, CFD_WIDTH, (int)plf->lfWidth, TRUE, nBase);
                    485:                        SetDlgItemValue (hwnd, CFD_ESCAPEMENT, (int)plf->lfEscapement, TRUE, nBase);
                    486:                        SetDlgItemValue (hwnd, CFD_ORIENTATION, (int)plf->lfOrientation, TRUE, nBase);
                    487:                        SetDlgItemValue (hwnd, CFD_WEIGHT, (int)plf->lfWeight, FALSE, nBase);
                    488:                        SetDlgItemValue (hwnd, CFD_ITALIC, (int)plf->lfItalic, FALSE, nBase);
                    489:                        SetDlgItemValue (hwnd, CFD_UNDERLINE, (int)plf->lfUnderline, FALSE, nBase);
                    490:                        SetDlgItemValue (hwnd, CFD_STRIKEOUT, (int)plf->lfStrikeOut, FALSE, nBase);
                    491:                        SetDlgItemValue (hwnd, CFD_CHARSET, (int)plf->lfCharSet, FALSE, nBase);
                    492:                        SetDlgItemValue (hwnd, CFD_OUTPUTPRECISION, (int)plf->lfOutPrecision, FALSE, nBase);
                    493:                        SetDlgItemValue (hwnd, CFD_CLIPPRECISION, (int)plf->lfClipPrecision, FALSE, nBase);
                    494:                        SetDlgItemValue (hwnd, CFD_QUALITY, (int)plf->lfQuality, FALSE, nBase);
                    495:                        SetDlgItemValue (hwnd, CFD_PITCHANDFAMILY, (int)plf->lfPitchAndFamily, FALSE, nBase);
                    496:                        SetDlgItemText(hwnd, CFD_FACENAME, plf->lfFaceName);
                    497: 
                    498:                        SetDlgItemValue (hwnd, ED_TYPE, (int)iType, FALSE, nBase);
                    499: 
                    500:                        return TRUE;
                    501: }
                    502: 
                    503: 
                    504: BOOL DrawSample (HWND hwnd, LPLOGFONT plf)
                    505: {
                    506:        HFONT   hfont, hfontPrev;
                    507:        HDC     hdc;
                    508:        RECT    r;
                    509: 
                    510:        hfont = CreateFontIndirect (plf);
                    511:        hdc = GetDC (hwnd);
                    512:        hfontPrev = SelectObject (hdc, hfont);
                    513:        GetWindowRect (hwnd, &r);
                    514:        ScreenToClient (hwnd, (LPPOINT)&r.left);
                    515:        ScreenToClient (hwnd, (LPPOINT)&r.right);
                    516: 
                    517:        Rectangle (hdc, r.left, r.top, r.right, r.bottom);
                    518: 
                    519:        InflateRect (&r, -1, -1);
                    520:        SetTextAlign (hdc, TA_BOTTOM | TA_CENTER);
                    521:        ExtTextOut (hdc, r.left + ((r.right-r.left)/2), r.bottom, ETO_CLIPPED, &r,"AaBbCcDdEe 012345", 17, NULL);
                    522: 
                    523:        SelectObject (hdc, hfontPrev);
                    524:        DeleteObject (hfont);
                    525:        ReleaseDC (hwnd, hdc);
                    526:        return TRUE;
                    527: }
                    528: 
                    529: 
                    530: BOOL APIENTRY EnumDlgProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
                    531: {
                    532:        static HANDLE /*TO FONTLIST*/ hFonts;
                    533:        static int iLoc=0;
                    534:        static int count=0;
                    535:        static BOOL bHex = FALSE;
                    536:        static LOGFONT *lplf;
                    537:        static LOGFONT lfDlg;
                    538:        INT wmId, i, j;
                    539:        HANDLE hInst;
                    540:        HWND   hwndItem;
                    541:        HDC hdc;
                    542:        FARPROC lpEnumFonts;
                    543:        LPFONTLIST    pFL;
                    544:        LPFONTSTRUCT  pFS;
                    545:        char szTmp[80];
                    546: 
                    547:        switch (msg) {
                    548:                case WM_INITDIALOG:
                    549:                        lplf = (LOGFONT *)lParam;
                    550:                        lfDlg = *lplf;
                    551:                        iLoc = 0;
                    552:                        count = 0;
                    553:                        bHex = FALSE;
                    554:                        /* First, lets enumerate ALL fonts, and store them in our list */
                    555:                        hFonts = GlobalAlloc (GHND, sizeof(FONTLIST));
                    556:                        if (hFonts) {
                    557: 
                    558: #if defined (NT)
                    559:        hInst = (HANDLE)GetWindowLong (hwnd, GWL_HINSTANCE);
                    560: #elif defined (WIN16)
                    561:        hInst = (HANDLE)GetWindowWord (hwnd, GWW_HINSTANCE);
                    562: #endif
                    563: 
                    564:                                lpEnumFonts = MakeProcInstance(DlgEnumFontNames, hInst);
                    565:                                if (lpEnumFonts) {
                    566:                                        hdc  = GetDC(hwnd);
                    567:                                        // The enumeration function will lock down the handle
                    568:                                        EnumFonts (hdc, NULL, lpEnumFonts, (LPSTR)&hFonts);
                    569:                                        // The handle will come back to us properly unlocked
                    570:                                        ReleaseDC(hwnd, hdc);
                    571:                                        FreeProcInstance (lpEnumFonts);
                    572: 
                    573:                                 }
                    574:                        }
                    575:                        pFL = (LPFONTLIST)GlobalLock (hFonts);
                    576:                        if (pFL) {
                    577:                                pFS = (LPFONTSTRUCT)GlobalLock (pFL->hList);
                    578:                                if (pFS) {
                    579:                                        iLoc = 0;
                    580:                                        j = 100;
                    581:                                        for (i=0; i<pFL->count; i++) {
                    582:                                                if (lstrcmp(lfDlg.lfFaceName, pFS[i].lf.lfFaceName) == 0) {
                    583:                                                        if (abs(lfDlg.lfHeight-pFS[i].lf.lfHeight) < j) {
                    584:                                                                j = abs(lfDlg.lfHeight-pFS[i].lf.lfHeight);
                    585:                                                                iLoc = i;
                    586:                                                        }
                    587:                                                }
                    588:                                        }
                    589:                                        FillEnumFields (hwnd, pFS[iLoc].ft, &pFS[iLoc].tm, &pFS[iLoc].lf, (bHex?16:10));
                    590:                                        hwndItem = GetDlgItem (hwnd, ED_SAMPLE);
                    591:                                        DrawSample (hwndItem, &pFS[iLoc].lf);
                    592:                                        GlobalUnlock (pFL->hList);
                    593: 
                    594:                                }
                    595:                                count = pFL->count;
                    596:                                GlobalUnlock (hFonts);
                    597: 
                    598:                        }
                    599:                        /* now fill in the dialog values */
                    600:                        wsprintf (szTmp, "EnumFonts %d of %d", iLoc+1, count);
                    601:                        SetWindowText (hwnd, szTmp);
                    602:                        CenterWindow (hwnd, GetWindow (hwnd, GW_OWNER));
                    603: 
                    604:                        return TRUE;
                    605: 
                    606:                case WM_COMMAND:
                    607: #if defined (NT)
                    608:                        wmId = LOWORD(wParam);
                    609: #elif defined (WIN16)
                    610:                        wmId = wParam;
                    611: #endif
                    612:                        switch (wmId) {
                    613: 
                    614:                                case ED_HEX:
                    615:                                        bHex = !bHex;
                    616:                                        CheckDlgButton (hwnd, wmId, bHex);
                    617:                                        pFL = (LPFONTLIST)GlobalLock (hFonts);
                    618:                                        if (pFL) {
                    619:                                                pFS = (LPFONTSTRUCT)GlobalLock (pFL->hList);
                    620:                                                if (pFS) {
                    621:                                                        FillEnumFields (hwnd, pFS[iLoc].ft, &pFS[iLoc].tm, &pFS[iLoc].lf, (bHex?16:10));
                    622:                                                        if (GlobalUnlock (pFL->hList)) {
                    623:                                                                MessageBox (GetFocus(), "In HEX", "Unlock pFL->hList", MB_OK);
                    624:                                                        }
                    625:                                                }
                    626:                                                if (GlobalUnlock (hFonts)) {
                    627:                                                        MessageBox (GetFocus(), "In HEX", "Unlock hFonts", MB_OK);
                    628:                                                }
                    629: 
                    630:                                        }
                    631:                                        break;
                    632: 
                    633:                                case ED_PREV:
                    634:                                        pFL = (LPFONTLIST)GlobalLock (hFonts);
                    635:                                        if (pFL) {
                    636:                                                if (iLoc > 0) {
                    637:                                                        iLoc--;
                    638:                                                        pFS = (LPFONTSTRUCT)GlobalLock (pFL->hList);
                    639:                                                        if (pFS) {
                    640:                                                                FillEnumFields (hwnd, pFS[iLoc].ft, &pFS[iLoc].tm, &pFS[iLoc].lf, (bHex?16:10));
                    641:                                                                hwndItem = GetDlgItem (hwnd, ED_SAMPLE);
                    642:                                                                DrawSample (hwndItem, &pFS[iLoc].lf);
                    643:                                                                GlobalUnlock (pFL->hList);
                    644:                                                        }
                    645:                                                }
                    646:                                                GlobalUnlock (hFonts);
                    647:                                        }
                    648:                                        wsprintf (szTmp, "EnumFonts %d of %d", iLoc+1, count);
                    649:                                        SetWindowText (hwnd, szTmp);
                    650:                                        break;
                    651: 
                    652:                                case ED_NEXT:
                    653:                                        pFL = (LPFONTLIST)GlobalLock (hFonts);
                    654:                                        if (pFL) {
                    655:                                                if ((pFL->count-1) > iLoc) {
                    656:                                                        iLoc++;
                    657:                                                        pFS = (LPFONTSTRUCT)GlobalLock (pFL->hList);
                    658:                                                        if (pFS) {
                    659:                                                                FillEnumFields (hwnd, pFS[iLoc].ft, &pFS[iLoc].tm, &pFS[iLoc].lf, (bHex?16:10));
                    660:                                                                hwndItem = GetDlgItem (hwnd, ED_SAMPLE);
                    661:                                                                DrawSample (hwndItem, &pFS[iLoc].lf);
                    662:                                                                GlobalUnlock (pFL->hList);
                    663:                                                        }
                    664: 
                    665:                                                }
                    666:                                                GlobalUnlock (hFonts);
                    667:                                        }
                    668:                                        wsprintf (szTmp, "EnumFonts %d of %d", iLoc+1, count);
                    669:                                        SetWindowText (hwnd, szTmp);
                    670:                                        break;
                    671: 
                    672:                                case IDOK:
                    673:                                        // Copy the LOGFONT structure from the enumeration list, into our private LF
                    674:                                        pFL = (LPFONTLIST)GlobalLock (hFonts);
                    675:                                        if (pFL) {
                    676:                                                if ((pFL->count-1) > iLoc) {
                    677:                                                        pFS = (LPFONTSTRUCT)GlobalLock (pFL->hList);
                    678:                                                        if (pFS) {
                    679:                                                                lfDlg = pFS[iLoc].lf;
                    680:                                                                GlobalUnlock (pFL->hList);
                    681:                                                        }
                    682:                                                }
                    683:                                                GlobalUnlock (hFonts);
                    684:                                        }
                    685:                                        // Now set our master lf to this value. This way, we 'could' verify that the
                    686:                                        // LOGFONT structure will in fact select this particular font, we just aren't
                    687:                                        *lplf = lfDlg;
                    688:                                        pFL = (LPFONTLIST)GlobalLock (hFonts);
                    689:                                        if (pFL) {
                    690:                                                if (GlobalFree (pFL->hList)) {
                    691:                                                        MessageBox (GetFocus(), "Failed To Free", "pFL->hList", MB_OK);
                    692:                                                } else {
                    693:                                                        GlobalUnlock (hFonts);
                    694:                                                        if (GlobalFree (hFonts)) {
                    695:                                                                MessageBox (GetFocus(), "Failed To Free", "hFonts", MB_OK);
                    696:                                                        }
                    697:                                                }
                    698:                                        }
                    699:                                        EndDialog(hwnd, TRUE);
                    700:                                        return (TRUE);
                    701: 
                    702:                                case IDCANCEL:
                    703:                                        pFL = (LPFONTLIST)GlobalLock (hFonts);
                    704:                                        if (pFL) {
                    705:                                                if (GlobalFree (pFL->hList)) {
                    706:                                                        MessageBox (GetFocus(), "Failed To Free", "pFL->hList", MB_OK);
                    707:                                                } else {
                    708:                                                        GlobalUnlock (hFonts);
                    709:                                                        if (GlobalFree (hFonts)) {
                    710:                                                                MessageBox (GetFocus(), "Failed To Free", "hFonts", MB_OK);
                    711:                                                        }
                    712:                                                }
                    713:                                        }
                    714:                                        EndDialog(hwnd, TRUE);
                    715:                                        return (TRUE);
                    716:                        }
                    717:                        break;
                    718:        }
                    719:        return (FALSE);
                    720: 
                    721:        /* Just For Reference */
                    722:        lParam;
                    723: }

unix.superglobalmegacorp.com

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