Userlib, set text area font. Without blitzes font system.. need help..

BlitzPlus Forums/BlitzPlus Programming/Userlib, set text area font. Without blitzes font system.. need help..

skn3(Posted 2004) [#1]
I am trying to make a function, to set a textarea's font, without using blitz's built-in font system.

Anyone who is more experienced with userlibs n stuff, check below and see what you think. What am I doing wrong ?

;Userlib
;.lib "user32.dll"
;SendMessageBank%(hwnd,msg,wParam,mPAram*):"SendMessageA"

;Code
Global window = CreateWindow("window",400,300,600,300,0,1)
Global logs   = CreateTextArea(0,0,ClientWidth(window),ClientHeight(window),window,0)

Notify Api_SetTextAreaFont(logs,"Blitz")

SetTextAreaText(logs,"aaa"+Chr(10)+"MMM")
WaitEvent()

Function Api_SetTextAreaFont(textarea,name$)
	;change the font of a test area, without using blitz's...
	;..crap font system.
	;
	;Meaning, fonts that dont work with the blitz font system, can now be used in textareas.
	
	;Create blitz struct
	bank = CreateBank(4+4+4+4+4+4+1+1+Len(name$)+1)
	;cbSize
	PokeInt ( bank,  0,  BankSize(bank))
	;dwMask
	PokeInt ( bank,  4,  256 )
	;dwEffects
	PokeInt ( bank,  8,    0 )
	;yHeight
	PokeInt ( bank, 12,   12 )
	;yOffset
	PokeInt ( bank, 16,   12 )
	;crTextColor
	PokeInt ( bank, 20,    0 )
	;bCharSet
	PokeByte( bank, 24,    1 )
	;bPitchAndFamily
	PokeByte( bank, 25,    0 Or 4 )
	;szFaceName
	For i=1 To Len(name$)
		PokeByte(bank,25+i,Asc(Mid$(name$,i,1)))
	Next
	PokeByte(bank,26+Len(names$),0)
	Return SendMessageBank(QueryObject(textarea,1),1024+68,4,bank)
End Function


Btw, there is already a way of loading any font into blitz, but its not ideal.

Try
settextareafont(textarea,requestfont())

This will allow you to pick any font, and it will load absolutly fine, into blitz's textarea gadget. As I said, this is far from helpfull when taken from a programemrs point of view.


soja(Posted 2004) [#2]
skn3,

I'm not sure what message 0x444 (1024+68) refers to. I couldn't find it, and consequently I couldn't look up lparam or wparam.

But... what's wrong with something like this?
;.lib "user32.dll"
;SendMessageBank2%(hwnd,msg,wParam,lParam):"SendMessageA"

Const WM_SETFONT = 48

Global fntWing = LoadFont("Wingdings", 24)
Global fntArial = LoadFont("Arial", 12)
Global wndMain = CreateWindow("SetFont Example", 400, 300, 600, 300, 0, 1)
Global tarMain = CreateTextArea(0,0,ClientWidth(wndMain),ClientHeight(wndMain),wndMain,0)

SetTextAreaText(tarMain, "Testing..." + Chr(10) + "Testing again...")
Api_SetTextAreaFont(tarMain, fntWing)
Delay 1000
Api_SetTextAreaFont(tarMain, fntArial)

While WaitEvent() <> $803 : Wend

Function Api_SetTextAreaFont(textarea, fnt)
	Return SendMessageBank2(QueryObject(textarea,1), WM_SETFONT, QueryObject(fnt,3), 0)
End Function

(Look up "WM_SETFONT" in the Windows User Interface: Platform SDK docs of MSDN.)


skn3(Posted 2004) [#3]
Thanks I will look that up.

This is where i was looking at for reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditmessages/em_setcharformat.asp

And the 1024 + 68 I got from the rich edit header file.
#define EM_SETCHARFORMAT (WM_USER + 68)

WM_USER is
#define WM_USER 0x0400



Blitz already has a function to set the font of a textarea. That was not the problem. The problem is, blitz is incapable of loading certain fonts into its font system.

Try "Roman", "Modern" or "Script" Non of these fonts work (these are all .fon).

What is strange, is that the only .fon font I can get to work using the built in font system, is blitz.fon

That is why I need, and want to bypass blitz's font system for changing a textareas font.


soja(Posted 2004) [#4]
Hmm, I see.

Perhaps a GDI function like CreateFont or AddFontResource??


skn3(Posted 2004) [#5]
Well its handled in the richedit dll .. so no need really...

At least I think it is, judging from what I read on the msdn site. I guess I am doing it wrong but the function described; allows you to set the default font of a rich edit control, using just the fontface's name...

Hm


soja(Posted 2004) [#6]
I've been fiddling with it for a while and am not having any luck either... I did notice a few things, though (which you may want to take with a grain of salt).

1) for dwMask, you may wish to use $ffffffff in order to allow any possible option from the other parameters
2) You'll want to multiple yHeight by 12 (240) because you're specifying the # of twips, (=points/20)
3) You should have 0 for yOffset because you don't want superscript or subscript.
4) for bPitchAdnFamily, "0 Or 4" os the same as "4", and doesn't do what you're expecting, I think. What you want is just plain 0, which indicates FF_DONTCARE and DEFAULT_PITCH.
5) You don't need the additional pokebyte "0" at the end (or any of the others that poke 0, I guess) because the bank is initialized with zeroes.

Beyond that, I kept getting a failure return value...


skn3(Posted 2004) [#7]
Great tips.. I'll give em a whurl in a bit. Btw that grain of salt tasted nice on my lunch...

A mate suggested that i try using the loadfont api in windows.. and then handle the resource from in blitz.. just without the blitz font system.

I'll try that also a bit later.. then post the results here.


skn3(Posted 2004) [#8]
wohoo got it all working :)

http://www.blitzbasic.com/Community/posts.php?topic=29143

thanks for the tips