While searching for subclass examples i found this.
It was originally written by Sapero.
$include "Api\\allapi.inc"
Const EDIT_1 = 1
Const EDIT_2 = 2
Const EDIT_3 = 3
Const EDIT_4 = 4
Const EDIT_5 = 5
Const EDIT_6 = 6
Const EDIT_7 = 7
Const EDIT_8 = 8
Const EDIT_9 = 9
Const EDIT_10 = 10
Const BUTTON_11 = 11
Const BUTTON_12 = 12
Window d1
OpenWindow d1,0,0,310,320,0,0,"enter tabbing",&d1_handler
Control d1,@Edit,"Edit1",19,14,265,20,0x50810080,EDIT_1
Control d1,@Edit,"Edit2",19,37,265,20,0x50810080,EDIT_2
Control d1,@Edit,"Edit3",19,60,265,20,0x50810080,EDIT_3
SubclassNumEdit(d1,EDIT_3)
Control d1,@Edit,"Edit4",19,83,265,20,0x50810080,EDIT_4
Control d1,@Edit,"Edit5",19,106,265,20,0x50810080,EDIT_5
Control d1,@Edit,"Edit6",19,129,265,20,0x50810080,EDIT_6
Control d1,@Edit,"Edit7",19,152,265,20,0x50810080,EDIT_7
Control d1,@Edit,"Edit8",19,175,265,20,0x50810080,EDIT_8
Control d1,@Edit,"Edit9",19,198,265,20,0x50810080,EDIT_9
Control d1,@Edit,"Edit10",19,221,265,20,0x50810080,EDIT_10
Control d1,@SysButton,"OK",216,252,70,23,0x50010000,BUTTON_11
Control d1,@SysButton,"Cancel",142,252,70,23,0x50010000,BUTTON_12
For x = EDIT_1 To EDIT_10
SetControlNotify(d1,x,1,1)
Next x
SetFocus d1,EDIT_1
WaitUntil d1 = 0
End
Sub d1_handler
Select @Message
Case @IDControl
If @ControlID >= EDIT_1 AND @ControlID <= EDIT_10
' set the focus of the next control
If @NotifyCode = @ENENTERKEY OR @NotifyCode = @ENTABKEY
SetFocus d1,@ControlID + 1
EndIf
' set the background color of the edit control
If @NotifyCode = @ENKillFocus
SetControlColor d1,@ControlID,0,0xFFFFFF
EndIf
If @NotifyCode = @ENSetFocus
SetControlColor d1,@ControlID,0,0xF0FFE0
EndIf
EndIf
Case @IDCreate
CenterWindow d1
Case @IDCloseWindow
CloseWindow d1
EndSelect
Return
EndSub
SUB SubclassNumEdit(parent as WINDOW,id as INT)
hEdit = GETCONTROLHANDLE(parent,id)
lpfn = SetWindowLongA(hEdit,-4,&numEditHandler)
'save the old handler as a property in the edit control
'this way we don't need any global variables
SetPropA(hEdit,"edit_handler",lpfn)
RETURN
ENDSUB
SUB UnSubclassNumEdit(parent as WINDOW,id as INT)
'restore the old handler and remove the property
hEdit = GETCONTROLHANDLE(parent,id)
SetWindowLongA(hEdit,-4,GetPropA(hEdit,"edit_handler"))
RemovePropA(hEdit,"edit_handler")
RETURN
ENDSUB
SUB numEditHandler(hwnd:int,uMsg:int,wParam:int,lParam:pointer),int
SELECT uMsg
CASE @IDCHAR
IF ((wParam < 0x30) OR (wParam > 0x39)) AND (wParam <> ASC(".")) AND (wParam <> 0x08) THEN RETURN 1
ENDSELECT
RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
ENDSUB
Sorry, but where do I find "allapi.inc" file?
It appears to be missing in my PC. Is it related to Vista, maybe?
Yours Carlo
Hi Dossic!
"allapi.inc" is a header that calls several other headers.
Here's a version that doesn't need the include file:
DECLARE IMPORT,CallWindowProcA(lpPrevWndFunc:INT,hWnd:INT,Msg:INT,wParam:INT,lParam:INT),INT
DECLARE IMPORT,SetWindowLongA(hWnd:INT,nIndex:INT,dwNewLong:INT),INT
DECLARE IMPORT,SetPropA(hWnd:UINT,lpString:STRING,hData:UINT),INT
DECLARE IMPORT,GetPropA(hWnd:UINT,lpString:STRING),UINT
DECLARE IMPORT,RemovePropA(hWnd:UINT,lpString:STRING),UINT
CONST EDIT_1 = 1
CONST EDIT_2 = 2
CONST EDIT_3 = 3
CONST EDIT_4 = 4
CONST EDIT_5 = 5
CONST EDIT_6 = 6
CONST EDIT_7 = 7
CONST EDIT_8 = 8
CONST EDIT_9 = 9
CONST EDIT_10 = 10
CONST BUTTON_11 = 11
CONST BUTTON_12 = 12
WINDOW d1
OPENWINDOW d1,0,0,310,320,0,0,"Enter Tabbing",&d1_handler
CONTROL d1,@EDIT,"Edit1",19,14,265,20,0x50810080,EDIT_1
CONTROL d1,@EDIT,"Edit2",19,37,265,20,0x50810080,EDIT_2
CONTROL d1,@EDIT,"Edit3",19,60,265,20,0x50810080,EDIT_3
SubclassNumEdit(d1,EDIT_3)
CONTROL d1,@EDIT,"Edit4",19,83,265,20,0x50810080,EDIT_4
CONTROL d1,@EDIT,"Edit5",19,106,265,20,0x50810080,EDIT_5
CONTROL d1,@EDIT,"Edit6",19,129,265,20,0x50810080,EDIT_6
CONTROL d1,@EDIT,"Edit7",19,152,265,20,0x50810080,EDIT_7
CONTROL d1,@EDIT,"Edit8",19,175,265,20,0x50810080,EDIT_8
CONTROL d1,@EDIT,"Edit9",19,198,265,20,0x50810080,EDIT_9
CONTROL d1,@EDIT,"Edit10",19,221,265,20,0x50810080,EDIT_10
CONTROL d1,@SYSBUTTON,"Cancel",142,252,70,23,0x50010000,BUTTON_11
CONTROL d1,@SYSBUTTON,"OK",216,252,70,23,0x50010000,BUTTON_12
FOR x = EDIT_1 TO EDIT_10
SETCONTROLNOTIFY(d1,x,1,1)
SETFONT d1,"MS Sans Serif",8,400,0,x
NEXT x
SETFOCUS d1,EDIT_1
WAITUNTIL d1 = 0
END
SUB d1_handler
SELECT @MESSAGE
CASE @IDCONTROL
IF @CONTROLID >= EDIT_1 AND @CONTROLID <= EDIT_10
'Set the focus of the next control
IF @NOTIFYCODE = @ENENTERKEY OR @NOTIFYCODE = @ENTABKEY
SETFOCUS d1,@CONTROLID + 1
ENDIF
'Set the background color of the edit control
IF @NOTIFYCODE = @ENKILLFOCUS
SETCONTROLCOLOR d1,@CONTROLID,0,0xFFFFFF
ENDIF
IF @NOTIFYCODE = @ENSETFOCUS
SETCONTROLCOLOR d1,@CONTROLID,0,0xFFC94B
ENDIF:ENDIF
IF @CONTROLID = BUTTON_12
CLOSEWINDOW d1
ENDIF
CASE @IDCREATE
CENTERWINDOW d1
CASE @IDCLOSEWINDOW
CLOSEWINDOW d1
ENDSELECT
RETURN:ENDSUB
SUB SubclassNumEdit(parent:WINDOW,id:INT)
hEdit = GETCONTROLHANDLE(parent,id)
lpFn = SetWindowLongA(hEdit,-4,&numEditHandler)
'Save the old handler as a property in the edit control, this way we don't need any global variables
SetPropA(hEdit,"edit_handler",lpFn)
RETURN:ENDSUB
SUB UnSubclassNumEdit(parent:WINDOW,id:INT)
'Restore the old handler and remove the property
hEdit = GETCONTROLHANDLE(parent,id)
SetWindowLongA(hEdit,-4,GetPropA(hEdit,"edit_handler"))
RemovePropA(hEdit,"edit_handler")
RETURN:ENDSUB
SUB numEditHandler(hWnd:INT,uMsg:INT,wParam:INT,lParam:POINTER),INT
SELECT uMsg
CASE @IDCHAR
IF ((wParam < 0x30) OR (wParam > 0x39)) AND (wParam <> ASC(".")) AND (wParam <> 0x08) THEN RETURN 1
ENDSELECT
RETURN CallWindowProcA(GetPropA(hWnd,"edit_handler"),hWnd,uMsg,wParam,lParam):ENDSUB
Brian