Hi !
I have a littlte problem in using the classic Hutch's subclassing example:
; ===============================================================
; Title: EdDec.inc
; ================================================================
DEF_EdDec struc
dCtlID DWORD ? ;Contol ID
dStyle DWORD ? ;Style
dExStyle DWORD ? ;Extended style
pTitle PSTRING ? ;-> Window title
sdPosX SDWORD ? ;X position
sdPosY SDWORD ? ;Y position
dWidth DWORD ? ;Width
dHeight DWORD ? ;Height
DEF_EdDec ends
PDEF_EdDec typedef ptr DEF_EdDec
; —————————————————————————————————————————————————
; Object: EdiDec
; Purpose: Implement a thin wrapper around the Edit GDI object.
Object EdDec, , WinControl ;Class "Edit"
RedefineMethod Done
RedefineMethod Init, POINTER, HWND, PDEF_EdDec
RedefineMethod WndProc, DWORD, WPARAM, LPARAM
ObjectEnd
; ===========================================================
if IMPLEMENT
; ————————————————————————————————————————————————
; Method: Edit.Done
; Purpose: Finalize the Edit object.
; Arguments: None.
; Return: Nothing.
Method EdDec.Done, uses esi
SetObject esi
Unsubclass EdDec ;Uses esi
ACall esi.Done
MethodEnd
; ——————————————————————————————————————————————————
; Method: EdiDec.Init
; Purpose: Initialize the Edit object.
; Arguments: Arg1: -> Owner object.
; Arg2: Parent window HANDLE.
; Arg3: -> DEF_Edit initialization structure.
; Return: Nothing.
Method EdDec.Init, uses esi, pOwner:POINTER, hParent:HWND, pDefStruc:PDEF_EdDec
SetObject esi
mov ecx, pDefStruc
assume ecx:PDEF_EdDec
mov eax, [ecx].dStyle
or eax, WS_VISIBLE or WS_CHILD or \
ES_AUTOHSCROLL or ES_NOHIDESEL
invoke CreateWindowEx, [ecx].dExStyle, $OfsCStr("EDIT"), [ecx].pTitle, eax, \
[ecx].sdPosX, [ecx].sdPosY, [ecx].dWidth, [ecx].dHeight, \
hParent, [ecx].dCtlID, hInstance, 0
assume ecx:NOTHING
ACall esi.Init, pOwner, eax
Subclass EdDec ;Uses esi
MethodEnd
; —————————————————————————————————————————————————————
; Method: EdiDec.WndProc
; Purpose: Processing of window messages. Before invoking it, the window must be subclassed.
; Arguments: Arg1: Message identifier.
; Arg2: First message parameter.
; Arg3: Second message parameter.
; Return: eax = This value is the result of the message processing and depends on the message ID.
; Note: Window HANDLE is passed in pSelf (hidden argument).
Method EdDec.WndProc,, uMsg:DWORD, wParam:WPARAM, lParam:LPARAM
LOCAL Buffer[32]:BYTE ; numeros con decimales
SetObject ebx
.if uMsg == WM_CHAR
.if wParam == 8 ; backspace
jmp accept
.endif
.if wParam == "." ; only allow one decimal point
; * * * T R O U B L E H E R E
; Hutch's line
invoke SendMessage, [ebx].hWnd, WM_GETTEXT, sizeof Buffer, ADDR Buffer
mov ecx, sizeof Buffer ; byte count in ecx
lea esi, Buffer ; address in esi
@xxx:
lodsb ; load byte into al
cmp al, "." ; if decimal point already in Buffer
jne @xx1
return 0 ; throw it away
@xx1:
dec ecx
cmp ecx, 0
jne @xxx
jmp accept
.endif
.if wParam < "0"
return 0
.endif
.if wParam > "9"
return 0
.endif
.endif
accept:
GetSubclassingInst EdDec, pSelf
OCall eax::EdDec.Dispatch, pSelf, uMsg, wParam, lParam
MethodEnd
endif
Ok. Not a little problem: the program crash when invoke SendMessage for string retrieving.
Thanks. HSE