You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
AddFontResource addresses the original challenge only... makes a font from a file available to the current process. It does NOT install the font permanently. For that you need, let me see if I can find it...no, but I found this comment under AddFontResource..
This function installs the font only for the current session. When the system restarts, the font will not be present. To have the font installed even after restarting the system, the font must be listed in the registry.
[/LATER]
[This message has been edited by Michael Mattias (edited February 16, 2007).]
#RESOURCE "truetype.pbr" 'MyFont RCDATAT alphalcd.ttf
CASE %WM_INITDIALOG
sFontFile = "C:\PowerBasic\Samples\alphalcd.ttf" '<-if from file
'sFontFile = "MyFont" '<-if from resource/ note: doesn't work
lRt& = AddFontResource(BYVAL STRPTR(sFontFile))
'SendMessage(%HWND_BROADCAST, %WM_FONTCHANGE, 0, 0) '<--not necessary if confined within your own process.
'SendMessage(%HWND_BROADCAST, %WM_SETTINGCHANGE, 0, 0)'<-- ditto
hFont = PBFormsMakeFont("Alphanumeric LCD",80,400,%FALSE,%FALSE,%FALSE,%ANSI_CHARSET)
CASE %WM_COMMAND
SELECT CASE AS LONG CBCTL
CASE %IDC_BUTTON1
IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
A$ = FORMAT$(123456, "00\:00\:00")
CONTROL SET TEXT CBHNDL, %IDC_LABEL1,A$
CONTROL SEND CBHNDL, %IDC_LABEL1, %WM_SETFONT, hFont, 0
CONTROL REDRAW CBHNDL, %IDC_LABEL1
END IF
END SELECT
CASE %WM_DESTROY
DeleteObject hFont
RemoveFontResource( BYVAL STRPTR(sFontFile)) '<--corrected VARPTR to STRPTR per MCM catch.
------------------
[This message has been edited by Jules Marchildon (edited February 18, 2007).]
I combined this with today's other neat feature (set numbers whilst button is down by Pierre Bellisle) to arrive at this PB/WIN 8x demo code:
(oops, needed to change szFontFile to STATIC)(Ok, so I'm lazy sometimes myself).
Code:
#COMPILE EXE '#Win 8.03#
#REGISTER NONE
#INCLUDE "Win32Api.inc" '#2005-01-27#
#INCLUDE "Pbforms.inc"
OPTION EXPLICIT
%ButtonOne = 101
%TimerOne = 201
%labelOne = 301
'______________________________________________________________________________
CALLBACK FUNCTION DlgProc
STATIC TimerCount AS LONG
LOCAL hCtrl AS LONG
STATIC szFontFile AS ASCIIZ * %MAX_PATH
LOCAL hFont AS LONG, I AS LONG
LOCAL sFontFace AS STRING
SELECT CASE CBMSG
CASE %WM_INITDIALOG
CONTROL HANDLE CBHNDL, %LabelOne TO hCtrl
' file from Jules Marchildon / tripod
szFontFile = "alphalcd.ttf"
sFontFace = "Alphanumeric LCD"
' file from Harvey Twyman
szFontFile = "7 Segment.ttf"
sFontFace = "7 Segment"
I = AddFontResource(BYVAL VARPTR(szFontFile))
MSGBOX USING$ ("Added # fonts", I)
'hFont = PBFormsMakeFont(sFontFace, 36, 200,%FALSE,%FALSE,%FALSE,%ANSI_CHARSET)
' LED font would not work with ANSI_CHARSET
hFont = PBFormsMakeFont(sFontFace, 30, 200,%FALSE,%FALSE,%FALSE,%DEFAULT_CHARSET)
IF ISFALSE hFont THEN
MSGBOX "MakeFont failed"
END IF
CONTROL SEND CBHNDL, %LabelOne, %WM_SETFONT, hFont, %NULL
CONTROL SET USER CBHNDL, %LabelOne, 1, hFont
CASE %WM_SETCURSOR
IF (CBWPARAM = GetDlgItem(CBHNDL, %ButtonOne)) AND _ 'Is it the button handle
(HI(WORD, CBLPARAM) = %WM_LBUTTONDOWN) THEN 'Is button pushed
DIALOG SET TEXT CBHNDL, HEX$(HI(WORD, CBLPARAM)) & " : Button is down "
SetTimer CBHNDL, %TimerOne, 100, BYVAL %NULL 'Set a 100 miliseconds timer
ELSE
DIALOG SET TEXT CBHNDL, HEX$(HI(WORD, CBLPARAM)) & " : Button is up"
KillTimer CBHNDL, %TimerOne
END IF
CASE %WM_DESTROY
CONTROL GET USER CBHNDL, %LabelOne, 1 TO hFont
DeleteObject hFont
RemoveFontResource( BYVAL VARPTR(szFontFile))
CASE %WM_TIMER
SELECT CASE CBWPARAM
CASE %TimerOne
INCR TimerCount
CONTROL SET TEXT CBHNDL, %ButtonOne, "Timercount :" & STR$(Timercount)
CONTROL SET TEXT CBHNDL, %LabelOne, USING$("Count #,", TimerCount)
END SELECT
CASE %WM_COMMAND
SELECT CASE LOWRD(CBWPARAM)
CASE %ButtonOne
IF CBCTLMSG = %BN_CLICKED THEN
END IF
END SELECT
END SELECT
END FUNCTION
'______________________________________________________________________________
FUNCTION PBMAIN()
LOCAL hDlg AS DWORD
DIALOG NEW %HWND_DESKTOP ,"Button down / LED FONT", , , 200, 120, _
%WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU, 0 TO hDlg
SetClassLong hDlg, %GCL_HICON, LoadIcon(BYVAL %NULL, BYVAL %IDI_INFORMATION)
CONTROL ADD BUTTON, hDlg, %ButtonOne, "Button", 50, 43, 100, 15, _
%BS_CENTER OR %BS_VCENTER OR %WS_TABSTOP, %WS_EX_LEFT
CONTROL ADD LABEL, hDlg, %LabelOne, "", 50,63,120, 80
DIALOG SHOW MODAL hDlg CALL DlgProc
END FUNCTION
'______________________________________________________________________________
Wasn't someone asking about a 'digital' clock display earlier this week?
MCM
[This message has been edited by Michael Mattias (edited February 17, 2007).]
I tested the 7 segment and 3D version loading as a file and all works well.
however, when embedded into a resource as done earlier with the alphalcd.ttf file,
the 7 segment will not load, returns "0" ...some more homework.
Also, nice effect is to change the forecolor and backcolors...
CONTROL SET COLOR hDlg, %IDC_LABEL3, %RED, %BLACK
Regards,
Jules
------------------
[This message has been edited by Jules Marchildon (edited February 18, 2007).]
I tricked myself again! The original test I did with embedding it into a resource,..
-> #RESOURCE "truetype.pbr" 'MyFont RCDATAT alphalcd.ttf
...actually yeilded errornous results, ...while playing around with "load from file first", I had
this line in the code -> SendMessage(%HWND_BROADCAST, %WM_FONTCHANGE, 0, 0) ,.. and later
testing loading the .ttf from resource & since I don't turn off or reset my computer that often,
the alphalcd.ttf font continued to reside on my system, and it didn't mater if I loaded from file
or resource, when I created the font, it worked anyway. Well, I'm not always the sharpest tool in the shed!!
Just wanted to corret myself, it didn't work using that particular load from resource method.
But,... Michaels excellent suggestion looks promising. Thanks!
Thanks, Michael & Jules. Now that I know about those API's, I can
start playing around. Thanks for the link to the free "7 Segment"
font, Michael. I've wanted such a font for a long time, and now am at
a time when I will start playing with this stuff.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment