News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Changing Text Color in a RichEdit Control

Started by vega, July 06, 2007, 07:52:44 AM

Previous topic - Next topic

vega

Is it possible to change text color in a rich edit by using EM_SETCHARFORMAT message?
I want to know about a method that changes none system text color in a rich edit.

-asmStudent

MichaelW

I'm not sure that all of this is correct, but apparently the answer is yes.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      hInstance     dd 0
      hWndRichEdit  dd 0
      cf            CHARFORMAT <,,,,,,,,"Courier New",0>
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

DlgProc proc hDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    Switch uMsg

      Case WM_INITDIALOG

        invoke GetDlgItem, hDlg, 101
        mov hWndRichEdit, eax

        mov cf.cbSize, SIZEOF(CHARFORMAT)
        mov cf.dwMask, CFM_COLOR
        mov cf.dwEffects, 0
        mov cf.yHeight, 200
        mov cf.yOffset, 0
        RGB 0,0,255
        mov cf.crTextColor, eax
        mov cf.bCharSet, ANSI_CHARSET
        mov cf.bPitchAndFamily, DEFAULT_PITCH or FF_DONTCARE

        invoke SendMessage,hWndRichEdit,EM_SETCHARFORMAT,SCF_ALL, ADDR cf

      Case WM_CLOSE

        invoke EndDialog, hDlg, 0

    EndSw

    xor eax, eax
    ret

DlgProc endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    invoke GetModuleHandle, NULL
    mov hInstance, eax

    ; Use Rich Edit version 2.0 or 3.0.

    szText ReDLL,"RICHED20.DLL"
    invoke LoadLibrary,ADDR ReDLL

    Dialog "Test", \
           "Courier New",8, \
           WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \
           1,0,0,160,120,1024

    DlgComCtl "RichEdit20a", \
              ES_MULTILINE or WS_VSCROLL or WS_HSCROLL or \
              ES_AUTOVSCROLL or ES_AUTOHSCROLL or \
              ES_WANTRETURN or ES_SUNKEN, \
              10,10,138,85,101

    CallModalDialog hInstance,0,DlgProc,NULL

    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation

vega

Just, I found one example from Icezelion Tutor as follow.


  SetColor proc

     LOCAL cfm:CHARFORMAT

     invoke SendMessage, hRichEdit, EM_SETBKGNDCOLOR, 0, BackgroundColor
     invoke RtlZeroMemory, addr cfm, sizeof cfm
     mov cfm.cbSize, sizeof cfm
     mov cfm.dwMask, CFM_COLOR
     push TextColor
     pop cfm.crTextColor
     invoke SendMessage, hRichEdit, EM_SETCHARFORMAT, SCF_ALL, addr cfm
     ret
  SetColor endp


but, I can't find any comment for 'RtlZeroMemory' function in Win32API Help.
so, I did replace it with 'ZeroMemory' function, but it occured 'undefined symbol' error in assemble time.
I don't know what is this problem.




MichaelW

ZeroMemory is a (C-language) macro. The actual function that the macro calls is RtlZeroMemory.

http://msdn2.microsoft.com/en-us/library/aa366920.aspx

I handled each member individually so the code would be easy to experiment with.
eschew obfuscation

vega

#4
Thank you very much, MichaelW..!
just ago, I solved this problem by your good example, as follow.




     ;Get current Text's Format Information into specified Structure
     INVOKE SendMessage, hRichEdit, EM_GETCHARFORMAT, 0, ADDR CharFormatStruc

     MOV  CharFormatStruc.cbSize, SizeOf CHARFORMAT
     MOV  CharFormatStruc.dwMask, CFM_COLOR
     MOV  CharFormatStruc.dwEffects, 0
     PUSH CharColorStruc.rgbResult
     POP  CharFormatStruc.crTextColor

     INVOKE SendMessage, hRichEdit, EM_SETCHARFORMAT, SCF_ALL, ADDR CharFormatStruc





thanks again..!!  :U

vega

and then,
Where is the 'Winbase.h' Location?

hutch--

vega,

You don't need winbase.h, its a C header file which is no use to you in assembler.

You can emulate the C macro if you want to using a different prototype.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    externdef _imp__RtlZeroMemory@8:PTR pr2
    ZeroMemory equ <_imp__RtlZeroMemory@8>

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main

    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL buffer[8192]:BYTE

    invoke ZeroMemory,ADDR buffer,8192

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Tedd

No snowflake in an avalanche feels responsible.

vega

sir. Hutch,
It is very difficult to understanding for me.


   ******************************************************
    externdef _imp__RtlZeroMemory@8:PTR pr2
    ZeroMemory equ <_imp__RtlZeroMemory@8>

   ******************************************************


May I understand this very difficult notating (red marked letters) Library locates anywhere
in other program module?


   _imp__RtlZeroMemory@8:PTR pr2

Please, interpret me, this meaning..most easily. :dazzled:




hutch--

vega,

    externdef _imp__RtlZeroMemory@8:PTR pr2

1. externdef means function is external to the code in the application
2. _imp__RtlZeroMemory@8 is the actualy import name of the function
3. Its data type is PTR (a pointer to)
4. pr2 is a macro of expanded arguments for the prototype.

    ZeroMemory equ <_imp__RtlZeroMemory@8>

This is an equate to make the name more managable.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

vega

Thank you,  Hutch~ (and Tedd)
I undersoot it......, barely...... :boohoo: