Edit control behaviour - Programmer

This is a discussion on Edit control behaviour - Programmer ; Hi Everyone, Lets say that I have a standard edit control on a dialog, and I am trying to validate user input - specifically I want the user to be able to only enter values between 2 and 1023. The ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Edit control behaviour

  1. Edit control behaviour

    Hi Everyone,

    Lets say that I have a standard edit control on a dialog, and I am
    trying to validate user input - specifically I want the user to be
    able to only enter values between 2 and 1023.

    The problem is figuring out how to set up the control to allow this.
    I have a control and value variable associated with the edit control,
    and am using the following code:

    void CImagerControlsDlg::OnEnChangeEditwoirowpointera()
    {
    UpdateData(TRUE);
    if ((woi_row_pointer_a < 2) | (woi_row_pointer_a > 1023)) {
    woi_row_pointer_a = 2;
    AfxMessageBox("WOI Row Pointer must be between 2 and 1023.");
    UpdateData(FALSE);
    }
    }

    Now heres the rub - if you try to enter a number - lets say 1014, as
    soon as you type the 1 in - the < 2 event is triggered and you cannot
    enter the number!

    Is there any way to structure the test so that it waits for the user
    to hit enter before testing? The only relevant events I can see for
    the dialog are EN_CHANGE and EN_UPDATE, neither of which will do the
    job...

    Any replies appreciated.

  2. Re: Edit control behaviour

    Rodney B. Elliott wrote:
    > Hi Everyone,
    >
    > Lets say that I have a standard edit control on a dialog, and I am
    > trying to validate user input - specifically I want the user to be
    > able to only enter values between 2 and 1023.
    >
    > The problem is figuring out how to set up the control to allow this.
    > I have a control and value variable associated with the edit control,
    > and am using the following code:
    >
    > void CImagerControlsDlg::OnEnChangeEditwoirowpointera()
    > {
    > UpdateData(TRUE);
    > if ((woi_row_pointer_a < 2) | (woi_row_pointer_a > 1023)) {
    > woi_row_pointer_a = 2;
    > AfxMessageBox("WOI Row Pointer must be between 2 and 1023.");
    > UpdateData(FALSE);
    > }
    > }
    >
    > Now heres the rub - if you try to enter a number - lets say 1014, as
    > soon as you type the 1 in - the < 2 event is triggered and you cannot
    > enter the number!
    >
    > Is there any way to structure the test so that it waits for the user
    > to hit enter before testing? The only relevant events I can see for
    > the dialog are EN_CHANGE and EN_UPDATE, neither of which will do the
    > job...
    >
    > Any replies appreciated.


    EN_KILLFOCUS is sent for tab, enter, click on a different control, etc.

    --
    Scott McPhillips [VC++ MVP]


+ Reply to Thread