home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / enumfont / enumfont.c next >
C/C++ Source or Header  |  1991-09-19  |  3KB  |  75 lines

  1. // enumfont.c
  2. //***************************************************************
  3. //*                                                             *
  4. //*                DLL to allow VB to use EnumFonts             *
  5. //*                                                             *
  6. //*  Copyright (C) Telelink Systems 1991 All Rights Reserved    *
  7. //*  Phone:  (916) 332-2671                   Fax:  332-2529    *
  8. //***************************************************************
  9. //
  10. // Compilation instructions:
  11. //    Turbo C++
  12. //    Small model
  13. //    SS=!DS
  14.  
  15. #include <windows.h>
  16. #include <drivinit.h>
  17.  
  18. HANDLE hCallerInstance;
  19.  
  20. // Globals
  21. int nFontIndex;                       // Running font number
  22. int nUserArraySize;                   // Size of the array provided by user
  23. LPLOGFONT  lpUserLogFontArray;        // User's logical font array or NULL
  24. LPTEXTMETRIC lpUserTextMetricArray;   // User's text metric array or NULL
  25. LPINT lpnUserFontTypeArray;           // User's font type array or NULL
  26.  
  27. // Call back routine
  28. int FAR PASCAL  EnumFontsCallBack(
  29.            LPLOGFONT lpLogFont,
  30.            LPTEXTMETRIC lpTextMetric,
  31.            short nFontType,
  32.            LPSTR lpData)
  33. {
  34.    // If user allocated space, move the data
  35.    if (nFontIndex<=nUserArraySize-1){
  36.        if (lpUserLogFontArray) *(lpUserLogFontArray+nFontIndex)=*lpLogFont;
  37.        if (lpUserTextMetricArray) *(lpUserTextMetricArray+nFontIndex)=*lpTextMetric;
  38.        if (lpnUserFontTypeArray) *(lpnUserFontTypeArray+nFontIndex)=nFontType;
  39.    }
  40.    // Increment number of fonts and return the number
  41.    return(++nFontIndex);
  42. }
  43.  
  44. // DLL Entry from Visual Basic
  45. int FAR PASCAL _export VBEnumFonts(
  46.           HDC hDC,                       // Device Context handle
  47.           LPSTR lpFaceName,              // typeface or null if all
  48.           LPLOGFONT lpLogFontArray,        // Array of LOGFONT elements or null
  49.           LPTEXTMETRIC lpTextMetricArray,// Array of TEXTMETRIC elements or null
  50.           LPINT nFontTypeArray,          // Array of integers or null
  51.           int nArraySize                 // Size of the arrays or 0
  52.           )                              // Returns number of fonts available
  53. {
  54.     static FARPROC lpfnEnumFontCallBack;
  55.  
  56.     // Register the call-back routine
  57.     if (!lpfnEnumFontCallBack) lpfnEnumFontCallBack=MakeProcInstance(EnumFontsCallBack,hCallerInstance);
  58.  
  59.     // Initialize global structure
  60.     nFontIndex=0;
  61.     nUserArraySize=nArraySize;
  62.     lpUserLogFontArray=lpLogFontArray;
  63.     lpUserTextMetricArray=lpTextMetricArray;
  64.     lpnUserFontTypeArray=nFontTypeArray;
  65.  
  66.     return(EnumFonts(hDC,lpFaceName,lpfnEnumFontCallBack,NULL));
  67. }
  68.  
  69.  
  70. int FAR PASCAL LibMain(HANDLE hInstance,WORD wDataSet, WORD cbHeapSize, LPSTR lpszCmdLine)
  71. {
  72.     hCallerInstance=hInstance;
  73.     return (1);
  74. }
  75.