September 20, 2020, 05:06:34 am

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


New Font

Started by aurelCB, April 04, 2010, 07:57:27 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

Hi all..
I try to add external font and i do this sometimes but i lost source code.
So i try on this way but without succses.
What i do wrong ? Any idea?
I use .fnt and try also .fon extension.
I also download small font maker called Fony.

Code Select
'main window app
Def w1:window
Def hfont:uINT
CONST WM_SETFONT = 0x30
CONST DEFAULT_CHARSET = 1
CONST ANSI_CHARSET = 0

Declare "gdi32", CreateFontA(nHeight:INT,nWidth:INT,nEsc:INT,nOri:INT,fnWeight:INT,fnItalic:INT,fnUnderline:INT,fnStrikeOut:INT,fnCharSet:INT,fnOutPrecision:INT,fnClipPrecision:INT,fnQuality:INT,fnPAFamily:INT,fnName:STRING),INT
'Private (nHeight,nWidth,nEscapement,nOrientation,fnWeight,fdwItalic,fdwUnderline,fdwStrikeOut,fdwCharSet,fdwOutputPrecision,fdwClipPrecision,fdwQuality,fdwPitchAndFamily,lpszFace As String) As Long
'open window
Window w1,0,0,500,400,@minbox,0,"MainGUI",main
Setwindowcolor w1,rgb(220,220,220)
'--------------------------------------------------------

hfont = CreateFontA(15,0,0,0,400,0,0,0,1,0,0,0,2,getstartpath+"Dina.fnt")
'CreateFont(_fsize,0,0,0,_ff,_fi,_fu,_fs,1,0,0,0,2,_fname)

'SetFont w1,getstartpath+"Dina.fnt",8,400,0
SendMessage(w1,WM_SETFONT,hfont,1)

Move w1,10,20:Print w1,"Font Test Aurel Small"


CONTROL w1,"RE,,7,35,570,294,0x50B010C4,1"
SendMessage(w1,WM_SETFONT,hfont,1,1)
'+SETCONTROLTEXT w1,1,"Widea"



'---------------------------------------------------------
run=1
waituntil run=0
'stoptimer w1
closewindow w1
end

'-------------------------------------------------------
Sub main
Select @class
Case @idclosewindow
run=0
Case @idcreate
Centerwindow w1
Endselect
Return
forum for hobby programming:<br />https://aurelsoft.ucoz.com

LarryMc

Zlatko

The last parameter, fname, is not the name of a file; it is the name of a font typeface like "Tahoma".

You have to create a font file; register it on your computer; and then the font name will appear on your computer.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

You need first to load the font with AddFontResourceA(path) api from gdi32.dll, then call CreateFont (passing font name instead path).

aurelCB

April 05, 2010, 01:51:23 am #3 Last Edit: April 05, 2010, 02:05:17 am by aurelCB
Oh my...
I forget about AddFontResourceA(fpath:string),INT  ::)
Thanks Sapero.. :)


Code Select
'main window app
Def w1:window
Def hfont:uINT
CONST WM_SETFONT = 0x30
CONST DEFAULT_CHARSET = 1
CONST ANSI_CHARSET = 0

Declare "gdi32", CreateFontA(nHeight:INT,nWidth:INT,nEsc:INT,nOri:INT,fnWeight:INT,fnItalic:INT,fnUnderline:INT,fnStrikeOut:INT,fnCharSet:INT,fnOutPrecision:INT,fnClipPrecision:INT,fnQuality:INT,fnPAFamily:INT,fnName:STRING),INT
Declare "gdi32",AddFontResourceA(fpath:string),INT

Window w1,0,0,500,400,@minbox,0,"MainGUI",main
Setwindowcolor w1,rgb(220,220,220)
'--------------------------------------------------------

AddFontResourceA(getstartpath+"C:\Program Files\Ionic Wind\Creative BASIC\samples\Dina.fon")
hfont = CreateFontA(12,0,0,0,400,0,0,0,1,0,0,0,1,"Dina")

' not work for window
SendMessage(w1,WM_SETFONT,hfont,1)
' this work for window
SetFont w1,"Dina",9,400,0

Move w1,10,20:Print w1,"Font Test Dina 9"

'work for control font
CONTROL w1,"E,,7,65,470,294,0x50B010C4,1"
SendMessage(w1,WM_SETFONT,hfont,1,1)

SetControlText w1,1,"Font Test Dina 9"



'---------------------------------------------------------
run=1
waituntil run=0
'stoptimer w1
closewindow w1
end

'-------------------------------------------------------
Sub main
Select @class
Case @idclosewindow
run=0
Case @idcreate
Centerwindow w1
Endselect
Return
forum for hobby programming:<br />https://aurelsoft.ucoz.com

sapero

Code Select
(getstartpath+"C:\Program Files
Huh? This is a path to alternate data stream (probably still invalid, not supported), not to a normal file ;)

aurelCB

April 05, 2010, 07:16:36 am #5 Last Edit: April 05, 2010, 03:31:26 pm by aurelCB
Dont worry man now works fine :)
Yes Sapero you right:
this is right
Code Select
AddFontResourceA(getstartpath+"Dina.fon")
hfont = CreateFontA(12,0,0,0,400,0,0,0,1,0,0,0,1,"Dina")
forum for hobby programming:<br />https://aurelsoft.ucoz.com