realtime translation in textarea, whats best approach?

Started by daydreamer, March 30, 2009, 02:22:24 PM

Previous topic - Next topic

daydreamer

WM_KEY +SETTEXT doesnt seem to work that good for my purposes
is there a GETTEXT that I could use to read input and writeback it changed with SETTEXT?
what about WM_CHAR ?
any events I can use that are part of editcontrol?


invoke CreateWindowEx,NULL,ADDR EditClass,NULL,\
                   WS_VISIBLE or WS_CHILD or ES_LEFT or ES_MULTILINE or\
                   ES_AUTOHSCROLL or ES_AUTOVSCROLL,0,\
                   32,790,500,hWnd,EditID,\
                   hInstance,NULL
        mov hwndEdit,eax

ToutEnMasm


Quote
WM_KEY +SETTEXT doesnt seem to work that good for my purposes
And what are your puposes ?.
Making a translator word by word ?

daydreamer

Quote from: ToutEnMasm on March 30, 2009, 04:10:28 PM

Quote
WM_KEY +SETTEXT doesnt seem to work that good for my purposes
And what are your puposes ?.
Making a translator word by word ?

char by char, can you be more helpful?plz

donkey

Well, there is the option of EM_SETSEL and EM_REPLACESEL that both work with standard edit controls. You can isolate the text using EM_SETSEL and use WM_COPY to move the text into a buffer, EM_REPLACESEL will replace only the selected portion of the text.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

daydreamer

thanks Donkey
you can sendmessage, GETTEXTLENGTH apparantly, which could be good solution to check against older textlength to see if user has written anything since last time
could it be wise to put this code in a TIMER_EVENT to not unnesserary do it too often?

jj2007

The official way to check it is through an EN_CHANGE notification. But check this article first.

For a RichEdit control, I use this handler:

CASE WM_COMMAND
mov ecx, lParam ; SWITCH uses eax, so we take ecx for the handle in lParam
mov eax, wParam
shr eax, 16
switch eax ; the WM_COMMAND message

case EN_CHANGE ; see also EN_SELCHANGE
... do stuff ...

daydreamer

Quote from: jj2007 on April 01, 2009, 11:41:49 AM
The official way to check it is through an EN_CHANGE notification. But check this article first.

For a RichEdit control, I use this handler:

CASE WM_COMMAND
mov ecx, lParam ; SWITCH uses eax, so we take ecx for the handle in lParam
mov eax, wParam
shr eax, 16
switch eax ; the WM_COMMAND message

case EN_CHANGE ; see also EN_SELCHANGE
... do stuff ...

thanks
crap it hangs when I transfer from dynamic memory with sendmessage, SETTEXT , where I have placed a testtext copied from datasection, I guess I need to have some kind of EOF marker or what?

jj2007

Magnus,
Can you post some code? I don't quite get what you are talking about. EOF is Ascii zero, but I doubt you meant that ::)

drizz

Quote from: daydreamer on March 30, 2009, 06:09:30 PMchar by char, can you be more helpful?plz
Subclass an editbox and handle WM_CHAR.


...
; on init dialog
invoke GetDlgItem,hWnd,IDC_TSTEDT
mov hEdt,eax
invoke SetWindowLong,hEdt,GWL_WNDPROC,offset MyEdtProc
mov EdtDefWndProc,eax
....
MyEdtProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.if uMsg == WM_CHAR
invoke CharUpper,addr wParam
.endif
invoke CallWindowProc,EdtDefWndProc,hWnd,uMsg,wParam,lParam
ret
MyEdtProc endp


for multiline you can also set buffer handle.

EDTBUFSIZE equ 1000h
invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT,EDTBUFSIZE
mov hEdtBufNew,eax
invoke SendMessage,hEdt,EM_LIMITTEXT,EDTBUFSIZE-1,0
invoke SendMessage,hEdt,EM_SETHANDLE,hEdtBufNew,0


and later  in subclassed wndproc

.if eax == WM_KEYUP
mov edx,hEdtBufNew
invoke lstrlen,edx
mov edx,hEdtBufNew
mov ecx,FALSE
.while eax
.if byte ptr [edx]>='a' && byte ptr [edx]<='z'
xor byte ptr [edx],' '
or ecx,TRUE
.endif
inc edx
dec eax
.endw
;; update needed?
.if ecx == TRUE
invoke InvalidateRect,hWnd,0,TRUE
.endif
.endif


The truth cannot be learned ... it can only be recognized.

daydreamer

thanks it works now with testing to change from lowercase to uppercase with single AND dl,255-32
and now it time to step up to unicode


daydreamer

I can't get unicode to work
         mov   edx,WS_VISIBLE or WS_CHILDWINDOW or WS_VSCROLL or ES_NOHIDESEL or ES_AUTOVSCROLL or ES_MULTILINE
    invoke CreateWindowEx,WS_EX_CLIENTEDGE,CADD("RichEdit20W"),NULL,edx,0,32,790,500,hWnd,799,hInstance,NULL
   
        mov hwndEdit,eax
       invoke SendMessage,hwndEdit,WM_SETTEXT,NULL,pMemory

or I need another way to set a unicode message?what includes are required? it only works in ascii
trying to set an arabic text in unicode doesnt work

daydreamer

ok I starting to get unicode to work, displaying arabic, kanji etc in a window, you use sendmessageW instead etc
here is what I found very useful
http://unicode.org/iuc/iuc17/a7/slides.ppt
you can get google to convert it for you to html
and now time to put some stickers on my new keyboard