flat assembler
Message board for the users of flat assembler.

Index > Windows > RichEdit Problems

Author
Thread Post new topic Reply to topic
DuXeN0N



Joined: 05 May 2009
Posts: 6
DuXeN0N 09 May 2009, 04:42
I tried to make my notepad with RichEdit control but I have found a problem with selecting font. I have made FontDialog but it's return value is LOGFONT struct. How can I translate LOGFONT to CHARFORMAT?

PS: I declared CHARFORMAT on my own:

struct CHARFORMAT
cbSize dd ?
dwMask dd ?
dwEffects dd ?
yHeight dd ?
yOffset dd ?
crTextColor dd ?
bCharSet db ?
bPitchAndFamily db ?
szFaceName db 32 dup(?)
_wPad2 dd ?
ends
Post 09 May 2009, 04:42
View user's profile Send private message ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 09 May 2009, 11:11
I presume you could copy each of the related members from LOGFONT into the CHARFORMAT structure?

A quick glance shows me:

lfFaceName <=> szFaceName
lfCharSet <=> bCharSet
lfHeight <=> yHeight
etc.
Post 09 May 2009, 11:11
View user's profile Send private message Visit poster's website Reply with quote
DuXeN0N



Joined: 05 May 2009
Posts: 6
DuXeN0N 09 May 2009, 11:33
revolution wrote:
I presume you could copy each of the related members from LOGFONT into the CHARFORMAT structure?

A quick glance shows me:

lfFaceName <=> szFaceName
lfCharSet <=> bCharSet
lfHeight <=> yHeight
etc.

How can I do this? I am beginner)
Post 09 May 2009, 11:33
View user's profile Send private message ICQ Number Reply with quote
pal



Joined: 26 Aug 2008
Posts: 227
pal 09 May 2009, 12:20
mov eax, value in logfont
mov value in logfont, eax

e.g.

Code:
mov eax,lfFaceName
mov szFaceName,eax
    
Post 09 May 2009, 12:20
View user's profile Send private message Reply with quote
DuXeN0N



Joined: 05 May 2009
Posts: 6
DuXeN0N 09 May 2009, 12:40
okey. and the last question, how can I change font in EDIT from LOGFONT? What struct should I use for EDIT?
Post 09 May 2009, 12:40
View user's profile Send private message ICQ Number Reply with quote
DuXeN0N



Joined: 05 May 2009
Posts: 6
DuXeN0N 10 May 2009, 02:13
I tried to copy each of the related members from LOGFONT into the CHARFORMAT but an error occured:

operand sizes do not match.

code:

invoke ChooseFont,cf
mov [lf],eax

mov [chf.cbSize],sizeof.CHARFORMAT

mov eax,lf.lfHeight
mov [chf.yHeight],eax

mov eax,lf.lfFaceName
mov [chf.szFaceName],eax



invoke SendMessage,[hRichEdit],EM_SETCHARFORMAT,SCF_SELECTION,0
jmp .finish

and one question.

how can I copy

BYTE lfItalic;
BYTE lfUnderline;
BYTE lfStrikeOut;

to CHARFORMAT

DWORD dwEffects;
Post 10 May 2009, 02:13
View user's profile Send private message ICQ Number Reply with quote
pal



Joined: 26 Aug 2008
Posts: 227
pal 10 May 2009, 08:36
Try something like (not tested as I aint making a RTB):

Code:
           mov             [cf.lStructSize],sizeof.CHOOSEFONT
          mov             [cf.Flags],CF_INITTOLOGFONTSTRUCT
           mov             [cf.lpLogFont],lf
           invoke  ChooseFont,cf
               test    eax,eax
             je              codeEnd
             
            mov     eax,[lf.lfHeight]
           mov             [chf.yHeight],eax
           mov     eax,[lf.lfFaceName]
         mov             [chf.szFaceName],eax
                mov             [chf.dwEffects],
            
            invoke  SendMessage,[hRichEdit],EM_SETCHARFORMAT,SCF_SETSELECTION,chf
               
    codeEnd:
                ret     


Your code is completely wrong. ChooseFront doesn't return a structure. You pass a pointer to a structure and it fills the items. If you set the flags to CF_INITTOLOGFONTSTRUCT and lpLogFont is a pointer to an initalised LOGFONT structure, it will fill that for you.

For the dwEffects, just check the value of each of the members of LOGFONT, and if they are set then or the corresponding value with the CHARFORMAT (CFE_BOLD, CFE_ITALIC, CFE_UNDERLINE etc.).
Post 10 May 2009, 08:36
View user's profile Send private message Reply with quote
DuXeN0N



Joined: 05 May 2009
Posts: 6
DuXeN0N 10 May 2009, 08:59
pal wrote:
Try something like (not tested as I aint making a RTB):

Code:
           mov             [cf.lStructSize],sizeof.CHOOSEFONT
          mov             [cf.Flags],CF_INITTOLOGFONTSTRUCT
           mov             [cf.lpLogFont],lf
           invoke  ChooseFont,cf
               test    eax,eax
             je              codeEnd
             
            mov     eax,[lf.lfHeight]
           mov             [chf.yHeight],eax
           mov     eax,[lf.lfFaceName]
         mov             [chf.szFaceName],eax
                mov             [chf.dwEffects],
            
            invoke  SendMessage,[hRichEdit],EM_SETCHARFORMAT,SCF_SETSELECTION,chf
               
    codeEnd:
                ret     


Your code is completely wrong. ChooseFront doesn't return a structure. You pass a pointer to a structure and it fills the items. If you set the flags to CF_INITTOLOGFONTSTRUCT and lpLogFont is a pointer to an initalised LOGFONT structure, it will fill that for you.

For the dwEffects, just check the value of each of the members of LOGFONT, and if they are set then or the corresponding value with the CHARFORMAT (CFE_BOLD, CFE_ITALIC, CFE_UNDERLINE etc.).


mov eax,[lf.lfFaceName]

operand sizes do not match
Post 10 May 2009, 08:59
View user's profile Send private message ICQ Number Reply with quote
pal



Joined: 26 Aug 2008
Posts: 227
pal 10 May 2009, 09:43
Move it to ax or use movzx then.
Post 10 May 2009, 09:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 10 May 2009, 09:46
lfFaceName is a pointer to a string. You need to copy all of the bytes. That is, you need multiple mov instructions to do it (or maybe rep movs).
Post 10 May 2009, 09:46
View user's profile Send private message Visit poster's website Reply with quote
pal



Joined: 26 Aug 2008
Posts: 227
pal 10 May 2009, 12:42
Oops yeah, my bad. I aint gonna update my code as its pretty easy to do.
Post 10 May 2009, 12:42
View user's profile Send private message Reply with quote
DuXeN0N



Joined: 05 May 2009
Posts: 6
DuXeN0N 11 May 2009, 04:51
can Tomasz Grysztar give me example of RichEdit with ChoseFont Dialog?
Post 11 May 2009, 04:51
View user's profile Send private message ICQ Number Reply with quote
habran



Joined: 31 Aug 2008
Posts: 82
Location: South Australia
habran 11 May 2009, 12:21
Hi DuXeN0N,

You can find all you need for RichEditor here:
http://board.flatassembler.net/topic.php?t=9144
You can find ChooseFont in FormatFonts.asm file

happy fasming

_________________
down under
Post 11 May 2009, 12:21
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.