An input box routine with the capacity to filter characters
Additional functions: ESC to exit without saving; ENTER to accept; CTRL/N to clear input.
Implementing a greater degree of control for specific uses would be simple, using a method such as this.
A time and date setting routine, for instance, moving with TAB or cursor keys to edit strictly defined areas with strictly controlled input.
'
Additional functions: ESC to exit without saving; ENTER to accept; CTRL/N to clear input.
Implementing a greater degree of control for specific uses would be simple, using a method such as this.
A time and date setting routine, for instance, moving with TAB or cursor keys to edit strictly defined areas with strictly controlled input.
'
Code:
#COMPILE EXE #DIM ALL #INCLUDE "Win32API.inc" ENUM Controls SINGULAR Btn_txt = 500 Btn_num Lbl_txt Lbl_num END ENUM FUNCTION PBMAIN() AS LONG LOCAL hDlg AS LONG DIALOG NEW PIXELS, 0, "Graphic InputBox", 300, 300, 320, 100, %WS_SYSMENU TO hDlg CONTROL ADD BUTTON, hDlg, %Btn_txt, "Get Text", 5, 5, 70, 25 CONTROL ADD BUTTON, hDlg, %Btn_num, "Get Number", 5, 50, 70, 25 CONTROL ADD LABEL, hDlg, %Lbl_txt, "Text Label ", 80, 10, 250, 40 CONTROL ADD LABEL, hDlg, %Lbl_num, "Number Label", 80, 55, 250, 40 DIALOG SHOW MODAL hDlg CALL DlgProc END FUNCTION CALLBACK FUNCTION DlgProc() LOCAL dflttxt, inputname AS STRING LOCAL limit AS LONG SELECT CASE CB.MSG CASE %WM_INITDIALOG CASE %WM_COMMAND SELECT CASE AS LONG CB.CTL CASE = %IDCANCEL DIALOG END CB.HNDL CASE %Btn_txt CONTROL SET TEXT CB.HNDL, %Lbl_txt, _ CustomInputBox(CB.HNDL, %Lbl_txt, "Enter any regular keyboard data. No caps.", _ "`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./[email protected]#$%^&*()_+{}:<>? ") CASE %Btn_num CONTROL SET TEXT CB.HNDL, %Lbl_num, _ CustomInputBox(CB.HNDL, %Lbl_num, "Enter numerical data.", _ "1234567890-+$,.") END SELECT END SELECT END FUNCTION '|_|_|_|_| Begin Custom Graphic Input Box ENUM CIB_controls SINGULAR CIB_lbl = 16001 CIB_gfx CIB_filter inputtimer END ENUM FUNCTION CustomInputBox(hParent AS LONG, ctrl AS LONG, title AS STRING, filter AS STRING) AS STRING 'get the parent dialog handle, control handle to which input is connected, 'title of the input box, allowed characters LOCAL dlginfo, result AS STRING LOCAL hDlg, exit_code AS LONG DIALOG DISABLE hParent 'disable parent dialog CONTROL GET TEXT hParent, ctrl TO result DIALOG NEW PIXELS, hParent, "", 10, 10, 300, 65, %WS_POPUP OR %WS_BORDER TO hDlg exit_code = VARPTR(result) DIALOG SET USER hDlg, 1, exit_code DIALOG SET COLOR hDlg, %BLACK, %RGB_THISTLE CONTROL ADD LABEL, hDlg, %CIB_lbl, " " + title + $CR + " ENTER = accept; ESC = exit; CTRL/N = clear", 5, 5, 290, 30 CONTROL ADD LABEL, hDlg, %CIB_filter, filter, -50, -50, 1, 1 CONTROL SET COLOR hDlg, %CIB_lbl, %WHITE, %RGB_DEEPSKYBLUE CONTROL ADD GRAPHIC, hDlg, %CIB_gfx, result, 5, 40, 290, 20, %SS_NOTIFY DIALOG SHOW MODAL hDlg CALL graphicInputBoxProc TO exit_code DIALOG ENABLE hParent CONTROL SET FOCUS hParent, ctrl FUNCTION = result END FUNCTION CALLBACK FUNCTION GraphicInputBoxProc() DIM txtIn AS STRING POINTER LOCAL tempstr, in_char AS STRING LOCAL utilvar AS LONG SELECT CASE CB.MSG CASE %WM_INITDIALOG CONTROL GET TEXT CB.HNDL, %CIB_gfx TO tempstr GRAPHIC ATTACH CB.HNDL, %CIB_gfx GRAPHIC COLOR %BLACK, %RGB_GAINSBORO GRAPHIC CLEAR GRAPHIC SET LOC 3,3 GRAPHIC PRINT tempstr settimer(CB.HNDL, %inputtimer, 100, 0) GRAPHIC DETACH CASE %WM_TIMER 'input routine CONTROL SET FOCUS CB.HNDL, %CIB_gfx GRAPHIC ATTACH CB.HNDL, %CIB_gfx GRAPHIC INKEY$ TO in_char IF in_char <> "" THEN SELECT CASE in_char CASE CHR$(8) CONTROL GET TEXT CB.HNDL, %CIB_gfx TO tempstr utilvar = LEN(tempstr) SELECT CASE utilvar CASE > 1: tempstr = LEFT$(tempstr, utilvar - 1) CASE 1: tempstr = "" END SELECT CONTROL SET TEXT CB.HNDL, %CIB_gfx, tempstr CASE CHR$(13) DIALOG GET USER CB.HNDL, 1 TO txtIn CONTROL GET TEXT CB.HNDL, %CIB_gfx TO tempstr 'retrieve edited string. @txtIn = tempstr 'assign value to string in calling function killtimer(CB.HNDL, %inputtimer) 'kill input timer DIALOG END CB.HNDL, 13 EXIT FUNCTION CASE CHR$(14) tempstr = "": CONTROL SET TEXT CB.HNDL, %CIB_gfx, tempstr CASE CHR$(27) DIALOG END CB.HNDL, 27 EXIT FUNCTION CASE ELSE CONTROL GET TEXT CB.HNDL, %CIB_filter TO tempstr 'get the filter string IF INSTR(tempstr, in_char) THEN 'test to see if charater is allowed CONTROL GET TEXT CB.HNDL, %CIB_gfx TO tempstr 'get the string to edit tempstr += in_char 'add character CONTROL SET TEXT CB.HNDL, %CIB_gfx, tempstr 'update string END IF END SELECT GRAPHIC DETACH END IF CONTROL GET TEXT CB.HNDL, %CIB_gfx TO tempstr CONTROL GET USER CB.HNDL, %CIB_gfx, 1 TO utilvar GRAPHIC ATTACH CB.HNDL, %CIB_gfx, REDRAW GRAPHIC CLEAR GRAPHIC SET POS (3,3) GRAPHIC PRINT tempstr; INCR utilvar IF utilvar > 4 THEN GRAPHIC PRINT "_ "; CONTROL SET USER CB.HNDL, %CIB_gfx, 1, 0 ELSE GRAPHIC PRINT " "; CONTROL SET USER CB.HNDL, %CIB_gfx, 1, utilvar END IF GRAPHIC REDRAW GRAPHIC DETACH END SELECT END FUNCTION '|_|_|_|_| End Custom Graphic Input Box '