-
Edit box question
Hello,
Im making a simple math game for children for an assignment. The program generates two numbers and the student has to type in the correct answer. I have an edit box for the answer to be typed in and a mark button beside it.
Is there any way to display an error message if nothing has been entered into the edit box and the mark button clicked?
Thanx for any help,
Jason
-
Is this a Windows assignment? You can determine whether the edit box has text by calling GetWindowText and checking the length of the text with the strlen function. Then, call MessageBox to display a message if no text has been entered.
-
Hi m8,
Yes this is windows, i should have put it in the other forum. Would it be possible for you to write an example with this 'GetWindowText' and checking the length?
Thanx
-
Code:
char buffer[256];
int length;
GetWindowText(hwndEdit,buffer,sizeof(buffer));
length=strlen(buffer);
In your case, you also need to validate the string and check if it's an integer, using either the strtol function or the atoi function.
To make sure the student only enters numbers, set the ES_NUMBER style to the edit box, as follows:
Code:
SetWindowLong(hwndEdit,GWL_STYLE,
GetWindowLong(hwndEdit,GWL_STYLE)|ES_NUMBER);
-
Thanx 4 all your help m8, it came in handy - have got it all working now.
Thanx again,
Jason
-
also add the edit style so the edit will only allow numbers to be typed in (so you don't have to validate the data too much)
ES_NUMBER
either add in the resource editor
or
on the fly
Code:
long lOldStyle=0,lNewStyle=0;
lOldStyle=GetWindowLong(hWndEdit,GWL_STYLE);
lNewStyle=lOldStyle|ES_NUMBER;
SetWindowLong(hWndEdit,GWL_STYLE,lNewStyle);
-
You can also use EM_MODIFY to find out if the content of
the edit box has been changed.
examine its return value(SendMessage) for true or false.