Author Topic: New richedit library module.  (Read 1035 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 8047
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
New richedit library module.
« on: March 10, 2020, 12:17:48 AM »
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

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

daydreamer

  • Member
  • *****
  • Posts: 1459
  • building nextdoor
Re: New richedit library module.
« Reply #1 on: March 10, 2020, 06:46:33 AM »
Great,thanks,wanted a 64bit example :thumbsup:
SIMD fan and macro fan
Happy new year 2021 that can only turn out to become better than worse 2020 :)

Adamanteus

  • Member
  • **
  • Posts: 240
    • LLC "AMS"
Re: New richedit library module.
« Reply #2 on: March 11, 2020, 12:03:58 AM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 8047
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: New richedit library module.
« Reply #3 on: March 11, 2020, 12:50:34 AM »
I am not sure what the gain is supposed to be, a richedit control will not run without a parent window.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

TouEnMasm

  • Member
  • *****
  • Posts: 1534
    • EditMasm
Re: New richedit library module.
« Reply #4 on: December 29, 2020, 07:44:28 PM »
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

« Last Edit: January 09, 2021, 09:01:45 PM by TouEnMasm »
Fa is a musical note to play with CL