News:

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

EditBox get last Char

Started by ragdog, May 09, 2010, 12:20:34 PM

Previous topic - Next topic

ragdog

Hi

I use for my edit field the EN_CHANGE messages
Now have i the probelm with get the last Char.

I need this for format this string with "-"

Example:

Enter a Char to the edit field >> get the last Char if this the 2 char add "-" then input this last pressed Char

greets,

qWord

What about getting the text with WM_GETTEXT and then extract the char. from buffer?
A more powerfull method would be to subclass the controll.
FPU in a trice: SmplMath
It's that simple!

Tedd

Use EN_UPDATE instead.
Then: buff = WM_GETTEXT, if changes are required {make changes, WM_SETTEXT (buff) }
No snowflake in an avalanche feels responsible.

ragdog

Thanks

What if the different to EN_UPDATE and EN_CHANGE?

ragdog

Ok i have it

EN_CHANGE     Change text after draw
EN_UPDATE       Change text before draw

Greenhorn__

Hi,

QuoteEN_CHANGE Notification Code

Sent when the user has taken an action that may have altered text in an edit control. Unlike the EN_UPDATE  notification code, this notification code is sent after the system updates the screen. The parent window of the edit control receives this notification code through a WM_COMMAND message.

http://msdn.microsoft.com/en-us/library/bb761676%28VS.85%29.aspx


Regards
Greenhorn
You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time.
(Abraham Lincoln)

joemc

Quote from: qWord on May 09, 2010, 12:55:21 PM
A more powerfull method would be to subclass the controll.

I agree, but he may want regular edits in his application as well, superclassing is probably preferred msdn

note: This will not prevent someone from typing 3 or more chars, than going back and erasing the '-' you would have to add a check for that as well. And if the user types the '-'  you will have two of them.... all easy to check for, left out for clarity and not sure what you are trying to achieve.



attached is full source with a main, message loop etc
relevant code:

.data
OriginalEditProc DWORD 0

.code
start:

call Main
call ExitProcess

CreateSuperEdit proc hParent:DWORD
LOCAL wc:WNDCLASSEX
LOCAL hinst:HINSTANCE
STRING szEditClass,"EDIT"
STRING szSuperEditClass, "SUPER_EDIT_CLASS"

invoke GetModuleHandle, NULL
mov hinst,eax

mov wc.cbSize, sizeof WNDCLASSEX
invoke GetClassInfoEx, NULL, ADDR szEditClass, ADDR wc
mov wc.lpszClassName, OFFSET szSuperEditClass
m2m OriginalEditProc, wc.lpfnWndProc
mov wc.lpfnWndProc, OFFSET SuperEditProc
m2m wc.hInstance, hinst
invoke RegisterClassEx, ADDR wc

invoke CreateWindowEx, WS_EX_LEFT, ADDR szSuperEditClass, NULL, WS_TABSTOP or WS_VISIBLE or WS_CHILD, 10, 10, 200, 20, hParent, NULL, hinst, NULL

ret
CreateSuperEdit endp

SuperEditProc proc hwnd:DWORD,msg:DWORD,wparam:DWORD,lparam:DWORD

.IF msg==WM_CHAR
invoke GetWindowTextLength,hwnd
.IF eax==2 && wparam !=8 ; backspace
mov eax,'-'
invoke CallWindowProc,OriginalEditProc,hwnd,msg,eax,lparam
.ENDIF
.ENDIF

invoke CallWindowProc,OriginalEditProc,hwnd,msg,wparam,lparam
ret
SuperEditProc endp