News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

New richedit library module.

Started by hutch--, March 10, 2020, 12:17:48 AM

Previous topic - Next topic

hutch--

I have consolidated the code necessary to build a very large capacity rich edit control. I has both background and text colour settings and optionally a user selected font. If no font is selected and zero (0) is passed, it defaults to "fixedsys". I have put it in the library and it will be available in the next distribution of the library.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    IFNDEF CHARFORMAT2
      CHARFORMAT2 STRUCT QWORD
        cbSize dd ?
        dwMask dd ?
        dwEffects dd ?
        yHeight dd ?
        yOffset dd ?
        crTextColor dd ?
        bCharSet db ?
        bPitchAndFamily db ?
        szFaceName db LF_FACESIZE dup (?)
        wWeight dw ?
        sSpacing dw ?
        crBackColor dd ?
        lcid dd ?
        dwReserved dd ?
        sStyle dw ?
        wKerning dw ?
        bUnderlineType db ?
        bAnimation db ?
        bRevAuthor db ?
      CHARFORMAT2 ENDS
    ENDIF

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

create_riched proc hParent:QWORD,instance:QWORD,bakcolour:QWORD,txtcolour:QWORD,hFont:QWORD

    LOCAL pEdit  :QWORD
    LOCAL styl   :QWORD

    invoke LoadLibrary,"riched20.dll"

  ; ---------------------------
  ; create the richedit control
  ; ---------------------------
    mov styl, WS_VISIBLE or WS_CHILDWINDOW or WS_CLIPSIBLINGS or \
              ES_MULTILINE or WS_VSCROLL or WS_HSCROLL or ES_AUTOHSCROLL or \
              ES_AUTOVSCROLL or ES_NOHIDESEL or ES_DISABLENOSCROLL

    invoke CreateWindowEx,WS_EX_LEFT,"RichEdit20a", \         ; WS_EX_STATICEDGE
           0,styl,0,0,200,100,hParent,111,instance,0

    mov pEdit, rax
  ; ---------------------------

    rcall SendMessage,pEdit,EM_EXLIMITTEXT,0,1000000000
    rcall SendMessage,pEdit,EM_SETOPTIONS,ECOOP_XOR,ECO_SELECTIONBAR

    .if hFont == 0
      mov hFont, rvcall(font_handle,"fixedsys",9,600)       ; default font if none set
    .endif

    rcall SendMessage,pEdit,WM_SETFONT,hFont,TRUE           ; set font to edit control

    mov ecx, 10
    mov edx, 5
    mov ax, dx
    rol eax, 16
    mov ax, cx
    rcall SendMessage,pEdit,EM_SETMARGINS,EC_LEFTMARGIN or EC_RIGHTMARGIN,rax
    rcall SendMessage,pEdit,EM_SETTEXTMODE,TM_PLAINTEXT or TM_MULTILEVELUNDO or TM_MULTICODEPAGE,0
    invoke set_edit_colours,pEdit,bakcolour,txtcolour

    mov rax, pEdit

    ret

create_riched endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

set_edit_colours proc edit:QWORD,bakcolour:QWORD,txtcolour:QWORD

    LOCAL tcol  :DWORD

    mov rax, txtcolour
    mov tcol, eax

    invoke SendMessage,edit,EM_SETBKGNDCOLOR,0,bakcolour

    .data?
      align 16
      cfm@_@2 CHARFORMAT2 <?>
    .code

    mov cfm@_@2.cbSize,            SIZEOF CHARFORMAT2
    mov cfm@_@2.dwMask,            CFM_COLOR
    mov cfm@_@2.dwEffects,         0
    mov cfm@_@2.yHeight,           0
    mov cfm@_@2.yOffset,           0
    mrmd cfm@_@2.crTextColor,      tcol
    mov cfm@_@2.bCharSet,          0
    mov cfm@_@2.bPitchAndFamily,   0
    mov cfm@_@2.szFaceName,        0
    mov cfm@_@2.wWeight,           0
    mov cfm@_@2.sSpacing,          0
    mov cfm@_@2.crBackColor,       0
    mov cfm@_@2.lcid,              0
    mov cfm@_@2.dwReserved,        0
    mov cfm@_@2.sStyle,            0
    mov cfm@_@2.wKerning,          0
    mov cfm@_@2.bUnderlineType,    0
    mov cfm@_@2.bAnimation,        0
    mov cfm@_@2.bRevAuthor,        0

    invoke PostMessage,edit,EM_SETCHARFORMAT,SCF_ALL,ADDR cfm@_@2

    ret

