News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

RichEd

Started by ctt, July 21, 2005, 01:22:15 PM

Previous topic - Next topic

ctt

Hello ... i think this is an easy one to solve but i can't and i read all riched posts here and tried google it first.

I want to select a font to use as default font in my riched ... but i can't figure out how to make it work.

Question: How do i select a font to use as default without any font dialogs etc ... i.e. Courier?

Here is little of my code
szFontName        DB  'Terminal', 24 Dup (0)


invoke lstrcpy, ADDR cfm.szFaceName, ADDR szFontName
invoke SendMessage,hwndRichEdit,EM_SETCHARFORMAT,SCF_ALL,addr cfm


:(

hutch--

ctt,

If its only a single font for the entire editor, its really simple, use WM_SETFONT using either a GetStockObject() system font or alternatively CreateFont() and use that handle.

PS: GREAT doggie avatar.  :U
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ctt

Great doggie great pictures you know  :U

Thanks for the quick responce. But I can't get it to work .. i've tried createfont and wm_settext .. nothing work .. i can't get it to display the thing in my font. And yes i do set the font BEFORE i stream the data ... is this wrong?

Does anyone have an example how i can do?

hutch--

Trick is to get a valid font handle, either from GetStockObject() or CreateFont() and then use


invoke SendMessage,hEdit,WM_SETFONT,hFont,TRUE


Make sure the font handle is valid by testing its return value and that you use the handle for the rich edit control and it should work OK.

If you ae still having a problem with it, let us know and show us the code that creates the rich edit control and what styles it is set to.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Mark Jones

This works for a regular edit box, unsure about riched:


.data
    CourierNew      LOGFONT <-11,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,\
                    OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,\
                    49,"Courier New">
.code
    invoke CreateFontIndirect,offset CourierNew
    mov [hFont],eax
    invoke SendDlgItemMessage,hWnd,IDC_EDT1,WM_SETFONT,[hFont],TRUE
; rest of code
    invoke DeleteObject,hFont
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

ctt

Okey! Getting somewhere .. a little mix of this and a little mix of this the font now starting to look a little diffrent :) Diffrent but not nice, let say i wanna look at a ASCII-picture which often looks good in "Terminal 9px" it doesn't look right at all, i used FIXED_PITCH and everything, i can't figure out whats wrong.

It looks like i use the wrong keymapping...

Okey look a bit deeper into this and it's Courier New and not Terminal?

Whats wrong with this:

.data
szLogFont           LOGFONT <-11,0,0,0,0,0,0,0,ANSI_CHARSET,\
                    OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,\
                    FIXED_PITCH,"Terminal">
...
.code
    invoke CreateFontIndirect,offset szLogFont
    mov [hFont],eax
invoke SendMessage,hwndRichEdit,WM_SETFONT,eax,TRUE



The richedit control is cut'n'pasted of iczels tutor 33 or 34 i think .. nothing changed more than i removed the menu.
Very very odd indeed  :eek


PBrennick

ctt,
First of all, -11 is 8pt., if that is too small try -13 for 10pt.

Also, try changing the fourth 0 to 400, 400 means normal, 700 means bold, etc.

so you would have


szLogFont           LOGFONT <-13,0,0,0,400,0,0,0,ANSI_CHARSET,\
                    OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,\
                    FIXED_PITCH,"Terminal">


I did not try the other settings but those 2 are the ones I always use.  BTW:  Mark used FW_NORMAL to achieve the same effect as 400.  Other values are:

FW_DONTCARE   equ 0
FW_THIN       equ 100
FW_EXTRALIGHT equ 200
FW_LIGHT      equ 300
FW_NORMAL     equ 400
FW_MEDIUM     equ 500
FW_SEMIBOLD   equ 600
FW_BOLD       equ 700
FW_EXTRABOLD  equ 800
FW_HEAVY      equ 900
FW_ULTRALIGHT equ FW_EXTRALIGHT
FW_REGULAR    equ FW_NORMAL
FW_DEMIBOLD   equ FW_SEMIBOLD
FW_ULTRABOLD  equ FW_EXTRABOLD
FW_BLACK      equ FW_HEAVY


Paul
The GeneSys Project is available from:
The Repository or My crappy website

ctt

Thanks for the quick reply Paul  :U

Still no luck tho.... if i use ANSI_CHARSET and Terminal as fontfamily it's Courier New when i stream the text into the riched control. :(

OEM_CHARSET looks more like Terminal but is still not right ...

This should be the easiest thing in the world i thought ... guess i was way wrong :D

No one that got a source for a nfo-viewer or something ... ? That should work for my needs aswell, nfo's are often full och ascii-pics and such looking good in Terminal.

Thanks for all answers to this question .. really friendly and helpingly atmosphear here  :thumbu

PBrennick

Always remember that windows will work around your errors by using font substitition.  If you are not getting what you think you should get, look at your code.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

ctt

I get no error codes at all :(
I'll try some other tricks i learned yesterday ... see if those work .. i will get back when i solve this matter or if not. ;)

hutch--

ctt,

Have a play with this, its a late example with a small editor tha uses a rich edit control. A lot of the richedit stuff is already canned in the MASM32 library and this is what its using. It also uses a number of the macros built into MASM32 but its simple enough to read.

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ctt

Thanks for the example code hutch, still got the same shit tho.

I've came up with this by reading msdn:

Fonts are identified by typeface names. The raster fonts have typeface names of
System (used for SYSTEM_FONT)
FixedSys (used for SYSTEM_FIXED_FONT)
Terminal (used for OEM_FIXED_FONT)
MS Sans Serif (used for DEFAULT_GUI_FONT)


These are the Windows built-in fonts ... it's OEM_FIXED_FONT i wanna use.
Now i figured out this as well; if i invoke GetOEMCP i get the result 850 MS-DOS Multilingual (Latin I) which is right for my swedish os. But i want it to be 437, so i thought of a SetOEMCP, but there is non! How do i change the codepage momentarily for the riched font?

hutch--

ctt,

Do you know for sure that your version of Windows has the correct font ?
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ctt

Yeap, i use it in notepad. So it should or?

hutch--

ctt,

Will you grab the later editor off my homesite called TopGun as it has to option to set the default font to "Terminal". It is done with an accessory called tgset.exe that patches the binary file with the corect data. If this works, we can go from there.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php