I know there is a demo of doing that here somewhere. Something to do with 7-segment LED fonts. If you can't find it let me know, because I know I did it and have it here.. somewhere.
I found it pretty quick (thank you Ultra-Edit "Find in Files")
What I could not find was a way to find the font face name given only the file name. I also see you DO need to "Create Font", but you can only do that AFTER you AddFontResource.
Let's look in the SDK for something which might tell us the face name(s?) of fonts in a file...no luck.
I guess 'maybe' you could enum all the type faces before, then AddFontResource(), then enum again to know what faces were added by the AddFontResource, but I really don't like the sound of that for some reason.
MCM
' While_button_down.bas
' Little example using WM_SETCURSOR message and a timer...
'Pierre
'
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, 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) 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, FORMAT$(TimerCount, "Count 00\:00\:00") 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", , , 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 '______________________________________________________________________________ '
Leave a comment: