home *** CD-ROM | disk | FTP | other *** search
/ ftp.funduc.com / 2014.08.ftp.funduc.com.tar / ftp.funduc.com / WiseFontDLL.zip / Wisefont.cpp < prev    next >
C/C++ Source or Header  |  2002-07-25  |  4KB  |  124 lines

  1. // mksht.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <tchar.h>
  6. #include <shlobj.h>
  7. #include <stdio.h>
  8. #include "wisedll.h"
  9.  
  10. #define WISEFONTFACE    _T("WISEFONTFACE")
  11. #define WISEFONTPOINTS  _T("WISEFONTPOINTS")
  12. #define WISEFONTITA     _T("WISEFONTITALIC")
  13. #define WISEFONTWEIGHT  _T("WISEFONTWEIGHT")
  14. #define WISEFONTUNDER   _T("WISEFONTUNDER")
  15. #define WISEFONTSTRIKE  _T("WISEFONTSTRIKE")
  16.  
  17. void GetVariable(LPDLLCALLPARAMS lpDllParams,char *szVariable,char *szValue);
  18. void SetVariable(LPDLLCALLPARAMS lpDllParams,char *szVariable,char *szValue);
  19.  
  20. __declspec(dllexport) BOOL CALLBACK GetFontInfo(LPDLLCALLPARAMS lpDllParams)
  21. {
  22.    if ((lpDllParams->lpszParam) && SUCCEEDED(CoInitialize(NULL)))
  23.    {
  24.       int nPointSize;
  25.       TCHAR szFontFace[MAX_PATH + 1], szFontSize[MAX_PATH + 1];
  26.       LOGFONT lf = {0};
  27.       CHOOSEFONT cf = {0};
  28.       GetVariable(lpDllParams, WISEFONTFACE, szFontFace);
  29.       GetVariable(lpDllParams, WISEFONTPOINTS, szFontSize);
  30.       nPointSize = atol(szFontSize);
  31.       GetVariable(lpDllParams, WISEFONTITA, szFontSize);
  32.       lf.lfItalic = (UCHAR)atol(szFontSize);
  33.       GetVariable(lpDllParams, WISEFONTWEIGHT, szFontSize);
  34.       lf.lfWeight = atol(szFontSize);
  35.       GetVariable(lpDllParams, WISEFONTUNDER, szFontSize);
  36.       lf.lfUnderline = (UCHAR)atol(szFontSize);
  37.       GetVariable(lpDllParams, WISEFONTSTRIKE, szFontSize);
  38.       lf.lfStrikeOut = (UCHAR)atol(szFontSize);
  39.  
  40.       cf.lStructSize = sizeof(CHOOSEFONT);
  41.       cf.hwndOwner = (HWND)lpDllParams->hWnd;
  42.       cf.lpLogFont = &lf; 
  43.       cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS; 
  44.       cf.nFontType = SCREEN_FONTTYPE; 
  45.       if (nPointSize)
  46.       {
  47.           HDC hdc = GetDC(NULL);
  48.           lf.lfHeight = -MulDiv(nPointSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
  49.           ReleaseDC(NULL, hdc);
  50.           strcpy(lf.lfFaceName, szFontFace);
  51.       }
  52.  
  53.       if (ChooseFont(&cf) == 0)
  54.           return FALSE;
  55.  
  56.       strcpy(szFontFace, lf.lfFaceName);
  57.       nPointSize = cf.iPointSize / 10;
  58.       SetVariable(lpDllParams, WISEFONTFACE, szFontFace);
  59.       sprintf(szFontSize, "%d", nPointSize);
  60.       SetVariable(lpDllParams, WISEFONTPOINTS, szFontSize);
  61.       sprintf(szFontSize, "%d", lf.lfItalic);
  62.       SetVariable(lpDllParams, WISEFONTITA, szFontSize);
  63.       sprintf(szFontSize, "%d", lf.lfWeight);
  64.       SetVariable(lpDllParams, WISEFONTWEIGHT, szFontSize);
  65.       sprintf(szFontSize, "%d", lf.lfUnderline);
  66.       SetVariable(lpDllParams, WISEFONTUNDER, szFontSize);
  67.       sprintf(szFontSize, "%d", lf.lfStrikeOut);
  68.       SetVariable(lpDllParams, WISEFONTSTRIKE, szFontSize);
  69.       return TRUE;
  70.    }
  71.    return FALSE;
  72. }
  73.  
  74. int CALLBACK LibMain(HINSTANCE hInst, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine)
  75. {
  76.   return(1);
  77. }
  78.  
  79. // GetVariable: Returns the value of a variable.
  80. //
  81. // lpDllParams  Parameter structure passed from Wise Installation
  82. // szVariable   Name of the variable (without %'s) to get value for
  83. // szValue      String that will hold the variables value
  84.  
  85. void GetVariable(LPDLLCALLPARAMS lpDllParams,char *szVariable,char *szValue)
  86. {
  87.    WORD i;
  88.    char szVar[32];
  89.  
  90.    *szVar = '%';
  91.    lstrcpy(&szVar[1],szVariable);
  92.    lstrcat(szVar,"%");
  93.    for (i = 0 ; (i < lpDllParams->wCurrReps) &&
  94.       (lstrcmp(&lpDllParams->lpszRepName[i * lpDllParams->wRepNameWidth],szVar) != 0) ; i++) ;
  95.    if (i < lpDllParams->wCurrReps) {
  96.       lstrcpy(szValue,&lpDllParams->lpszRepStr[i * lpDllParams->wRepStrWidth]);
  97.    } else *szValue = '\0';
  98. }
  99.  
  100. // SetVariable: Sets/Creates a variable.
  101. //
  102. // lpDllParams  Parameter structure passed from Wise Installation
  103. // szVariable   Name of the variable (without %'s) to set value for
  104. // szValue      String that contains the variables new value
  105.  
  106. void SetVariable(LPDLLCALLPARAMS lpDllParams,char *szVariable,char *szValue)
  107. {
  108.    WORD i;
  109.    char szVar[32];
  110.  
  111.    *szVar = '%';
  112.    lstrcpy(&szVar[1],szVariable);
  113.    lstrcat(szVar,"%");
  114.    for (i = 0 ; (i < lpDllParams->wCurrReps) &&
  115.       (lstrcmp(&lpDllParams->lpszRepName[i * lpDllParams->wRepNameWidth],szVar) != 0) ; i++) ;
  116.    if (i >= lpDllParams->wCurrReps) {
  117.       if (i >= lpDllParams->wMaxReplaces) return; // Too many variables
  118.       lstrcpy(&lpDllParams->lpszRepName[i * lpDllParams->wRepNameWidth],szVar);
  119.       lpDllParams->wCurrReps++;
  120.    }
  121.    lstrcpy(&lpDllParams->lpszRepStr[i * lpDllParams->wRepStrWidth],szValue);
  122. }
  123.  
  124.