Thread: validate data in a dialog box

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    26

    validate data in a dialog box

    I am displaying a dialog box. On the dialog box I have some edit boxes, raidio buttons, static boxes, push buttons, and check boxes.

    The user enters some information in the edit boxes and clicks on the "Submit" push button.

    Once the Submit button is pushed I validate the data that was just entered. If it is OK the program continues if not I want to return focus to the edit box that is invalid and allow the user to correct the error.

    This is my problem. How can I return focus back to the edit box that is bad, let the user correct the problem, and then push Submit again? Once the Submit button is pushed I again want to validate the data.

    I am new at this so any help you have would be great.

    Thanks,

  2. #2
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    Code:
    if (data invalid)
       SetFocus(GetDlgItem(hwnd,editboxID));
    I think this might help ya out.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    26
    I added the following code
    Code:
     
    if (intMonths < 1 || intMonths > 999) 
             SetFocus(GetDlgItem(hwnd, IDC_EDIT_NUM_MONTHS));
    but was getting a couple of errors.
    error C2065: 'hwnd' : undeclared identifier
    and
    error C2660: 'SetFocus' : function does not take 1 parameters

    I haven't covered handles yet so I'm not really sure what the first error is telling me and I know SetFocus does take 1 parameter, which is what I am passing it.

    Thanks,

  4. #4
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    I haven't covered handles yet so I'm not really sure what the first error is telling me
    Well the handle in this case is a handle for your window/dialog. Your main windows proceedure looks like this:
    Code:
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    or something similar. The Dialog proceedure kinda look the same except the HWND would be a handle to your dialog and a dialog proceedure returns a BOOL type. I was passing SetFocus() a HWND called hwnd. That is just a name I use for it so you probably have yours named differently and that is why you are getting an error. I was just using it as an example. Maybe I should have said it like this:
    Code:
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    HWND EditboxYouWant;  
    if(dataNotValid)
    {
       EditboxYouWant = GetDlgItem(hwnd,IDC_EDIT_NUM_MONTHS);
       SetFocus(EditboxYouWant);
    }
    Hope this helps you
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    26
    Thanks, I'll try it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Set Printer Prior To Loading Print Dialog Box
    By Beaner in forum Windows Programming
    Replies: 3
    Last Post: 10-10-2008, 01:02 PM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  4. Click button on dialog box to open window.
    By ooosawaddee3 in forum Windows Programming
    Replies: 1
    Last Post: 11-29-2002, 08:53 AM
  5. Dialog box
    By DeanaM in forum Windows Programming
    Replies: 3
    Last Post: 10-16-2002, 12:04 PM