News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

EM_SETCHARFORMAT no working.

Started by xandaz, October 18, 2021, 05:34:45 AM

Previous topic - Next topic

xandaz

    Hey guys. I'm using EM_SETCHARFORMAT to change the font of the Edit Control but it's not working. i Have this line of code:            mov     chFont.lStructSize,sizeof CHOOSEFONT
            mov     chFont.lpLogFont,offset LogFont
            invoke  ChooseFont,addr chFont
            invoke  CopyBuffer,addr LogFont.lfFaceName,addr chFormat.CHARFORMAT2.szFaceName
            invoke  MessageBox,0,addr LogFont.lfFaceName,addr chFormat.CHARFORMAT2.szFaceName,MB_OK
            mov     chFormat.cbSize,sizeof CHARFORMAT2
            push    LogFont.lfWeight
            pop     chFormat.wWeight
            mov     chFormat.dwMask,CFM_FACE
            mov     chFormat.crTextColor,0ffh
            invoke  SendMessage,hMdi,WM_MDIGETACTIVE,0,0
            invoke  GetWindowLong,eax,GWL_USERDATA
            invoke  SendMessage,[eax.MdiStruct.hEdit],EM_SETCHARFORMAT,SCF_ALL,addr chFormat

    Thanks in advance.

jj2007

"sets character formatting in a rich edit control"

xandaz

    It's a richedit 5.0 control. why is it not working? 

jj2007

Quote from: xandaz on October 18, 2021, 05:34:45 AM
    Hey guys. I'm using EM_SETCHARFORMAT to change the font of the Edit Control

xandaz

   ha ha ha. You're very funny JJ. Still, can you see anything wrong with the code. Isn't that the way to change fonts and colors of richedit control?
ty

jj2007

If you post a complete example, I might look at it. Some code out of context? No thanks. Besides, you should make an effort to test the return value and get error message.

xandaz

    it's in the mdichildproc. search for if ax==IDM_CHOOSEFONT. Thanks

jj2007

Too much work for me. You are using a non-standard setup, maybe you modified some include files, and I am not willing to solve the mysteries...

The problem starts with your assumption that include files have to sit on drive C:
include c:\masm32\include\masm32rt.inc
include c:\masm32\include\winclasses.asm


The correct syntax is include \masm32\include\masm32rt.inc, i.e. no drive letter.
When I include your winclasses.asm file (not in the archive, but I have it from your earlier posts), I still get loads of errors, related to chFormat:

.\mdi.asm(280) : Error A2167: Missing quotation mark in string
.\mdi.asm(280): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(280) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(280): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(281) : Error A2167: Missing quotation mark in string
.\mdi.asm(281): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(281) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(281): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(282) : Error A2167: Missing quotation mark in string
.\mdi.asm(282): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(282) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(282): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(283) : Error A2167: Missing quotation mark in string
.\mdi.asm(283): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(283) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(283): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(284) : Error A2167: Missing quotation mark in string
.\mdi.asm(284): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(284) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(284): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(285) : Error A2167: Missing quotation mark in string
.\mdi.asm(285): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(285) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(285): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(286) : Error A2167: Missing quotation mark in string
.\mdi.asm(286): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(286) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(286): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(287) : Error A2167: Missing quotation mark in string
.\mdi.asm(287): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(287) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(287): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(288) : Error A2167: Missing quotation mark in string
.\mdi.asm(288): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(288) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(288): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(289) : Error A2167: Missing quotation mark in string
.\mdi.asm(289): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(289) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(289): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(290) : Error A2167: Missing quotation mark in string
.\mdi.asm(290): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(290) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(290): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(291) : Error A2167: Missing quotation mark in string
.\mdi.asm(291): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(291) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(291): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(292) : Error A2167: Missing quotation mark in string
.\mdi.asm(292): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(292) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(292): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(293) : Error A2167: Missing quotation mark in string
.\mdi.asm(293): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(293) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(293): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(294) : Error A2167: Missing quotation mark in string
.\mdi.asm(294): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(294) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(294): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(295) : Error A2167: Missing quotation mark in string
.\mdi.asm(295): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(295) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(295): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(296) : Error A2167: Missing quotation mark in string
.\mdi.asm(296): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(296) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(296): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(297) : Error A2167: Missing quotation mark in string
.\mdi.asm(297): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(297) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(297): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(298) : Error A2167: Missing quotation mark in string
.\mdi.asm(298): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(298) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(298): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(299) : Error A2167: Missing quotation mark in string
.\mdi.asm(299): Included by
  Tmp_File.asm(5): Main line code
