James Bott wrote:Ollie wants to be able to save and retore a user defined font.
This is a working sample:
- Code: Select all Expand view
#include "Fivewin.ch"
FUNCTION MAIN()
LOCAL oWnd
LOCAL cVar := "This is a test"
LOCAL aFont := SELECTFONT( oWnd )
LOCAL aSaved
IF EMPTY( aFont ); RETURN NIL; ENDIF
DEFINE WINDOW oWnd
@ 1, 1 SAY "This is a test";
COLOR CLR_BLACK
@ 3, 1 GET cVar;
SIZE 100, 20
@ 5, 1 BUTTON "Choose font";
SIZE 100, 20;
ACTION aFont := SELECTFONT( oWnd )
@ 7, 1 BUTTON "Save font";
SIZE 100, 20;
ACTION aSaved := aFont
@ 9, 1 BUTTON "Restore font";
SIZE 100, 20;
ACTION RESTOREFONT( oWnd, aSaved )
ACTIVATE WINDOW oWnd
RETURN NIL
#define FW_NORMAL 400
STATIC FUNCTION SELECTFONT( oWnd )
LOCAL aFont := CHOOSEFONT()
LOCAL oFont := BUILDFONT( aFont )
IF oFont = NIL; RETURN NIL; ENDIF
IF oWnd != NIL; REFRESHWND( oWnd, oFont ); ENDIF
RETURN aFont
STATIC FUNCTION RESTOREFONT( oWnd, aFont )
LOCAL oFont := BUILDFONT( aFont )
IF oFont = NIL; RETURN NIL; ENDIF
REFRESHWND( oWnd, oFont )
RETURN NIL
STATIC FUNCTION BUILDFONT( aFont )
IF EMPTY( aFont[ LF_FACENAME ] )
RETURN NIL
ENDIF
RETURN TFont():New( aFont[ LF_FACENAME ],;
,;
aFont[ LF_HEIGHT ],;
.f.,;
!( aFont[ LF_WEIGHT ] == FW_NORMAL ),;
aFont[ LF_ESCAPEMENT ],;
aFont[ LF_ORIENTATION ],;
aFont[ LF_WEIGHT ],;
aFont[ LF_ITALIC ],;
aFont[ LF_UNDERLINE ],;
aFont[ LF_STRIKEOUT ],;
aFont[ LF_CHARSET ],;
aFont[ LF_OUTPRECISION ],;
aFont[ LF_CLIPPRECISION ],;
aFont[ LF_QUALITY ],;
,;
aFont[ LF_PITCHANDFAMILY ] )
STATIC FUNCTION REFRESHWND( oWnd, oFont )
LOCAL i
oWnd:SetFont( oFont )
FOR i = 1 TO LEN( oWnd:aControls )
oWnd:aControls[ i ]:SetFont( oFont )
oWnd:aControls[ i ]:Refresh()
NEXT
RETURN NIL
EMG