I am again asking for help. All other times I've had good & useful advice. I am a PB learner with VB background, so some things are much different here. Previously, I had a powerful textbox input routine that could monitor keystrokes, etc. I could set any given textbox to receive SINGLE, DOUBLE, LONG, INTEGER, STRING, etc. with limits on min, max, field length, etc. The routine used the Got Focus event to set the parameters up for the SUB that tested keystrokes and then tested the full textbox entry when the user pressed CR or when the Lost Focus event occurred. With an invalid entry, the Lost Focus event popped up a message box with descriptive error and then returned the focus to the offending textbox. I could even monitor cut and paste operations.
Anyway, I want to do it here in PB, and once I get it right I'd be happy to post it to the downloads with commented directions within the file.
But I'm having a bit of a problem reading KeyDn. KeyAscii and KeyUp values. I've placed a test program below for anyone interested to patch up and make work.
Thanks (again) very much in advance.
Bob
+++++++++++++++++++++++++++++++++++++++++++++++++++
#PBFORMS CREATED V1.51
'------------------------------------------------------------------------------
' The first line in this file is a PB/Forms metastatement.
' It should ALWAYS be the first line of the file. Other
' PB/Forms metastatements are placed at the beginning and
' end of "Named Blocks" of code that should be edited
' with PBForms only. Do not manually edit or delete these
' metastatements or PB/Forms will not be able to reread
' the file correctly. See the PB/Forms documentation for
' more information.
' Named blocks begin like this: #PBFORMS BEGIN ...
' Named blocks end like this: #PBFORMS END ...
' Other PB/Forms metastatements such as:
' #PBFORMS DECLARATIONS
' are used by PB/Forms to insert additional code.
' Feel free to make changes anywhere else in the file.
'------------------------------------------------------------------------------
#COMPILE EXE
#DIM ALL
'------------------------------------------------------------------------------
' ** Includes **
'------------------------------------------------------------------------------
#PBFORMS BEGIN INCLUDES
#IF NOT %DEF(%WINAPI)
#INCLUDE "WIN32API.INC"
#ENDIF
#PBFORMS END INCLUDES
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' ** Constants **
'------------------------------------------------------------------------------
#PBFORMS BEGIN CONSTANTS
%IDD_DIALOG1 = 101
%IDC_CHECKBOX1 = 1001
%IDC_TEXTBOX1 = 1002
%IDC_TEXTBOX2 = 1003
%IDC_LABEL1 = 1004
%IDC_LABEL2 = 1005
#PBFORMS END CONSTANTS
'------------------------------------------------------------------------------
' ** Declarations **
'------------------------------------------------------------------------------
DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
#PBFORMS DECLARATIONS
'=====================================================================================================
'=====================================================================================================
' ** My Globals **
'=====================================================================================================
GLOBAL MyDlg AS DWORD
GLOBAL Txt AS STRING
'=====================================================================================================
'=====================================================================================================
' ** My Declarations **
'=====================================================================================================
DECLARE FUNCTION DispatchMessage LIB "USER32.DLL" ALIAS "DispatchMessageA" (lpMsg AS tagMSG) AS LONG
DECLARE FUNCTION TranslateMessage LIB "USER32.DLL" ALIAS "TranslateMessage" (lpMsg AS tagMSG) AS LONG
DECLARE FUNCTION GetMessage LIB "USER32.DLL" ALIAS "GetMessageA" (lpMsg AS tagMSG, BYVAL hWnd AS DWORD, BYVAL uMsgFilterMin AS DWORD, BYVAL uMsgFilterMax AS DWORD) AS LONG
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' ** Main Application Entry Point **
'------------------------------------------------------------------------------
FUNCTION PBMAIN()
ShowDIALOG1 %HWND_DESKTOP
END FUNCTION
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' ** CallBacks **
'------------------------------------------------------------------------------
CALLBACK FUNCTION ShowDIALOG1Proc()
LOCAL lpMsg AS tagMSG
LOCAL NULL AS DWORD
LOCAL TabChar AS STRING * 1
LOCAL RtnChar AS STRING * 2
NULL = 0
TabChar = CHR$(9)
RtnChar = CHR$(13) & CHR$(10)
SELECT CASE AS LONG CBMSG
CASE %WM_INITDIALOG
' Initialization handler
Txt = ""
CASE %WM_NCACTIVATE
STATIC hWndSaveFocus AS DWORD
IF ISFALSE CBWPARAM THEN
' Save control focus
hWndSaveFocus = GetFocus()
ELSEIF hWndSaveFocus THEN
' Restore control focus
SetFocus(hWndSaveFocus)
hWndSaveFocus = 0
END IF
CASE %WM_COMMAND
' Process control notifications
SELECT CASE AS LONG CBCTL
CASE %IDC_CHECKBOX1
CONTROL SET TEXT MyDlg, %IDC_TEXTBOX2, TRIM$(Txt)
CASE %IDC_TEXTBOX1
SELECT CASE CBCTLMSG
CASE %EN_SETFOCUS ' got focus event
'msgbox "Got Focus", %MB_TASKMODAL
Txt = Txt & "Got focus - 1" & TabChar & "CBCTLMSG=" & HEX$(CBCTLMSG) & TabChar & "CBMSG=" & HEX$(CBMSG) & RtnChar
CALL GetMessage(lpMsg, NULL, 0, 0) ' these 3 lines are probably wrong or in in the wrong place and maybe need to be put in a loop???
CALL TranslateMessage(lpMsg)
CALL DispatchMessage(lpMsg)
Txt = Txt & "Got focus - 2" & TabChar & "CBCTLMSG=" & HEX$(CBCTLMSG) & TabChar & "CBMSG=" & HEX$(CBMSG) & RtnChar
CONTROL SET TEXT MyDlg, %IDC_TEXTBOX2, Txt
CASE %EN_KILLFOCUS ' lost focus event
Txt = Txt & "Lost focus" & TabChar & "CBCTLMSG=" & HEX$(CBCTLMSG) & TabChar & "CBMSG=" & HEX$(CBMSG) & RtnChar
CONTROL SET TEXT MyDlg, %IDC_TEXTBOX2, Txt
CASE ELSE ' I sure would like to determine KeyDn, KeyAscii and Key Up !!!!
Txt = Txt & "Something else" & TabChar & "CBCTLMSG=" & HEX$(CBCTLMSG) & TabChar & "CBMSG=" & HEX$(CBMSG) & RtnChar
CONTROL SET TEXT MyDlg, %IDC_TEXTBOX2, Txt
END SELECT
CASE %IDC_TEXTBOX2
CASE %IDC_LABEL1
CASE %IDC_LABEL2
END SELECT
END SELECT
END FUNCTION
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' ** Dialogs **
'------------------------------------------------------------------------------
FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
LOCAL lRslt AS LONG
#PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
LOCAL hDlg AS DWORD
DIALOG NEW hParent, "TbInputTest", 451, 116, 396, 346, %WS_POPUP OR _
%WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _
%WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
%DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
CONTROL ADD CHECKBOX, hDlg, %IDC_CHECKBOX1, "This checkbox has no purpose " + _
"other than to receive and lose focus.", 15, 12, 228, 12
CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 15, 42, 114, 12, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _
%ES_LEFT OR %ES_AUTOHSCROLL, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR _
%WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX2, "", 15, 72, 369, 258, _
%WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %WS_HSCROLL OR %WS_VSCROLL OR _
%ES_LEFT OR %ES_AUTOVSCROLL OR %ES_READONLY OR %ES_MULTILINE, _
%WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
%WS_EX_RIGHTSCROLLBAR
CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "Type Input Here", 15, 33, 117, 9
CONTROL ADD LABEL, hDlg, %IDC_LABEL2, "Receive Textbox Messages Here", 15, 63, 117, 9
#PBFORMS END DIALOG
MyDlg = hDlg ' Save handle to dialog
DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
#PBFORMS BEGIN CLEANUP %IDD_DIALOG1
#PBFORMS END CLEANUP
FUNCTION = lRslt
END FUNCTION
'------------------------------------------------------------------------------
Anyway, I want to do it here in PB, and once I get it right I'd be happy to post it to the downloads with commented directions within the file.
But I'm having a bit of a problem reading KeyDn. KeyAscii and KeyUp values. I've placed a test program below for anyone interested to patch up and make work.
Thanks (again) very much in advance.
Bob
+++++++++++++++++++++++++++++++++++++++++++++++++++
#PBFORMS CREATED V1.51
'------------------------------------------------------------------------------
' The first line in this file is a PB/Forms metastatement.
' It should ALWAYS be the first line of the file. Other
' PB/Forms metastatements are placed at the beginning and
' end of "Named Blocks" of code that should be edited
' with PBForms only. Do not manually edit or delete these
' metastatements or PB/Forms will not be able to reread
' the file correctly. See the PB/Forms documentation for
' more information.
' Named blocks begin like this: #PBFORMS BEGIN ...
' Named blocks end like this: #PBFORMS END ...
' Other PB/Forms metastatements such as:
' #PBFORMS DECLARATIONS
' are used by PB/Forms to insert additional code.
' Feel free to make changes anywhere else in the file.
'------------------------------------------------------------------------------
#COMPILE EXE
#DIM ALL
'------------------------------------------------------------------------------
' ** Includes **
'------------------------------------------------------------------------------
#PBFORMS BEGIN INCLUDES
#IF NOT %DEF(%WINAPI)
#INCLUDE "WIN32API.INC"
#ENDIF
#PBFORMS END INCLUDES
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' ** Constants **
'------------------------------------------------------------------------------
#PBFORMS BEGIN CONSTANTS
%IDD_DIALOG1 = 101
%IDC_CHECKBOX1 = 1001
%IDC_TEXTBOX1 = 1002
%IDC_TEXTBOX2 = 1003
%IDC_LABEL1 = 1004
%IDC_LABEL2 = 1005
#PBFORMS END CONSTANTS
'------------------------------------------------------------------------------
' ** Declarations **
'------------------------------------------------------------------------------
DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
#PBFORMS DECLARATIONS
'=====================================================================================================
'=====================================================================================================
' ** My Globals **
'=====================================================================================================
GLOBAL MyDlg AS DWORD
GLOBAL Txt AS STRING
'=====================================================================================================
'=====================================================================================================
' ** My Declarations **
'=====================================================================================================
DECLARE FUNCTION DispatchMessage LIB "USER32.DLL" ALIAS "DispatchMessageA" (lpMsg AS tagMSG) AS LONG
DECLARE FUNCTION TranslateMessage LIB "USER32.DLL" ALIAS "TranslateMessage" (lpMsg AS tagMSG) AS LONG
DECLARE FUNCTION GetMessage LIB "USER32.DLL" ALIAS "GetMessageA" (lpMsg AS tagMSG, BYVAL hWnd AS DWORD, BYVAL uMsgFilterMin AS DWORD, BYVAL uMsgFilterMax AS DWORD) AS LONG
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' ** Main Application Entry Point **
'------------------------------------------------------------------------------
FUNCTION PBMAIN()
ShowDIALOG1 %HWND_DESKTOP
END FUNCTION
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' ** CallBacks **
'------------------------------------------------------------------------------
CALLBACK FUNCTION ShowDIALOG1Proc()
LOCAL lpMsg AS tagMSG
LOCAL NULL AS DWORD
LOCAL TabChar AS STRING * 1
LOCAL RtnChar AS STRING * 2
NULL = 0
TabChar = CHR$(9)
RtnChar = CHR$(13) & CHR$(10)
SELECT CASE AS LONG CBMSG
CASE %WM_INITDIALOG
' Initialization handler
Txt = ""
CASE %WM_NCACTIVATE
STATIC hWndSaveFocus AS DWORD
IF ISFALSE CBWPARAM THEN
' Save control focus
hWndSaveFocus = GetFocus()
ELSEIF hWndSaveFocus THEN
' Restore control focus
SetFocus(hWndSaveFocus)
hWndSaveFocus = 0
END IF
CASE %WM_COMMAND
' Process control notifications
SELECT CASE AS LONG CBCTL
CASE %IDC_CHECKBOX1
CONTROL SET TEXT MyDlg, %IDC_TEXTBOX2, TRIM$(Txt)
CASE %IDC_TEXTBOX1
SELECT CASE CBCTLMSG
CASE %EN_SETFOCUS ' got focus event
'msgbox "Got Focus", %MB_TASKMODAL
Txt = Txt & "Got focus - 1" & TabChar & "CBCTLMSG=" & HEX$(CBCTLMSG) & TabChar & "CBMSG=" & HEX$(CBMSG) & RtnChar
CALL GetMessage(lpMsg, NULL, 0, 0) ' these 3 lines are probably wrong or in in the wrong place and maybe need to be put in a loop???
CALL TranslateMessage(lpMsg)
CALL DispatchMessage(lpMsg)
Txt = Txt & "Got focus - 2" & TabChar & "CBCTLMSG=" & HEX$(CBCTLMSG) & TabChar & "CBMSG=" & HEX$(CBMSG) & RtnChar
CONTROL SET TEXT MyDlg, %IDC_TEXTBOX2, Txt
CASE %EN_KILLFOCUS ' lost focus event
Txt = Txt & "Lost focus" & TabChar & "CBCTLMSG=" & HEX$(CBCTLMSG) & TabChar & "CBMSG=" & HEX$(CBMSG) & RtnChar
CONTROL SET TEXT MyDlg, %IDC_TEXTBOX2, Txt
CASE ELSE ' I sure would like to determine KeyDn, KeyAscii and Key Up !!!!
Txt = Txt & "Something else" & TabChar & "CBCTLMSG=" & HEX$(CBCTLMSG) & TabChar & "CBMSG=" & HEX$(CBMSG) & RtnChar
CONTROL SET TEXT MyDlg, %IDC_TEXTBOX2, Txt
END SELECT
CASE %IDC_TEXTBOX2
CASE %IDC_LABEL1
CASE %IDC_LABEL2
END SELECT
END SELECT
END FUNCTION
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' ** Dialogs **
'------------------------------------------------------------------------------
FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
LOCAL lRslt AS LONG
#PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
LOCAL hDlg AS DWORD
DIALOG NEW hParent, "TbInputTest", 451, 116, 396, 346, %WS_POPUP OR _
%WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _
%WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
%DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
CONTROL ADD CHECKBOX, hDlg, %IDC_CHECKBOX1, "This checkbox has no purpose " + _
"other than to receive and lose focus.", 15, 12, 228, 12
CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 15, 42, 114, 12, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _
%ES_LEFT OR %ES_AUTOHSCROLL, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR _
%WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX2, "", 15, 72, 369, 258, _
%WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %WS_HSCROLL OR %WS_VSCROLL OR _
%ES_LEFT OR %ES_AUTOVSCROLL OR %ES_READONLY OR %ES_MULTILINE, _
%WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
%WS_EX_RIGHTSCROLLBAR
CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "Type Input Here", 15, 33, 117, 9
CONTROL ADD LABEL, hDlg, %IDC_LABEL2, "Receive Textbox Messages Here", 15, 63, 117, 9
#PBFORMS END DIALOG
MyDlg = hDlg ' Save handle to dialog
DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
#PBFORMS BEGIN CLEANUP %IDD_DIALOG1
#PBFORMS END CLEANUP
FUNCTION = lRslt
END FUNCTION
'------------------------------------------------------------------------------
Comment