peter1234 Posted March 5, 2006 Share Posted March 5, 2006 Does anyone know how to install a new font using AutoIt? Just adding the font to the font folder using FileInstall does not work. Link to comment Share on other sites More sharing options...
strate Posted March 5, 2006 Share Posted March 5, 2006 Does anyone know how to install a new font using AutoIt? Just adding the font to the font folder using FileInstall does not work.You should be able to use FileCopy I think. INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station... Link to comment Share on other sites More sharing options...
peter1234 Posted March 5, 2006 Author Share Posted March 5, 2006 strate, Thanks for the reply, but that does not work either. Link to comment Share on other sites More sharing options...
Lord_Doominik Posted March 5, 2006 Share Posted March 5, 2006 hm, usual you need to install a font correctly the install function in the font folder... but it could work with filecopy, either... file install is for sth. vry different, as you see in the help-file... Link to comment Share on other sites More sharing options...
BigDod Posted March 5, 2006 Share Posted March 5, 2006 Here is an article from MSDMhttp://support.microsoft.com/default.aspx?...kb;en-us;186722 Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
peter1234 Posted March 5, 2006 Author Share Posted March 5, 2006 I used a free exe called fontinst.exe from ParaType Software. That requires creating a folder and flashes a message box but works fine. I hope someone who knows DLLs will make a _FontInstall UDF. In the mean time, I recommend fontinst.exe for anyone else wanting to do this. Link to comment Share on other sites More sharing options...
GaryFrost Posted March 5, 2006 Share Posted March 5, 2006 Does anyone know how to install a new font using AutoIt? Just adding the font to the font folder using FileInstall does not work. Do a search, I've answered this one before SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
Developers Jos Posted March 5, 2006 Developers Share Posted March 5, 2006 (edited) see if this works: #include<file.au3> $rc = InstallFont("C:\temp\jdeb.ttf","JdeB test Font") ConsoleWrite('@@ Debug(2) : $rc = ' & $rc & @lf & '>Error code: ' & @error & @lf);### Debug Console ; Func InstallFont($SourceFile,$FontDescription) Local $HWND_BROADCAST = 0xFFFF Local $WM_FONTCHANGE = 0x1D Local $null, $FontFile, $FontExt _PathSplit($SourceFile,$null,$null,$FontFile,$FontExt) $FontFile = $FontFile & $FontExt Local $rc = FileCopy($SourceFile,@WindowsDir & "\fonts\" & $FontFile,1) If $rc = 0 Then SetError(1) Return 0 EndIf Local $res = DllCall("gdi32.dll","Int","AddFontResource","str",@WindowsDir & "\fonts\" & $FontFile) If $res[0] > 0 Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $FontDescription, "REG_SZ", $FontFile) DllCall("user32.dll","Int","SendMessage","HWND",$HWND_BROADCAST,"int", $WM_FONTCHANGE,"int", 0,"int", 0) Return 1 Else SetError(2) Return 0 EndIf EndFunc Edited March 5, 2006 by JdeB SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
peter1234 Posted March 5, 2006 Author Share Posted March 5, 2006 gafrost, Thanks. When I tried this I got a DllStructDelete($s_p) error. Font was in same folder as script. ;>>>>>> NOTE - REQUIRES BETA AUTOIT AND COMPILER <<<<<<<<< #include <GuiConstants.au3> FileChangeDir (@ScriptDir) _LoadFont("ariblk.ttf") Func _LoadFont($Fontname) $s_p = DllStructCreate("char[" & StringLen($Fontname) + 1 & "]") If @error Then Return @error EndIf DllStructSetData($s_p, 1, $Fontname) $msg = DllCall("gdi32.dll", "int", "AddFontResource", "ptr", DllStructGetPtr($s_p)) DllStructDelete($s_p) If @error = 1 Then MsgBox(0, "DLLcall", "unable to use the DLL file") If @error = 2 Then MsgBox(0, "DLLcall", "unknown return type") Return $msg[0] EndFunc ;==>_LoadFont Link to comment Share on other sites More sharing options...
GaryFrost Posted March 5, 2006 Share Posted March 5, 2006 gafrost, Thanks. When I tried this I got a DllStructDelete($s_p) error. Font was in same folder as script. ;>>>>>> NOTE - REQUIRES BETA AUTOIT AND COMPILER <<<<<<<<< #include <GuiConstants.au3> FileChangeDir (@ScriptDir) _LoadFont("ariblk.ttf") Func _LoadFont($Fontname) $s_p = DllStructCreate("char[" & StringLen($Fontname) + 1 & "]") If @error Then Return @error EndIf DllStructSetData($s_p, 1, $Fontname) $msg = DllCall("gdi32.dll", "int", "AddFontResource", "ptr", DllStructGetPtr($s_p)) DllStructDelete($s_p) If @error = 1 Then MsgBox(0, "DLLcall", "unable to use the DLL file") If @error = 2 Then MsgBox(0, "DLLcall", "unknown return type") Return $msg[0] EndFunc;==>_LoadFont just change DllStructDelete($s_p) to $s_p = 0 SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
peter1234 Posted March 5, 2006 Author Share Posted March 5, 2006 JdeB, This works but The Font Thing shows a warning symbol next to font and is not able to uninstall the font, so I think it is not being installed correctly. But it works, thanks. Font was in same folder as script. #include <GuiConstants.au3> #include<file.au3> FileChangeDir (@ScriptDir) $rc = InstallFont("ariblk.ttf","Arial Black") ConsoleWrite('@@ Debug(2) : $rc = ' & $rc & @lf & '>Error code: ' & @error & @lf);### Debug Console MsgBox(0, "Font Installed", "Arial Black ") ; Func InstallFont($SourceFile,$FontDescription) Local $HWND_BROADCAST = 0xFFFF Local $WM_FONTCHANGE = 0x1D Local $null, $FontFile, $FontExt _PathSplit($SourceFile,$null,$null,$FontFile,$FontExt) $FontFile = $FontFile & $FontExt Local $rc = FileCopy($SourceFile,@WindowsDir & "\fonts\" & $FontFile,1) If $rc = 0 Then SetError(1) Return 0 EndIf Local $res = DllCall("gdi32.dll","Int","AddFontResource","str",@WindowsDir & "\fonts\" & $FontFile) If $res[0] > 0 Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", $FontDescription, "REG_SZ", $FontFile) DllCall("user32.dll","Int","SendMessage","HWND",$HWND_BROADCAST,"int", $WM_FONTCHANGE,"int", 0,"int", 0) Return 1 Else SetError(2) Return 0 EndIf EndFunc Link to comment Share on other sites More sharing options...
peter1234 Posted March 5, 2006 Author Share Posted March 5, 2006 gafrost, Thanks. That works, but font is not installed correctly. Font does show up in Word and can be used in AutoIt scripts, but Font does not appear in Font folder and is not detected by The Font Thing program. Link to comment Share on other sites More sharing options...
peter1234 Posted March 5, 2006 Author Share Posted March 5, 2006 I have noticed that if I just copy the font to the font folder and then open and close the Font folder, the font gets registered OK. But I haven't figured out how to get AutoIt to open and close the font folder in a script. Link to comment Share on other sites More sharing options...
CyberSlug Posted March 5, 2006 Share Posted March 5, 2006 I have noticed that if I just copy the font to the font folder and then open and close the Font folder, the font gets registered OK. But I haven't figured out how to get AutoIt to open and close the font folder in a script.Something like this should work: Opt("WinTitleMatchMode", 2);match partial titles Run("explorer " & @WindowsDir & "\Fonts", "", @SW_MINIMIZE) WinWait("Fonts") WinClose("Fonts") Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
peter1234 Posted March 6, 2006 Author Share Posted March 6, 2006 (edited) CyberSlug, Thanks. This works perfect using Windows XP. #include <GuiConstants.au3> FileChangeDir (@ScriptDir) $FontFile="ariblk.ttf" _FontInstall ( $FontFile ) MsgBox(0, "Font Installed", $FontFile ) Func _FontInstall ( $FontFile ) FileCopy ( $FontFile, @WindowsDir & "\Fonts" ,1 ) Run("explorer " & @WindowsDir & "\Fonts", "", @SW_HIDE) WinWait("Fonts") WinClose("Fonts") EndFunc Edited March 6, 2006 by peter1234 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now