Author Topic: EM_SETCHARFORMAT no working.  (Read 583 times)

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
EM_SETCHARFORMAT no working.
« on: October 18, 2021, 05:34:45 AM »
    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:
Code: [Select]
            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

  • Member
  • *****
  • Posts: 11783
  • Assembler is fun ;-)
    • MasmBasic
Re: EM_SETCHARFORMAT no working.
« Reply #1 on: October 18, 2021, 08:43:50 AM »
"sets character formatting in a rich edit control"

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: EM_SETCHARFORMAT no working.
« Reply #2 on: October 18, 2021, 04:36:50 PM »
    It's a richedit 5.0 control. why is it not working? 

jj2007

  • Member
  • *****
  • Posts: 11783
  • Assembler is fun ;-)
    • MasmBasic
Re: EM_SETCHARFORMAT no working.
« Reply #3 on: October 18, 2021, 07:57:45 PM »
    Hey guys. I'm using EM_SETCHARFORMAT to change the font of the Edit Control

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: EM_SETCHARFORMAT no working.
« Reply #4 on: October 18, 2021, 08:27:36 PM »
   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

  • Member
  • *****
  • Posts: 11783
  • Assembler is fun ;-)
    • MasmBasic
Re: EM_SETCHARFORMAT no working.
« Reply #5 on: October 19, 2021, 01:12:20 AM »
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

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: EM_SETCHARFORMAT no working.
« Reply #6 on: October 19, 2021, 06:09:38 AM »
    it's in the mdichildproc. search for if ax==IDM_CHOOSEFONT. Thanks

jj2007

  • Member
  • *****
  • Posts: 11783
  • Assembler is fun ;-)
    • MasmBasic
Re: EM_SETCHARFORMAT no working.
« Reply #7 on: October 19, 2021, 08:22:40 AM »
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:
Code: [Select]
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:

Code: [Select]
.\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:
Code: [Select]
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--

  • Administrator
  • Member
  • ******
  • Posts: 8741
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: EM_SETCHARFORMAT no working.
« Reply #8 on: October 19, 2021, 09:04:19 AM »
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

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: EM_SETCHARFORMAT no working.
« Reply #9 on: October 19, 2021, 09:58:43 AM »
    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--

  • Administrator
  • Member
  • ******
  • Posts: 8741
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: EM_SETCHARFORMAT no working.
« Reply #10 on: October 19, 2021, 10:17:23 AM »
There is nothing to apologise for here, we all take shortcuts where we can.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: EM_SETCHARFORMAT no working.
« Reply #11 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'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
« Last Edit: October 19, 2021, 09:19:17 PM by xandaz »

jj2007

  • Member
  • *****
  • Posts: 11783
  • Assembler is fun ;-)
    • MasmBasic
Re: EM_SETCHARFORMAT no working.
« Reply #12 on: October 19, 2021, 10:08:15 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

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: EM_SETCHARFORMAT no working.
« Reply #13 on: October 19, 2021, 10:19:05 PM »
   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

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: EM_SETCHARFORMAT no working.
« Reply #14 on: October 19, 2021, 10:51:56 PM »
    I got this code that is present in the help file but the fonts are still too small!
Code: [Select]
           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:
Code: [Select]
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.