Hi
I have a question to subclass an edit field
Subclass a one edit with a one function works fine and i have long works with this.
By my new project need i a subclass with one edit Two function by button click.
I have try with a option function this option set i by button click of hOption 1 or 0
EditSubclass PROC hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL EditOldProc :DWORD
invoke GetWindowLong,hWnd,GWL_USERDATA
mov EditOldProc,eax
.if uMsg==WM_CHAR
mov eax,wParam
.If hOption==0
.if (al>="0" && al<="9")
invoke CallWindowProc,EditOldProc,hWnd,uMsg,eax,lParam
ret
.endif
.endif
...
.
.
Gives a any api or example for this or can i Destroy a subclass
and make a new subclass?
Thanks in forward
Could you be more specific?
Yes
I have an subclasses edit field this works only from A-Z by WM_CHAR
and i add a two subclasses routine this works by WM_CHAR from 0-9
If i check a button disable this first subclass1 (A-Z WM_CHAR)
and enable subclass2 (0-9 WM_CHAR)
This edit field uses only 0-9
If Not checked this button disable 0-9 subclass2 and enable subclass1 (A-Z WM_CHAR)
And this 2 subclasses works only with a one editfield
I hope you have understand this if not,can i make an example!?
I guess you found the solution. The hOption value should work like a switch. Hitting the button will modify the value of this variable to switch between the two subclassing options.
No i have not found a solution this works not
I have think this works with a hOption switsh
Here this mean i
invoke IsDlgButtonChecked,hWnd,1002
.if eax ==TRUE
invoke SetWindowLong,hEdit,GWL_WNDPROC,addr EditWndProc
invoke SetWindowLong,hEdit,GWL_USERDATA,eax
.else
invoke SetWindowLong,hEdit,GWL_WNDPROC,addr EditWndProc1
invoke SetWindowLong,hEdit,GWL_USERDATA,eax
.endif
EditWndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL EditOldProc :DWORD
invoke GetWindowLong,hWnd,GWL_USERDATA
mov EditOldProc,eax
.if uMsg==WM_CHAR
mov eax,wParam
.if (al>="A" && al<="Z") || (al>="a" && al<="z")
.endif
.endif
invoke CallWindowProc,EditOldProc,hWnd,uMsg,wParam,lParam
ret
EditWndProc endp
EditWndProc1 proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL EditOldProc :DWORD
invoke GetWindowLong,hWnd,GWL_USERDATA
mov EditOldProc,eax
.if uMsg==WM_CHAR
mov eax,wParam
.if (al>="0" && al<="9")
.endif
.endif
invoke CallWindowProc,EditOldProc,hWnd,uMsg,wParam,lParam
ret
EditWndProc1 endp
Here is this what i have trying
Wm_INIT_DIALOG
invoke SetWindowLong,hEdit,GWL_WNDPROC,addr EditWndProc
invoke SetWindowLong,hEdit,GWL_USERDATA,eax
WM_COMMAND
invoke IsDlgButtonChecked,hWnd,1002
.if eax ==TRUE
mov hOption,1
.else
mov hOption,0
.endif
EditWndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL EditOldProc :DWORD
invoke GetWindowLong,hWnd,GWL_USERDATA
mov EditOldProc,eax
.if uMsg==WM_CHAR
mov eax,wParam
.if hOption==1
.if (al>="A" && al<="Z") || (al>="a" && al<="z")
.endif
.else
.if (al>="0" && al<="9")
.endif
.endif
.endif
invoke CallWindowProc,EditOldProc,hWnd,uMsg,wParam,lParam
ret
EditWndProc endp
Hi ragdog,
Your subclassing routine is flawed, it does not take care of messages like WM_PASTE and therefore allows you insert invalid characters into the edit using context menu paste and CTRL-V. For this reason ES_NUMBER is pretty much useless, if you need only numbers and your program is relying on that data there is a chance (depending on what you do with the input) of triggering an exception.
Yes i know Is only a quick example for help
My routine is finish i need only a function or api
for destroy this subclass and open a new subclass1
what mean you with "triggering a GPF"?
ragdog,
If you want to use the sme subclass for diferent controls, you need to select between different handles for different controls if they do different things. If you are filtering characters that are IDENTICAL you can use a common subclass without having to bother but if you use different algorithms for each or have different types of controls you need to separate them by using code like,
.if hWin == control1
; code
.elseif hWin == control2
etc ....
"control1" and "control2" are valid window handles for each control.
ragdog,
This is a quick example of what I think you are trying to do.
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
IDC_EDIT equ 100
IDC_BTN equ 101
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
hInstance dd 0
origEditProc dd 0
hwndEdit dd 0
filter dd 0
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
EditProc proc hwnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
SWITCH uMsg
CASE WM_CHAR
.IF wParam == 13
invoke CallWindowProc, origEditProc, hwnd, uMsg, wParam, lParam
.ENDIF
.IF filter
.IF (wParam>="A" && wParam<="Z") || (wParam>="a" && wParam<="z")
invoke CallWindowProc, origEditProc, hwnd, uMsg, wParam, lParam
.ENDIF
.ELSE
.IF (wParam>="0" && wParam<="9")
invoke CallWindowProc, origEditProc, hwnd, uMsg, wParam, lParam
.ENDIF
.ENDIF
CASE WM_PASTE
; This effectively disables the WM_PASTE message,
; preventing the user from pasting characters.
DEFAULT
invoke CallWindowProc, origEditProc, hwnd, uMsg, wParam, lParam
ENDSW
ret
EditProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
DlgProc proc hwndDlg:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
SWITCH uMsg
CASE WM_INITDIALOG
invoke GetDlgItem, hwndDlg, IDC_EDIT
mov hwndEdit, eax
invoke SetWindowLong, hwndEdit, GWL_WNDPROC, EditProc
mov origEditProc, eax
CASE WM_COMMAND
SWITCH wParam
CASE IDC_BTN
not filter
invoke SetFocus, hwndEdit
CASE IDCANCEL
invoke EndDialog, hwndDlg, 0
ENDSW
CASE WM_CLOSE
invoke EndDialog, hwndDlg, 0
ENDSW
return 0
DlgProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
Dialog "TEST","MS Sans Serif",10, \
WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \
2,0,0,100,80,1024
DlgEdit WS_BORDER or ES_MULTILINE or ES_WANTRETURN or WS_TABSTOP or \
WS_HSCROLL or WS_VSCROLL or ES_AUTOVSCROLL or ES_AUTOVSCROLL, \
5,5,87,40,IDC_EDIT
DlgButton "Switch Filter",WS_TABSTOP,26,53,45,10,IDC_BTN
CallModalDialog hInstance,0,DlgProc,NULL
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
[attachment deleted by admin]
Thanks to all
This is it from MichaelW Thanks
I have on a vb source found close a subclass
This start a subclass
invoke SetWindowLong, hEdit,GWL_WNDPROC,addr EditWndProc
mov PrevWndProc, eax
close
invoke SetWindowLong,hWnd, GWL_WNDPROC, PrevWndProc
Greets,