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

    It seems to be working after all. Thanks!

xandaz

    And btw JJ. I'm using the MASM32 SDK exactly as it came only with the addtion of the winclasses file.

jj2007

Quote from: xandaz 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.

Right, the Masm32 SDK is not the culprit. Line 278 of mdi.asm:
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

   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

    Hey guys. Having a hard time to get CHARFORMAT2 to work. Help is appreciated            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

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: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

xandaz

#21
   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