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

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: EM_SETCHARFORMAT no working.
« Reply #15 on: October 19, 2021, 10:55:34 PM »
    It seems to be working after all. Thanks!

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: EM_SETCHARFORMAT no working.
« Reply #16 on: October 19, 2021, 11:19:10 PM »
    And btw JJ. I'm using the MASM32 SDK exactly as it came only with the addtion of the winclasses file.

jj2007

  • Member
  • *****
  • Posts: 11768
  • Assembler is fun ;-)
    • MasmBasic
Re: EM_SETCHARFORMAT no working.
« Reply #17 on: October 20, 2021, 02:33:56 AM »
    And btw JJ. I'm using the MASM32 SDK exactly as it came only with the addtion of the winclasses file.

Right, the Masm32 SDK is not the culprit. Line 278 of mdi.asm:
Code: [Select]
MdiStruct   STRUCT

hMdi            HWND     ?
hToolbar        HWND     ?
wIDToolbar      dd       ?
hIml            dd       ?
hEdit           HWND     ?
hMenu           HWND ?
hFile           dd       ?
hStatic         HWND ?
szFile          dw       1024 dup(0)
lpTextBuffer    dd       ?
cf              CHARFORMAT  <sizeof CHARFORMAT,<>>  ; <<<<<<<<<<<<<<<<<<<<< ????

MdiStruct   ENDS

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: EM_SETCHARFORMAT no working.
« Reply #18 on: October 20, 2021, 03:56:58 AM »
   Is it wrongly initialized? I thought worked. The first member of Struct being it's own size: chSTRUCT CHARFORMAT  <sizeof CHARFORMAT,<other uninitialized members>. Anyway i don't see a real problem there. The problem is the Font dimension. That's what i was looking to get help for. Thanks

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: EM_SETCHARFORMAT no working.
« Reply #19 on: October 26, 2021, 01:58:49 AM »
    Hey guys. Having a hard time to get CHARFORMAT2 to work. Help is appreciated
Code: [Select]
            invoke  ClearMemory,esi,sizeof CHARFORMAT2
            push    hInstance
            pop     chFont.hInstance
            invoke  SendMessage,hMdi,WM_MDIGETACTIVE,0,0
            mov     chFont.hwndOwner,eax
            invoke  GetDC,[edi].hEdit
            mov     chFont.hDC,eax
            mov     [esi].cbSize,sizeof CHARFORMAT2
            mov     chFont.lStructSize,sizeof CHOOSEFONT
            mov     chFont.lpLogFont,offset LogFont
            mov     chFont.nFontType,SCREEN_FONTTYPE
            invoke  ChooseFont,addr chFont
            invoke  ReleaseDC,[edi].hEdit,chFont.hDC
            invoke  GetDeviceCaps,chFont.hDC,LOGPIXELSY
            mov     ebx,chFont.iPointSize;           
            xor     edx,edx
            mul     ebx
            mov     ebx,72
            xor     edx,edx
            div     ebx
            mov     [esi].yHeight,eax
            push    LogFont.lfWeight
            pop     [esi].wWeight
            mov     [esi].dwMask,CFM_FACE OR CFM_SIZE or CFM_WEIGHT or CFM_SIZE
            mov     [esi].bPitchAndFamily,al
            mov     [esi].bCharSet,ANSI_CHARSET
            invoke  CopyBuffer,addr LogFont.lfFaceName,addr [esi].szFaceName
            invoke  SendMessage,[edi].hEdit,EM_SETCHARFORMAT,SCF_ALL,esi

fearless

  • Member
  • ****
  • Posts: 539
    • Github
Re: EM_SETCHARFORMAT no working.
« Reply #20 on: October 26, 2021, 03:01:10 AM »
Here is some functions I have used for richedit to change color and put a wavy red underline under spelling mistakes or coding mistakes or other words or letters of interest:
Code: [Select]
RichSetPos              PROTO :DWORD, :DWORD

RichAppend              PROTO :DWORD, :DWORD, :DWORD
RichAppendEx            PROTO :DWORD, :DWORD, :DWORD

RichAppendW             PROTO :DWORD, :DWORD, :DWORD
RichAppendExW           PROTO :DWORD, :DWORD, :DWORD


.CODE

;-----------------------------------------------------------------------------------------
; RichSetPos - Set position
;-----------------------------------------------------------------------------------------
RichSetPos PROC hRWnd:DWORD, dwPos:DWORD
    LOCAL charrng:CHARRANGE
    mov eax, dwPos
    mov charrng.cpMin, eax
    mov charrng.cpMax, eax
    invoke SendMessageW, hRWnd, EM_EXSETSEL, NULL, ADDR charrng
    invoke SendMessageW, hRWnd, EM_SCROLLCARET, NULL, NULL      ;scroll the text into view
    ret
RichSetPos ENDP



;-----------------------------------------------------------------------------------------
; RichAppendW - WIDE - Append text with color to RichEdit control
;-----------------------------------------------------------------------------------------
RichAppendW proc hRWnd:DWORD, pBuff:DWORD,dwColor:DWORD
    LOCAL charrng:CHARRANGE
    LOCAL charfmt:CHARFORMAT2
   
    Invoke RtlZeroMemory, Addr charfmt, SIZEOF CHARFORMAT2
    mov eax, -1
    mov charrng.cpMax, eax
    mov charrng.cpMin, eax
    mov charfmt.cbSize, SIZEOF CHARFORMAT2
    mov charfmt.dwMask, CFM_COLOR or CFM_UNDERLINE or CFM_UNDERLINETYPE or CFM_BOLD or CFM_BACKCOLOR
    mov charfmt.dwEffects, CFE_AUTOBACKCOLOR
    mov charfmt.bUnderlineType, CFU_UNDERLINENONE
    mov eax, dwColor
    mov charfmt.crTextColor, eax
    invoke SendMessageW, hRWnd, EM_EXSETSEL, NULL, ADDR charrng
    invoke SendMessageW, hRWnd, EM_SETCHARFORMAT, SCF_SELECTION, ADDR charfmt
    invoke SendMessageW, hRWnd, EM_REPLACESEL, FALSE, pBuff
    invoke SendMessageW, hRWnd, EM_SCROLLCARET, NULL, NULL      ;scroll the text into view
    ret
RichAppendW endp


;-----------------------------------------------------------------------------------------
; RichAppendExW - WIDE - Append text with wavy underline and red bolded text to RE control
;-----------------------------------------------------------------------------------------
RichAppendExW proc hRWnd:DWORD, pBuff:DWORD,dwColor:DWORD
    LOCAL charrng:CHARRANGE
    LOCAL charfmt:CHARFORMAT2
   
    Invoke RtlZeroMemory, Addr charfmt, SIZEOF CHARFORMAT2
    mov eax, -1
    mov charrng.cpMax, eax
    mov charrng.cpMin, eax
    mov charfmt.cbSize, SIZEOF CHARFORMAT2
    mov charfmt.dwMask, CFM_COLOR or CFM_UNDERLINE or CFM_UNDERLINETYPE or CFM_BOLD or CFM_BACKCOLOR
    mov charfmt.dwEffects, CFE_UNDERLINE or CFE_BOLD or CFE_OUTLINE or CFE_AUTOBACKCOLOR
    mov charfmt.bUnderlineType, CFU_UNDERLINEHEAVYWAVE
    mov eax, dwColor
    mov charfmt.crTextColor, eax
    mov eax, 0EEEEFFh
    mov charfmt.crBackColor, eax
    mov charfmt.bReserved1, 5
    invoke SendMessageW, hRWnd, EM_EXSETSEL, NULL, ADDR charrng
    invoke SendMessageW, hRWnd, EM_SETCHARFORMAT, SCF_SELECTION, ADDR charfmt
    invoke SendMessageW, hRWnd, EM_REPLACESEL, FALSE, pBuff
    invoke SendMessageW, hRWnd, EM_SCROLLCARET, NULL, NULL      ;scroll the text into view
    ret