.\mdi.asm(299) : Error A2233: Invalid data initializer: dwMask
.\mdi.asm(299): Included by
  Tmp_File.asm(5): Main line code
Tmp_File.asm: 352 lines, 1 passes, 144 ms, 0 warnings, 40 errors
*** Assembly error ***


This line is horrible, but it's not the reason for your problem:
mov     chFormat.dwMask,CFM_FACE+CFM_WEIGHT+CFM_COLOR+CFM_SIZE

By sheer accident, there are no overlapping bits. How many times did we discuss in this forum that bitmasks must be constructed with the or operator, not with +?

And of course, not a single check for errors, not a single display of return values. Why bother if members of this forum can do it for you?

hutch--

I don't have an example in 32 bit MASM but I have it in 32 bit PowerBASIC. Should be easy enough to translate.


    SendMessage hEdit,%EM_SETBKGNDCOLOR,0,&H00333333
    set_text_colour hEdit,&H00FFFFFF


' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

FUNCTION set_text_colour( _
                          ByVal edit   as DWORD, _
                          ByVal rgbcol as DWORD _
                        ) as DWORD

    LOCAL cfm as CHARFORMAT

    cfm.cbSize          = SIZEOF(cfm)
    cfm.dwMask          = %CFM_COLOR
    cfm.dwEffects       = 0
    cfm.yHeight         = 0
    cfm.yOffset         = 0
    cfm.crTextColor     = rgbcol
    cfm.bCharSet        = 0
    cfm.bPitchAndFamily = 0
    cfm.szFaceName      = "  "
    cfm.wFiller         = 0

    SendMessage edit,%EM_SETCHARFORMAT,%SCF_ALL,VarPtr(cfm)

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

xandaz

    Sorry JJ. I'm thansfule for the help. i forgot that the winclasses.asm wasn't included. I wasn't trying to take any advantage from any forum member. Sorry for the trouble. TY

hutch--

There is nothing to apologise for here, we all take shortcuts where we can.

xandaz

#11
     Well Hutch. I got it to work thanks to your eaxmple. I was using CHARFORMAT2 and turned it to CHARFORMAT and thigs started working. I'm having some trouble with the font size. CHOOSEFONT.logfont has a parameter lfHeight that i'm not sure works with CHARFORMAT yHeight.  The font size is too small. I'm also not sure that EM_SETCHARFORMAT is aware that one is using CHARFORMAT2. Is there a way to convert lfHeight into pixel units. I have to multiply it by 20 to be able to see some chars. Thanks JJ and Hutch

jj2007

Quote from: xandaz on October 19, 2021, 07:47:17 PM
     Well Hutch. I got it to work thanks to your eaxmple. I was using CHARFORMAT2 and turned it to CHARFORMAT and thigs started working.

I've counted 31 hits for CHARFORMAT2 in my RichMasm source, they all work perfectly.

Two problems:
- Your source doesn't assemble on my machine, even with WinClasses.asm included. Since many thousands of other sources assemble perfectly, the reason must be a modification of your Masm32 SDK.
- Your habit of adding flags together, as in
  mov chFormat.dwMask,CFM_FACE+CFM_WEIGHT+CFM_COLOR+CFM_SIZE
  This will sooner or later bite you. Most Windows flags are well-behaved, but some are not. Use OR, not +.

xandaz

   yeah. you re right JJ. I usually forget to use OR. Can you tell me why the lfHeight member of LOGFONT doesn,t return in pixels? How to work around
that? ty

xandaz

    I got this code that is present in the help file but the fonts are still too small!           invoke  GetDeviceCaps,chFont.hDC,LOGPIXELSY
            mov     ebx,chFont.iPointSize;           
            xor     edx,edx
            mul     ebx
            mov     ebx,72
            xor     edx,edx
            div     ebx
            mov     chFormat.yHeight,eax

   The original code is:lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
 

   I must be doing something wrong. The font sizes don't match the ones in ChooseFont Common Dialog.