I have written a procedure that takes, as input, a window handle to a richedit control and sets the text color to gray and the font to "Verdana". I am using the CHARFORMAT structure as well as the EM_GETCHARFORMAT and EM_SETCHARFORMAT messaes. I fill out the CHARFORMAT structure as best as I can and call SendMessage but then I always get a return value of 0 which means that the SendMessage call failed. Does anyone know what I am doing wrong. Here is a section of my code:
SetupEditFont proc hWnd :DWORD
LOCAL fmt:CHARFORMAT
INVOKE SendMessage, hWnd, EM_GETCHARFORMAT, NULL, ADDR fmt
mov fmt.cbSize,SIZEOF CHARFORMAT
mov fmt.dwEffects, 0h
mov fmt.dwMask, CFM_COLOR or CFM_FACE or CFM_SIZE or CFM_BOLD
mov fmt.crTextColor, 0C0C0C0h ;gray
INVOKE lstrcpy, ADDR fmt.szFaceName, OFFSET FontName
mov fmt.yHeight, 165
INVOKE SendMessage, hWnd, EM_SETCHARFORMAT, SCF_ALL, ADDR fmt
.if eax==0 ; sendmessage failed.
invoke MessageBox, NULL, ADDR DebugMsg, OFFSET AppName, MB_OK
.endif
ret
SetupEditFont endp
Sorry about any whitespace.
All variables are defined in the .data section of my code. The code compiles perfectly and the window handle passed as input is always a Richedit Control yet SendMessage always returns 0. Any ideas ?
Also, so that I don't post another question.. What is the difference between OFFSET and ADDR ?
Thanks,
Devin.
You must set the size first.
mov fmt.cbSize, SIZEOF CHARFORMAT
INVOKE SendMessage, hWnd, EM_GETCHARFORMAT, NULL, ADDR fmt
Change the NULL to TRUE if you want the current settings.
If that doesn't work.
Are you using version 1 or 2/3 of RichEdit?
What Windows.inc are you using?
OFFSET - Gives address of the variable declared in .data or .data? section.
ADDR - Gives address of the variable declared as LOCAL variable. LOCAL variables are in stack. In order to know the address you have to use 'LEA' instruction to find the address. MASM does that for you when you use ADDR. It is being translated as 'LEA eax, variable'. Eg. 'LEA eax, '.
Ewayne,
Thanks, it is now working. I updated my include files to version 1.21 (from 1.18) and changed a line in my code. I guess by placing the MOV after the Sendmessage call does fix the problem. That is strange because I ripped the code out from a C Win32 program.
I was using RICHED32.DLL. So version 1.0
The NULL and TRUE values don't seem to have any effect for my procedure.
Also, thanks sjhenry for answering my question on OFFSET and ADDR
Devin
i have the same problem : SendMessage fail for EM_SETCHARFORMAT
invoke SendMessageA, hRichEdit, EM_SETBKGNDCOLOR, 0, 0 ; black
mov cf.cbSize, sizeof CHARFORMAT
mov cf.dwMask,40000000h ;CFM_COLOR
mov cf.crTextColor,0c0c0c0h ; gray
invoke SendMessageA, hRichEdit, EM_SETCHARFORMAT, 4, addr cf
SCF_ALL equ 4 ???
i use "Richedit20A" ( version 2 or 3)
i don't understand what's wrong...