Hi,
Does anyone know how to limit the number of characters a user can put in in a text edit box?
For example,
I only want them to enter maximum 20 characters.
Help needed!!
Thankyou
This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Limiting Characters in a Text Box
Started by
mouy
, Feb 10 2003 00:08
9 replies to this topic
Posted 10 February 2003 - 16:03
Probably can do it in a custom dialog, but unfortunately I've never messed with those.
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.
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
Hi,
The thing is I am using custom dialog boxes but it is also limiting in that case.
Thanks anyways.
The thing is I am using custom dialog boxes but it is also limiting in that case.
Thanks anyways.
Posted 11 February 2003 - 01:58
If follow you right, you're saying that you're already using a custom dialog, but that wasn't sufficient, so your still doing the InstallScript checks. Is that correct?
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.
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
There's a WinAPI call (can't recall which one) that can be used to set a character limit on a edit box. You would call it in your custom dialog script.
Stefan Krüger
InstallSite.org twitter facebook
Posted 11 February 2003 - 22:46
Hi,
How do we call a WinAPI from a custom dialog box?
Is there any documentation for it?
Thank you very much
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
You will need to gain knowledge of using Custom Dialogs from some source. I was lucky enough to attend InstallShield training about 4 years ago and got my exposure to Custom Dialogs there.
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);
abort;
endif;
// Initialize the indicator used to control the while loop.
bDone = FALSE;
// Loop until done.
repeat
// Display the dialog and return the next dialog event.
nCmdValue = WaitOnDialog(szDialogName); // Respond to the event.
switch (nCmdValue)
case DLG_CLOSE:
// The user clicked the window's close button.
Do (EXIT);
case DLG_ERR:
MessageBox ("Unable to display dialog. Setup canceled.", SEVERE);
abort;
case DLG_INIT:
// 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");
case RES_DIALOG_LISTBOX:
// 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);
else
CtrlSetText (szDialogName, RES_DIALOG_EDITBOX, svDrive);
endif;
case RES_PBUT_CANCEL: // The user clicked the Cancel button.
Do (EXIT);
case RES_PBUT_NEXT:
bDone = TRUE;
case RES_PBUT_BACK:
bDone = TRUE;
endswitch;
until bDone;
// Close the dialog box.
EndDialog (szDialogName);
// Free the dialog box from memory.
ReleaseDialog (szDialogName);
ListDestroy (list_FOLDERS);
// setup default status
SetStatusWindow(0, "");
Enable(STATUSEX);
StatusUpdate(ON, 100);
return 0;
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);
abort;
endif;
// Initialize the indicator used to control the while loop.
bDone = FALSE;
// Loop until done.
repeat
// Display the dialog and return the next dialog event.
nCmdValue = WaitOnDialog(szDialogName); // Respond to the event.
switch (nCmdValue)
case DLG_CLOSE:
// The user clicked the window's close button.
Do (EXIT);
case DLG_ERR:
MessageBox ("Unable to display dialog. Setup canceled.", SEVERE);
abort;
case DLG_INIT:
// 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");
case RES_DIALOG_LISTBOX:
// 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);
else
CtrlSetText (szDialogName, RES_DIALOG_EDITBOX, svDrive);
endif;
case RES_PBUT_CANCEL: // The user clicked the Cancel button.
Do (EXIT);
case RES_PBUT_NEXT:
bDone = TRUE;
case RES_PBUT_BACK:
bDone = TRUE;
endswitch;
until bDone;
// Close the dialog box.
EndDialog (szDialogName);
// Free the dialog box from memory.
ReleaseDialog (szDialogName);
ListDestroy (list_FOLDERS);
// setup default status
SetStatusWindow(0, "");
Enable(STATUSEX);
StatusUpdate(ON, 100);
return 0;
Posted 12 February 2003 - 22:39
Thanks a million!
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.
Thanks heaps!!!
Cheers
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.
Thanks heaps!!!
Cheers
Posted 20 February 2003 - 10:42
Hi All,
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.
and
at the begining of your project.
Where
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.
Enjoy, Ide
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.
Code Sample |
SendMessage( GetDlgItem(hwndDialog,ID_FIELDNAME), EM_LIMITTEXT32, nMaxLength, 0); |
and
Code Sample |
#define EM_LIMITTEXT32 0x00c5 #define EM_LIMITTEXT16 0x0415 |
at the begining of your project.
Where
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.
Enjoy, Ide