How to display in Edit control the text which is not null terminating

Started by kyo, July 08, 2007, 09:59:07 AM

Previous topic - Next topic

kyo

HI,
My question is that how to display the text which is not Null terminating in the edit box or text box.I have tried to read EXE and similar files using InputFile macro and then display it in the edit control but it never succeeded it only shows MZ and further 2 chars next whole file is omitted.How can I read small binary files and display them in the text box even if the contain 0 or null char.

ramguru

You can't display non-null-terminated (or two-null-terminated if we're talking about unicode) strings in edit control. One workaround is to replace non-visual chars with dots. And remember the purpose of edit control is to display text, you're probably aiming at hex editor, that has your described functionality.

kyo

Quote from: ramguru on July 08, 2007, 10:23:01 AM
You can't display non-null-terminated (or two-null-terminated if we're talking about unicode) strings in edit control. One workaround is to replace non-visual chars with dots. And remember the purpose of edit control is to display text, you're probably aiming at hex editor, that has your described functionality.

Notpad uses that edit control but it is still able to open the binary files and display all chars like the edit command does in the dos  mode. So why cant that edit control which is in the notpad work properly in my asm program.

ramguru


kyo

Ok if that the fact we can put it in rich edit but WM_SETTEXT msg takes null terminating string how to solve this. :dazzled:. Is there other way to fill in without null strings.

ramguru

There is no simple way to do that...
you can replace zeroes to spaces with this code:

mov    fname, FUNC(OpenFileDialog, hWin, hInstance, CADD("Choose file"), CTXT("PE files",0,"*.exe",0))
.if byte ptr [eax] != 0
invoke GetProcessHeap
mov    glob_heap, eax
mov    file, fopen(fname)
invoke GetFileSize, file, 0
mov    esi, eax
invoke HeapAlloc, glob_heap, 0, esi
mov    edi, eax
mov    ecx, fread(file, edi, esi)
; replace zeroes to spaces
mov    eax, edi
mov    ecx, esi
@@:
test   ecx, ecx
jz     @zero_count
cmp    BYTE PTR [eax], 0
jnz    @just_go_on
mov    BYTE PTR [eax], ' '
@just_go_on:
inc    eax
dec    ecx
jmp    @B
@zero_count:

invoke SendDlgItemMessage, hWin, 1001, WM_SETTEXT, 0, edi ; setting text for edit-box
fclose(file)
invoke HeapFree, glob_heap, 0, edi
.endif

Or you can try to code even more sophisticated app, custom control .. whatever.

BTW I think it's useless to have binary file in edit-box, because you cannot modify & save it back...

Tedd

If you have a RichEdit control, use EM_STREAMIN to set the text, not WM_SETTEXT/SetWindowText (which expects a null terminated string).
No snowflake in an avalanche feels responsible.

kyo

Quote from: Tedd on July 08, 2007, 02:02:42 PM
If you have a RichEdit control, use EM_STREAMIN to set the text, not WM_SETTEXT/SetWindowText (which expects a null terminated string).


Ok  :dance: it  seems to be good i will try this