tags:

views:

90

answers:

1

Ok, i have 2 edit controls and a button in my main window; in one edit control the user can write a number and when he push the button i read that number and i print it in the other edit control (which is read only).

My problem is that when i put a number and i press the button, for some reason that i dont understand i can get that number. And GetDlgItemInt() always return zero and his third parameter always return me false.

This is the code where i use GetDlgItemInt () to read the number:

            case CM_BUTTON:
                number = GetDlgItemInt(hwndEdit2, CM_EDIT2, &flag, FALSE); 
                if(flag)
                {
                    if(number > 0 && number < 20)
                    {
                        sprintf(message, "This is the number %d", number);
                        SetWindowText(hwndEdit, message);
                    }
                    else
                        MessageBox(hwnd, "Number to high or to low", "Error", MB_OK | MB_ICONWARNING);
                }
                else 
                    MessageBox(hwnd, "Error getting the number", "Error", MB_ICONEXCLAMATION | MB_OK);
                break;

Any suggest?

+5  A: 

The first parameter to GetDlgItemInt should be the handle to the dialog box. Unless the name hwndEdit2 is extremely deceiving, you're currently passing the handle to the edit control itself instead.

Jerry Coffin
Ok, i have test it and actually work when i use the correct handle (the handle of my main window); thanks for the help my friend.
ezgar