Tengo que comprobar si un fuente TTF de codigo de barras esta instalado en un PC y si no lo encuentro instalarlo desde mi executable.
Alquien tieen codigo para eso?
Tengo que comprobar si un fuente TTF de codigo de barras esta instalado en un PC y si no lo encuentro instalarlo desde mi executable.
Alquien tieen codigo para eso?
LZCOPYFILE( Curdrive()+":\"+Curdir()+"\I2of5nt.ttf", GetWindir()+"\fonts\I2of5nt.ttf")
*-- Code begins here
聽 聽CLEAR DLLS
聽 聽PRIVATE iRetVal, iLastError
聽 聽PRIVATE sFontDir, sSourceDir, sFontFileName, sFOTFile
聽 聽PRIVATE sWinDir, iBufLen
聽 聽iRetVal = 0
聽 聽***** Code to customize with actual file names and locations.
聽 聽*-- .TTF file path.
聽 聽sSourceDir = "C:\TEMP\"
聽 聽*-- .TTF file name.
聽 聽sFontFileName = "TestFont.TTF"
聽 聽*-- Font description (as it will appear in Control Panel).
聽 聽sFontName = "My Test Font" + " (TrueType)"
聽 聽******************** End of code to customize *****
聽 聽DECLARE INTEGER CreateScalableFontResource IN win32api ;
聽 聽 聽LONG fdwHidden, ;
聽 聽 聽STRING lpszFontRes, ;
聽 聽 聽STRING lpszFontFile, ;
聽 聽 聽STRING lpszCurrentPath
聽 聽DECLARE INTEGER AddFontResource IN win32api ;
聽 聽 聽 聽STRING lpszFilename
聽 聽DECLARE INTEGER RemoveFontResource IN win32api ;
聽 聽 聽 聽STRING lpszFilename
聽 聽DECLARE LONG GetLastError IN win32api
聽 聽DECLARE INTEGER GetWindowsDirectory IN win32api STRING @lpszSysDir,;
聽 聽 聽INTEGER iBufLen
聽 聽#DEFINE WM_FONTCHANGE 聽 29 && 0x001D
聽 聽#DEFINE HWND_BROADCAST 聽65535 && 0xffff
聽 聽DECLARE LONG SendMessage IN win32api ;
聽 聽 聽 聽LONG hWnd, INTEGER Msg, LONG wParam, INTEGER lParam
聽 聽#DEFINE HKEY_LOCAL_MACHINE 2147483650 聽 && (HKEY) 0x80000002
聽 聽#DEFINE SECURITY_ACCESS_MASK 983103 聽 聽 && SAM value KEY_ALL_ACCESS
聽 聽DECLARE RegCreateKeyEx IN ADVAPI32.DLL ;
聽 聽 聽 INTEGER, STRING, INTEGER, STRING, INTEGER, INTEGER, ;
聽 聽 聽 聽 聽 聽INTEGER, INTEGER @, INTEGER @
聽 聽DECLARE RegSetValueEx IN ADVAPI32.DLL;
聽 聽 聽 聽 聽 聽INTEGER, STRING, INTEGER, INTEGER, STRING, INTEGER
聽 聽DECLARE RegCloseKey IN ADVAPI32.DLL INTEGER
聽 聽*-- Fonts folder path.
聽 聽*-- Use the GetWindowsDirectory API function to determine
聽 聽*-- where the Fonts directory is located.
聽 聽sWinDir = SPACE(50) 聽&& Allocate the buffer to hold the directory name.
聽 聽iBufLen = 50 聽 聽 聽 聽 && Pass the size of the buffer.
聽 聽iRetVal = GetWindowsDirectory(@sWinDir, iBufLen)
聽 聽*-- iRetVal holds the length of the returned string.
聽 聽*-- Since the string is null-terminated, we need to
聽 聽*-- snip the null off.
聽 聽sWinDir = SUBSTR(sWinDir, 1, iRetVal)
聽 聽sFontDir = sWinDir + "\FONTS\"
聽 聽*-- Get .FOT file name.
聽 聽sFOTFile 聽= sFontDir + LEFT(sFontFileName, ;
聽 聽 聽LEN(sFontFileName) - 4) + ".FOT"
聽 聽*-- Copy to Fonts folder.
聽 聽COPY FILE (sSourceDir + sFontFileName) TO ;
聽 聽 聽(sFontDir + sFontFileName)
聽 聽*-- Create the font.
聽 聽iRetVal = ;
聽 聽 聽CreateScalableFontResource(0, sFOTFile, sFontFileName, sFontDir)
聽 聽IF iRetVal = 0 THEN
聽 聽 聽 聽iLastError = GetLastError ()
聽 聽 聽 聽IF iLastError = 80
聽 聽 聽 聽 聽 MESSAGEBOX("Font file " + sFontDir + sFontFileName + ;
聽 聽 聽 聽 聽 "already exists.")
聽 聽 聽 聽ELSE
聽 聽 聽 聽 聽 聽MESSAGEBOX("Error " + STR (iLastError))
聽 聽 聽 聽ENDIF
聽 聽 聽 RETURN
聽 聽ENDIF
聽 聽*-- Add the font to the system font table.
聽 聽iRetVal = AddFontResource (sFOTFile)
聽 聽IF iRetVal = 0 THEN
聽 聽 聽 聽iLastError = GetLastError ()
聽 聽 聽 聽IF iLastError = 87 THEN
聽 聽 聽 聽 聽 聽MESSAGEBOX("Incorrect Parameter")
聽 聽 聽 聽ELSE
聽 聽 聽 聽 聽 聽MESSAGEBOX("Error " + STR (iLastError))
聽 聽 聽 聽ENDIF
聽 聽 聽 RETURN
聽 聽ENDIF
聽 聽*-- Make the font persistent across reboots.
聽 聽STORE 0 TO iResult, iDisplay
聽 聽iRetVal = RegCreateKeyEx(HKEY_LOCAL_MACHINE, ;
聽 聽 聽"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", 0, "REG_SZ", ;
聽 聽 聽0, SECURITY_ACCESS_MASK, 0, @iResult, ;
聽 聽 聽@iDisplay) && Returns .T. if successful
聽 聽*-- Uncomment the following lines to display information
聽 聽*!* 聽 *-- about the results of the function call.
聽 聽*!* 聽 聽 聽WAIT WINDOW STR(iResult) 聽 && Returns the key handle
聽 聽*!* 聽 聽 聽WAIT WINDOW STR(iDisplay) 聽&& Returns one of 2 values:
聽 聽*!* 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 && REG_CREATE_NEW_KEY = 1
聽 聽*!* 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 && REG_OPENED_EXISTING_KEY = 2
聽 聽iRetVal = RegSetValueEx(iResult, sFontName, 0, 1, sFontFileName, 13)
聽 聽*-- Close the key. 聽Don't keep it open longer than necessary.
聽 聽iRetVal = RegCloseKey(iResult)
聽 聽*-- Notify all the other application a new font has been added.
聽 聽iRetVal = SendMessage (HWND_BROADCAST, WM_FONTCHANGE, 0, 0)
聽 聽IF iRetVal = 0 THEN
聽 聽 聽 聽iLastError = GetLastError ()
聽 聽 聽 聽 聽 聽MESSAGEBOX("Error " + STR (iLastError))
聽 聽 聽 RETURN
聽 聽ENDIF
聽 聽ERASE (sFOTFile)
聽 聽*-- Code ends hereHola,
probaste con la funci贸n AddFontResource
Adds a new font to the Windows font table
Syntax:
AddFontResource( <cFontFile> | <hFontResource> ) --> nFontsAdded
This function add a font resource to the Windows font table. Any application can then use the font.
Parameters:
<cFontFile> The name of an external file where we have stored some fonts we want to use in our application.
<hFontResource> The handle of a module (DLL) where we have stored some fonts we want to use in our application.
Returns:
<nFontsAdded> The number of fonts the system successfully added.
Pruebe con fontinst.exe, se acabaron los problemas (windows 7 incluido)
FUNCTION INSTFONTS()
Local lDescarga:=.F.
IF FILE("fontinst.inf")
聽ERASE fontinst.inf
ENDIF
IF !MSGYESNO("Instalar Codigos de barras")
RETURN NIL
ENDIF
IF !FILE("fontinst.exe")
lDescarga:=.T.
ENDIF
IF !FILE("Bar128ct.ttf")
lDescarga:=.T.
ENDIF
IF lDescarga
聽UPLOADFONTS()
ENDIF
XMENSCEN("[fonts]")
LZCOPYFILE( Curdrive()+ ":\" + Curdir() + "\Bar128ct.ttf", GetWindir()+"\fonts\Bar128ct.ttf" )
xmenscen("Bar128ct.ttf")
WINEXEC("fontinst.exe /f fontinst.inf")
MSGWAIT("Fuentes Instalados")
RETURN NIL
************************************************************
FUNCTION XMENSCEN(cText)
Local cFile:="fontinst.inf"
Local oText
oText := TTxtFile():New(cFile)
if oText:Open()
oText :Add( cText )
oText :Close()
endif
RETURN NIL
****************************************************
FUNCTION UPLOADFONTS()
Local oText,i
Local n:=0
IF FILE("UPLOADB.TXT")
聽ERASE 聽UPLOADB.TXT
ENDIF
oText:= TTxtFile():New("UPLOADB.TXT" )
if oText:Open()
oText :Add("OPEN 999.999.999.999") //ftp de los fuentes 聽
oText :Add("software") 聽 聽 聽 聽 聽
oText :Add("1234567890" ) 聽 聽 聽 聽 聽
oText :Add("PROMPT OFF" )
oText :Add("BIN" )
oText :Add("HASH" )
oText :Add("MGET Bar128ct.ttf")
oText :Add("MGET fontinst.exe" )
oText :Add("QUIT" )
oText:Close()
endif
IF FILE("UPLOADB.TXT")
聽WAITRUN("FTP -s:UPLOADB.TXT")
ENDIF
ERASE UPLOADB.TXT
MSGWAIT("Fuentes descargados","Descarga OK")
Return .T.
**********************************************************************************