i superclassed an editbox,so that i only can enter a-f A-F 0-9 and some other stuff...

now COPY and PASTE (CTRL+C,CTRL+V) doesnt work. see also Iczelions tut's (20,22), there also CTRL+C doesnt work.

here is some code:


WndProc proc handle1:DWORD,uMsg1:DWORD,wParam1:DWORD,lParam1:DWORD
.IF uMsg1 == WM_CHAR
mov eax,wParam1
mov edx,_len
mov edi,currentDialog
.IF (al>="0" && al<="9") || (al>="a" && al<="f") || (al>="A" && al<="F") || al=="*" || al=="," || al==VK_BACK
.IF (byte ptr[edi+edx-1]!=22h) && (byte ptr[edi+edx-1]!="'")
.IF al>="a" && al<="f"
sub al,20h
.ENDIF
.ENDIF
mov wParam1,eax
jmp @sendkey
.ELSEIF (al==22h || al=="'") && _len==0
jmp @sendkey
.ELSEIF (al==22h || al=="'") ; && (byte ptr[edi+edx-1]=="," || byte ptr[edi+edx-2]==22h ||byte ptr[edi+edx-2]=="'" )
jmp @sendkey
.ELSEIF (al>=0 && al<=255) && (byte ptr[edi+edx-1]==22h || byte ptr[edi+edx-1]=="'")
jmp @sendkey
.ENDIF
.ELSE
@sendkey:
invoke CallWindowProc,lpfnWndProc,handle1,uMsg1,wParam1,lParam1
.ENDIF
ret
WndProc endp
Posted on 2004-07-05 12:20:24 by diablo2oo2
It just needs some debugging. Sooo thats what we are going to do...
Lets start at the beginning: Minimal superclass of the edit control

Minimum superclass


EditWndProc PROC hEdit:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
invoke CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam
ret
EditWndProc endp


Compile and run. Control is superclassed and cut-and-paste still work.
Thus subclassing is not the issue. The problem *has* to be in the way
the routine is coded. Lets expand on this a little.

Expand


EditWndProc PROC hEdit:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
.if uMsg==WM_CHAR
mov eax,wParam
.if (al>="0" && al<="9") || (al>="A" && al<="F") || (al>="a" && al<="f") || al==VK_BACK
.if al>="a" && al<="f"
sub al,20h
invoke CallWindowProc,OldWndProc,hEdit,uMsg,eax,lParam
ret
.endif
.endif
.endif

invoke CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam
ret
EditWndProc endp


Ok so hows it doing now? Getting better actually. It does no filtering on the
characters yet, but any lower case charater from a-f is changed to A-F and we
can still cut-and-paste. No problems yet. Lets add some filtering...



EditWndProc PROC hEdit:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
.if uMsg==WM_CHAR
mov eax,wParam
.if (al>="0" && al<="9") || (al>="A" && al<="F") || (al>="a" && al<="f") || al==VK_BACK
.if al>="a" && al<="f"
sub al,20h
invoke CallWindowProc,OldWndProc,hEdit,uMsg,eax,lParam
ret
.endif
.else
xor eax, eax
ret
.endif
.endif

invoke CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam
ret
EditWndProc endp


Now? Well now it filters out all non hex characters ... OOPS, cut and paste broke.
So the whole issue lies with the character filter... Lets check the docs :alright:


WM_CHAR

Remarks
Because there is not necessarily a one-to-one correspondence between keys pressed
and character messages generated, the information in the high-order word of the lKeyData
parameter is generally not useful to applications. The information in the high-order word
applies only to the most recent WM_KEYDOWN message that precedes the posting of the
WM_CHAR message.


The ultimate problem with this is the phrase "not necessarily a one-to-one correspondence
between keys pressed". So when you hit the control key WM_CHAR is sent and the message
is eaten by the ret so the control never sees it. We need to check for this before hand so
the control will process it as normal.

Final


EditWndProc PROC hEdit:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
.if uMsg==WM_CHAR
invoke GetKeyState, VK_CONTROL
cmp eax, 0
jne ContinueProcessingKeys

mov eax,wParam
.if (al>="0" && al<="9") || (al>="A" && al<="F") || (al>="a" && al<="f") || al==VK_BACK
.if al>="a" && al<="f"
sub al,20h
invoke CallWindowProc,OldWndProc,hEdit,uMsg,eax,lParam
ret
.endif
.else
mov eax, 0
ret
.endif
.endif

ContinueProcessingKeys:
invoke CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam
ret
EditWndProc endp


Now this code works properly. I am sure the same technique will also work for your routine...
Cheers

Graebel
Posted on 2004-07-06 21:35:42 by Graebel
ok it so simple after reading your post. thank you very much.

ps: i already tryed GetKeyState, but i used it wrong.
Posted on 2004-07-07 11:02:01 by diablo2oo2