set_edit_colours endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end

These are the prototypes.

    externdef create_riched:PROC
    externdef set_edit_colours:PROC

Code is called in this manner.

    mov hFont, rvcall(font_handle,"Consolas",18,600)
    mov hEdit, rv(create_riched,hWnd,hInstance,bak_colour,txt_colour,hFont)
    rcall SetFocus,hEdit


daydreamer

Great,thanks,wanted a 64bit example :thumbsup:
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

Adamanteus

For be app window, could be child style under condition :
Code (asm) Select

; ---------------------------
  ; create the richedit control
  ; ---------------------------
    mov styl, WS_VISIBLE or WS_CLIPSIBLINGS or \
              ES_MULTILINE or WS_VSCROLL or WS_HSCROLL or ES_AUTOHSCROLL or \
              ES_AUTOVSCROLL or ES_NOHIDESEL or ES_DISABLENOSCROLL
   
    .if hParent
or styl, WS_CHILDWINDOW
.endif

hutch--

I am not sure what the gain is supposed to be, a richedit control will not run without a parent window.

TouEnMasm

#4
The structure had not the same size in unicode or ansi and change with version + bUnderlineColor.
Quote
CHARFORMAT2W   STRUCT DEFALIGNMASM
   cbSize DWORD ?
   dwMask DWORD ?
   dwEffects DWORD ?
   yHeight DWORD ?
   yOffset DWORD ? ; > 0 for superscript, < 0 for subscript
   crTextColor COLORREF ?
   bCharSet BYTE ?
   bPitchAndFamily BYTE ?
   szFaceName WORD LF_FACESIZE dup (?)
   wWeight WORD ? ; Font weight (LOGFONT value)      
   sSpacing WORD ? ; Amount to space between letters   
   crBackColor COLORREF ? ; Background color             
   lcid LCID ? ; Locale ID                  
IF ( _RICHEDIT_VER GE 00500h)
   union
   dwReserved DWORD ? ; Name up to 5.0
   dwCookie DWORD ? ; Client cookie opaque to RichEdit
   ENDS
   ELSE
   dwReserved DWORD ? ; Name up to 5.0
ENDIF
   sStyle WORD ? ; Style handle                
   wKerning WORD ? ; Twip size above which to kern char pair
   bUnderlineType BYTE ? ; Underline type               
   bAnimation BYTE ? ; Animated text like marching ants
   bRevAuthor BYTE ? ; Revision author index         
IF ( _RICHEDIT_VER GE 00800h)
   bUnderlineColor BYTE ? ; Underline color
ENDIF
CHARFORMAT2W      ENDS



CHARFORMAT2A   STRUCT DEFALIGNMASM
   cbSize DWORD ?
   dwMask DWORD ?
   dwEffects DWORD ?
   yHeight DWORD ?
   yOffset DWORD ? ; > 0 for superscript, < 0 for subscript
   crTextColor COLORREF ?
   bCharSet BYTE ?
   bPitchAndFamily BYTE ?
   szFaceName BYTE LF_FACESIZE dup (?)
   wWeight WORD ? ; Font weight (LOGFONT value)      
   sSpacing WORD ? ; Amount to space between letters   
   crBackColor COLORREF ? ; Background color             
   lcid LCID ? ; Locale ID   
               
IF ( _RICHEDIT_VER GE 00500h)
   union
   dwReserved DWORD ? ; Name up to 5.0
   dwCookie DWORD ? ; Client cookie opaque to RichEdit
   ENDS
   ELSE
   dwReserved DWORD ? ; Name up to 5.0
ENDIF
   sStyle WORD ? ; Style handle                
   wKerning WORD ? ; Twip size above which to kern char pair
   bUnderlineType BYTE ? ; Underline type               
   bAnimation BYTE ? ; Animated text like marching ants
   bRevAuthor BYTE ? ; Revision author index         

IF ( _RICHEDIT_VER GE 00800h)
   bUnderlineColor BYTE ? ; Underline color
ENDIF
CHARFORMAT2A      ENDS




IFDEF UNICODE
CHARFORMAT2   equ   <CHARFORMAT2W>
ELSE
CHARFORMAT2   equ   <CHARFORMAT2A>
ENDIF

Fa is a musical note to play with CL

hutch--

I don't see the point of the comment, the code posted above is ANSI, not UNICODE.