Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reverse of PROCEDURE InstallSystemFont() (by agoeddeke) ????

Status
Not open for further replies.

Ivanq

Programmer
Aug 30, 2005
8
US
I am using the PROCEDURE InstallSystemFont() posted by agoeddeke on 21 Oct 04. It does exactly what I needed (thank you very much). Now I need a procedure that will do just the reverse - remove the font from AddFontResource from within VFP. I allow a user to view non-installed fonts and give them the option of installing or not. To do this I copy the font ttf file, which is in a table, to a temp folder and call InstallSystemFont(). If they choose not to install I need to ERASE that font file from the temp folder. Problem is the font file in in use by windows and can not be erased from the temp folder untill a reboot.

Would appreciate any help.
 
This is untested, but maybe try the RemoveFontResource API:

Code:
llSuccess = RemoveSystemFont("path\filename.ttf")
** erase file now ***


PROCEDURE RemoveSystemFont()
   LPARAMETERS lcFontLocFile
   LOCAL lnNumFontsRemoved

   DECLARE INTEGER RemoveFontResource IN GDI32.DLL ;
      STRING @ lpszFileName
   DECLARE INTEGER SendMessage IN USER32.DLL ;
      INTEGER hWnd, ;
      INTEGER Msg, ;
      INTEGER wParameter, ;
      INTEGER lParameter
   #DEFINE HWND_BROADCAST 0xFFFF
   #DEFINE WM_FONTCHANGE  0x001D

   lnNumFontsRemoved=RemoveFontResource(lcFontLocFile)
   IF lnNumFontsRemoved > 0
      *\\Font removed sucessfully, send notification to Windows so apps get updated
      =SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0)
      RETURN .T.
      ELSE
      *\\Unable to remove font
      RETURN .F.
   ENDIF   
ENDPROC

Andy
 
Thank you for your help but it doesn't seem to work. Always returns .f.. Maybe I'm doing something wrong - I just pass the full font name such as =RemoveSystemFont("easygo.tff") - is this correct?

As far as using RemoveFontResource API I haven't a clue on how to do it but would like to learn.

Do appreciate your time - - -
 
Maybe I'm doing something wrong - I just pass the full font name such as =RemoveSystemFont("easygo.tff") - is this correct?

I guess I might try fully qualifying the path to the TTF file. As in:
Code:
=RemoveSystemFont(GETENV("SYSTEMROOT")+"\FONTS\easygo.ttf")

Just a guess. [ponder]

Andy
 
I tried the above suggestion but still returns .f.

Regardless of what value the procedure returns, are you able to erase the TTF file after you call the procedure? That's the overall goal isn't it?

Andy
 
I think I've solved this problem. At least this procedure is working for me now. I can now erase the temp font file.

*************************************************************
* adds/removes temp fonts
* found basis of code ( I have modified) at:
* * and
* * and lots of code/help from agoeddeke on Tek=Tips
* para:
* whichaction = 'add', 'remove'
* processfontname = full font name
*
* NOTE!!!
* the parameter processfontname must also incude the
* file path if the font is NOT
* in the default windows/font folder - this applies
* for add or remove
* IE:
* do AddRemoveFont with "add',"t\baxter.ttf"
* where 't\' is a subdir that has the font file
* under some circumstances you must use
* CLEAR RESOURCES 'fontname' before calling this
* procedure to remove a font
*************************************************************
Procedure AddRemoveFont
Lparameters whichaction,processfontname
failed=.F.
* add the font
Do Case
Case whichaction="add"
Declare AddFontResource In GDi32.Dll String
If AddFontResource(processfontname)
Wait Window Nowait "Font Installed..."
Else
Wait Window "Addition Failed..." Nowait
failed=.T.
Endif
* not sure if this is correct
Clear Dlls "AddFontResource"
* Removing the resource file is done with
* RemoveFontResource which resides
* in the same DLL and has the same parameter
Case whichaction="remove"
Declare RemoveFontResource In GDi32.Dll String
If RemoveFontResource(processfontname)
Wait Window Nowait "Font Removed..."
Else
Wait Window "Removal Failed..." Nowait
failed=.T.
Endif
* not sure if this is correct
Clear Dlls "RemoveFontResource"
Endcase
* message to other win apps of the modified
* font selections
If Not failed
Declare Integer SendMessage In USER32.Dll ;
INTEGER HWnd, ;
INTEGER Msg, ;
INTEGER wParameter, ;
INTEGER Lparameter
#Define HWND_BROADCAST 0xFFFF
#Define WM_FONTCHANGE 0x001D
=SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0)
Endi
Return .T.
 
agoeddeke, thanks for all your help

Cliff - - -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top