I am new to MASM32, in my coding, i try to change the font face and also the size as well in my application under Win98, and it works well :grin: , but when i run it under WinXP, it come out in scripting text with size very small :( . My question is, am i have to change my code ? XP seems cant display my ASCII well too :( Arent the code in win9x and XP both the same ? :confused:

Any help, comment, idea is appreciate, thanks.
Posted on 2003-05-30 08:33:33 by Gerlt
Hi,

the code remains the same but in my opinion there it's all the registry problem....... i suggest you to see the msdn for the various api and parameters....

regards
/
Posted on 2003-05-30 08:47:50 by processingspeed
You didn't post your algo for calculating font size so I'll post one just in case you need it. This will result in an accurate font size for the LOGFONT structure
invoke GetDC,hWin

mov TARGETDC,eax
invoke GetDeviceCaps,TARGETDC,LOGPIXELSY
mul FSIZE
mov ecx,72
div ecx
neg eax

mov FontStruct.lfHeight,eax
mov FontStruct.lfWidth,0
hWin is the handle of the control where the font will be placed, this method will yeild the correct result even for displays with other than 96dpi screens. FSIZE is the point size of your font eg 10pt = 10, and FontStruct is a LOGFONT structure that is used to create the font handle. Be sure to close the TARGETDC handle when your done.
Posted on 2003-05-30 10:44:00 by donkey
Wow !! This is fast !! :)

processingspeed:
Will check the API function and parameters. thx.

donkey :
The code is cool. Will give it a try very soon. And, seems that I need sometime to have a close look at it first. heheh ... ...

Here is my code :




.DATA
FontName db "Arial",0

.CODE
LOCAL hdc:HDC
LOCAL ps:PAINTSTRUCT
LOCAL hfont:HFONT

invoke BeginPaint,hWnd, addr ps
mov hdc,eax
invoke CreateFont,16,0,0,0,500,0,0,0,OEM_CHARSET,\
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,\
addr FontName
invoke SelectObject,hdc,eax
invoke TextOut,hdc,15,15,addr Text,SIZEOF Text-1
invoke SelectObject,hdc,hfont
invoke EndPaint,hWnd, addr ps

Is this ok ?
Posted on 2003-05-30 12:48:30 by Gerlt
The CreateFont API takes em units not points as it's size parameter. The method you are using may give you different results on different platforms. I use the following algorithm to create a font, it is much more reliable...
LOCAL lf :LOGFONT

LOCAL hDC :HANDLE
LOCAL hFont :HANDLE

invoke GetDC,hWin
mov hDC,eax

invoke GetDeviceCaps,hDC,LOGPIXELSY
mul DlgXTemplate.pointsize
mov ecx,72
mov edx,0
div ecx
neg eax

mov lf.lfHeight,eax
mov lf.lfWidth,0
mov lf.lfEscapement,0
mov lf.lfOrientation,0
mov lf.lfWeight,FW_NORMAL
mov lf.lfItalic,FALSE
mov lf.lfUnderline,FALSE
mov lf.lfStrikeOut,FALSE
mov lf.lfCharSet,DEFAULT_CHARSET
mov lf.lfOutPrecision,OUT_DEFAULT_PRECIS
mov lf.lfClipPrecision,CLIP_DEFAULT_PRECIS
mov lf.lfQuality,DEFAULT_QUALITY

invoke lstrcpy,ADDR lf.lfFaceName,pszfontname
invoke CreateFontIndirect,ADDR lf
mov hFont,eax
invoke ReleaseDC,hWin,hDC
It's always worked well for me.
Posted on 2003-05-30 13:49:11 by donkey
:grin: :grin:

Look like I have to change my title subject to <using font> :o

Btw, I have one more question regarding this topic .. : In C, i use puts("my text here"); and using \n to insert a new line, 0A and 0D in assembly, .. in MASM32, i use a coordinate for each line as follow :



Text1 db "1st line",0
Text2 db "2nd line",0
Text3 db "3rd line",0

invoke TextOut,hdc,15,15,ADDR Text1,SIZEOF Text1-1
invoke TextOut,hdc,15,30,ADDR Text2,SIZEOF Text2-1
invoke TextOut,hdc,15,45,ADDR Text3,SIZEOF Text3-1


And my question is, is there any other way in doing this ? Where can I get a tutorial for it ? or which API works better ? Can I insert direct sting with a variable like printf("the number is %d", number1);

Again .. thanks !!
Posted on 2003-05-30 23:10:38 by Gerlt
Yes, the wsprintf instruction is available as part of the API.
Posted on 2003-05-30 23:17:08 by donkey
thx .. this is Great .. and makes me feel at home :)
Posted on 2003-05-31 07:47:42 by Gerlt