Limiting Characters in a Text Box
Posted 10 February 2003 - 00:08
Does anyone know how to limit the number of characters a user can put in in a text edit box?
I only want them to enter maximum 20 characters.
Posted 10 February 2003 - 16:03
However, worst case, you can always just add such checks to InstallScript code and don't allow them to continue until the entered text meets those requirements.
Posted 10 February 2003 - 22:28
The thing is I am using custom dialog boxes but it is also limiting in that case.
Posted 11 February 2003 - 01:58
If so, I'm certainly not an expert when it comes to comes to Custom dialogs by any means, so maybe somebody else can help you out.
Posted 11 February 2003 - 20:15
Posted 11 February 2003 - 22:46
How do we call a WinAPI from a custom dialog box?
Is there any documentation for it?
Thank you very much
Posted 12 February 2003 - 16:29
Each object on a form has an ID number. Globally define those ID’s first in the beginning of your script. In the example below we will use Dialog 12008, which is the “SdSelectFolder” dialog.
// Dialog and control IDs.
#define RES_DIALOG_ID 12008 // ID of Dialog itself
#define RES_PBUT_NEXT 1 // ID of 'Next' push button
#define RES_PBUT_CANCEL 9 // ID of 'Cancel' push button
#define RES_PBUT_BACK 12 // ID of 'Back' push button
#define RES_DIALOG_EDITBOX 301 // ID of edit box
#define RES_DIALOG_LISTBOX 401 // ID of list box
Within a local subroutine you will call the form to display. The code below displays the form and loops until the user selects a displayed path. If the length of the path-string in greater than 20 the user will see the message box. You might want to also include the string length check in the case RES_PBUT_NEXT: object. That way the user cannot advance to the next step if the string is longer than 20 characters.
// Create list of folders
list_FOLDERS = ListCreate ( STRINGLIST );
// BY DIRECTORY
FindAllDirs ( "C:\\SomeFolder", INCLUDE_SUBDIR, list_FOLDERS );
// Specify a name to identify the custom dialog in this setup.
szDialogName = "CustomDialog";
// Define the dialog. Pass a null string in the second parameter
// to get the dialog from _isuser.dll or _isres.dll. Pass a null
// string in the third parameter because the dialog is identified
// by its ID in the fourth parameter.
nResult = EzDefineDialog (szDialogName, "", "", RES_DIALOG_ID);
if (nResult < 0) then // Report an error; then terminate.
MessageBox ("Error in defining dialog", SEVERE);
// Initialize the indicator used to control the while loop.
bDone = FALSE;
// Loop until done.
// Display the dialog and return the next dialog event.
nCmdValue = WaitOnDialog(szDialogName); // Respond to the event.
// The user clicked the window's close button.
MessageBox ("Unable to display dialog. Setup canceled.", SEVERE);
// Place list of directories into list box
CtrlSetList( szDialogName, RES_DIALOG_LISTBOX, list_FOLDERS);
// Set the static text of the buttons.
CtrlSetText ( szDialogName, RES_PBUT_NEXT , "&Next");
CtrlSetText ( szDialogName, RES_PBUT_BACK , "&Back");
// Get the current list box selection.
CtrlGetCurSel (szDialogName, RES_DIALOG_LISTBOX, svSelection);
// Put the current selection in the edit box.
ParsePath( svDrive , svSelection ,PATH);
nStringLength = StrLength ( svSelection );
if nStringLength > 20 then
MessageBox ( "Please limit your entry to 20 characters in length.", INFORMATION);
CtrlSetText (szDialogName, RES_DIALOG_EDITBOX, svDrive);
case RES_PBUT_CANCEL: // The user clicked the Cancel button.
bDone = TRUE;
bDone = TRUE;
// Close the dialog box.
// Free the dialog box from memory.
// setup default status
Posted 12 February 2003 - 22:39
From you I also learnt how to handle the Cancel button.
I checked the InstallShield Docs and they said to use the OnCanceling() but that doesnt seem to work.
Posted 20 February 2003 - 10:42
In custom boxes you can specifically limit the size of an edit box with the following statement in the 'DLG_INIT' section of your custom script.
|SendMessage( GetDlgItem(hwndDialog,ID_FIELDNAME), EM_LIMITTEXT32, nMaxLength, 0);|
|#define EM_LIMITTEXT32 0x00c5|
#define EM_LIMITTEXT16 0x0415
at the begining of your project.
hwndDialog is the handle to your dialog box,
ID_FIELDNAME is the id of the editbox to limit, and
nMaxLength is the maximum number of characters.