Thread: Edit box question

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    21

    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

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    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.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    21
    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

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    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);
    Last edited by poccil; 03-27-2003 at 05:17 PM.

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    21
    Thanx 4 all your help m8, it came in handy - have got it all working now.

    Thanx again,
    Jason

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    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);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. edit box
    By beene in forum Windows Programming
    Replies: 3
    Last Post: 11-11-2006, 04:40 AM
  2. WS_HSCROLL in ES_READONLY edit box error
    By Homunculus in forum Windows Programming
    Replies: 4
    Last Post: 02-13-2006, 08:46 AM
  3. Multiline Edit Box Parser
    By The Brain in forum Windows Programming
    Replies: 6
    Last Post: 11-01-2005, 07:15 PM
  4. setting fixed floats in edit box
    By WaterNut in forum Windows Programming
    Replies: 4
    Last Post: 08-13-2004, 09:13 AM
  5. How do i make a "new line" with in an edit box?
    By Clyde in forum Windows Programming
    Replies: 3
    Last Post: 05-18-2002, 01:35 PM