RichAppendExW endp


;-----------------------------------------------------------------------------------------
; RichAppend - ASCII - Append text with color to RichEdit control
;-----------------------------------------------------------------------------------------
RichAppend proc hRWnd:DWORD, pBuff:DWORD,dwColor:DWORD
    LOCAL charrng:CHARRANGE
    LOCAL charfmt:CHARFORMAT2
   
    Invoke RtlZeroMemory, Addr charfmt, SIZEOF CHARFORMAT2
    mov eax, -1
    mov charrng.cpMax, eax
    mov charrng.cpMin, eax
    mov charfmt.cbSize, SIZEOF CHARFORMAT2
    mov charfmt.dwMask, CFM_COLOR or CFM_UNDERLINE or CFM_UNDERLINETYPE or CFM_BOLD or CFM_BACKCOLOR
    mov charfmt.dwEffects, CFE_AUTOBACKCOLOR
    mov charfmt.bUnderlineType, CFU_UNDERLINENONE
    mov eax, dwColor
    mov charfmt.crTextColor, eax
    invoke SendMessage, hRWnd, EM_EXSETSEL, NULL, ADDR charrng
    invoke SendMessage, hRWnd, EM_SETCHARFORMAT, SCF_SELECTION, ADDR charfmt
    invoke SendMessage, hRWnd, EM_REPLACESEL, FALSE, pBuff
    invoke SendMessage, hRWnd, EM_SCROLLCARET, NULL, NULL      ;scroll the text into view
    ret
RichAppend endp


;-----------------------------------------------------------------------------------------
; RichAppendEx - ASCII - Append text with wavy underline and red bolded text to RE control
;-----------------------------------------------------------------------------------------
RichAppendEx proc hRWnd:DWORD, pBuff:DWORD,dwColor:DWORD
    LOCAL charrng:CHARRANGE
    LOCAL charfmt:CHARFORMAT2
   
    Invoke RtlZeroMemory, Addr charfmt, SIZEOF CHARFORMAT2
    mov eax, -1
    mov charrng.cpMax, eax
    mov charrng.cpMin, eax
    mov charfmt.cbSize, SIZEOF CHARFORMAT2
    mov charfmt.dwMask, CFM_COLOR or CFM_UNDERLINE or CFM_UNDERLINETYPE or CFM_BOLD or CFM_BACKCOLOR
    mov charfmt.dwEffects, CFE_UNDERLINE or CFE_BOLD ;or CFE_AUTOBACKCOLOR
    mov charfmt.bUnderlineType, CFU_UNDERLINEHEAVYWAVE
    mov eax, dwColor
    mov charfmt.crTextColor, eax
    mov eax, 0FF80EFh
    mov charfmt.crBackColor, eax
    invoke SendMessage, hRWnd, EM_EXSETSEL, NULL, ADDR charrng
    invoke SendMessage, hRWnd, EM_SETCHARFORMAT, SCF_SELECTION, ADDR charfmt
    invoke SendMessage, hRWnd, EM_REPLACESEL, FALSE, pBuff
    invoke SendMessage, hRWnd, EM_SCROLLCARET, NULL, NULL      ;scroll the text into view
    ret
RichAppendEx endp
fearless

Lian Li PC-O11DW Case, ASUS Crosshair VIII Hero, AMD Ryzen 9 5950X, 32GB DDR4, MSI RX 5700XT, NZXT Kraken Z73, Seasonic 1000W PSU

My Github  Twitter  My Gitbook

xandaz

  • Member
  • ***
  • Posts: 468
  • I luv you babe
    • My asm examples
Re: EM_SETCHARFORMAT no working.
« Reply #21 on: October 26, 2021, 03:48:46 AM »
   Thanks for your examples. I'm still haveing trouble. The EM_SETCHARFORMAT dones't work. It gives ERROR_SUCCESS but there's no change to the edit control.  Strangelly CHARFORMAT2 seems to work if I don't use UNICODE. ty
« Last Edit: October 26, 2021, 05:02:00 AM by xandaz »