control ID not found, Resolved
-
Windows 7, Visual Studio 2008, MFC, C++, dialog Making this short, after failing elsewhere I created a test project. The dialog has one edit box with the default ID of IDC_EDIT1. A button was created and the following code added for that button.
void Cvs_2008_get_port_numberDlg::OnBnClickedButton1()
{
UINT port_number;
BOOL status = FALSE;
int last_error = 0;port\_number = m\_box\_get\_port\_number.GetDlgItemInt( IDC\_EDIT1, &status ); last\_error = GetLastError();
}
Run the code, type in 123 in the edit box, press the button, and port_number gets zero. last_error gets value 1421, Control ID not found. Some searching indicated that there may be a windows problem: http://www.errorfixes.net/error-1421-windows-7.php[^] But I find myself skeptical of that. Do I have a simple error that I can correct? Or is this a deeper problem?
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
-
Windows 7, Visual Studio 2008, MFC, C++, dialog Making this short, after failing elsewhere I created a test project. The dialog has one edit box with the default ID of IDC_EDIT1. A button was created and the following code added for that button.
void Cvs_2008_get_port_numberDlg::OnBnClickedButton1()
{
UINT port_number;
BOOL status = FALSE;
int last_error = 0;port\_number = m\_box\_get\_port\_number.GetDlgItemInt( IDC\_EDIT1, &status ); last\_error = GetLastError();
}
Run the code, type in 123 in the edit box, press the button, and port_number gets zero. last_error gets value 1421, Control ID not found. Some searching indicated that there may be a windows problem: http://www.errorfixes.net/error-1421-windows-7.php[^] But I find myself skeptical of that. Do I have a simple error that I can correct? Or is this a deeper problem?
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
What is
m_box_get_port_number
in the above code? I would have expected to see something more like:BOOL status = TRUE; port\_number = GetDlgItemInt( IDC\_EDIT1, &status ); if (status = FALSE) last\_error = GetLastError();
// ...
Also, where is the button that this handler refers to: on the dialog or the main window?
-
What is
m_box_get_port_number
in the above code? I would have expected to see something more like:BOOL status = TRUE; port\_number = GetDlgItemInt( IDC\_EDIT1, &status ); if (status = FALSE) last\_error = GetLastError();
// ...
Also, where is the button that this handler refers to: on the dialog or the main window?
I state up front that I am not experienced with GUIs. My tasks include VS MFS dialogs to control how the app runs and show its performance, but the app is a number cruncher and has no significant user interface. Once started there is no user interaction. The problem is probably a beginner's error so do not hesitate to ask or point out the basics. This test app is an MFC dialog and has only one dialog. I don't know your intent in differentiating between "dialog or main window." It is only a few steps beyond a just created MFC dialog project. So far in the test project there is one edit box, one check box, and one button. A right click on the edit box produced a drop down and "Add variable" was selected. The name used was m_box_get_port_number. I added the check for status per your code and it is returned with value 0, false. The error code remains 1421. The one button has the event handler shown in the OP and runs that code. Is all that of any use?
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
-
I state up front that I am not experienced with GUIs. My tasks include VS MFS dialogs to control how the app runs and show its performance, but the app is a number cruncher and has no significant user interface. Once started there is no user interaction. The problem is probably a beginner's error so do not hesitate to ask or point out the basics. This test app is an MFC dialog and has only one dialog. I don't know your intent in differentiating between "dialog or main window." It is only a few steps beyond a just created MFC dialog project. So far in the test project there is one edit box, one check box, and one button. A right click on the edit box produced a drop down and "Add variable" was selected. The name used was m_box_get_port_number. I added the check for status per your code and it is returned with value 0, false. The error code remains 1421. The one button has the event handler shown in the OP and runs that code. Is all that of any use?
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
If I understand what you are saying you have an MFC application that is a dialog; that's fairly standard. Within the dialog are a few controls, one of which is an edit box. You then say, "A right click on the edit box produced a drop down and "Add variable" was selected.". That part I don't understand, an edit box is just that, a box that you type text into which allows simple editing. What I would expect to happen would be that you would type something into the edit box, and then click the button. Your button handler would be something like:
void Cvs_2008_get_port_numberDlg::OnBnClickedButton1()
{
UINT port_number;
BOOL status;
int last_error = 0;port\_number = GetDlgItemInt( IDC\_EDIT1, &status ); if (status == FALSE) last\_error = GetLastError();
// ...
// store the port number somewhereWhen you prefix your call to
GetDlgItemInt
withm_box_get_port_number
(the edit box variable name) you are trying to find the itemIDC_EDIT1
within the edit control. But the edit control does not have a child window with that ID so the call fails. -
If I understand what you are saying you have an MFC application that is a dialog; that's fairly standard. Within the dialog are a few controls, one of which is an edit box. You then say, "A right click on the edit box produced a drop down and "Add variable" was selected.". That part I don't understand, an edit box is just that, a box that you type text into which allows simple editing. What I would expect to happen would be that you would type something into the edit box, and then click the button. Your button handler would be something like:
void Cvs_2008_get_port_numberDlg::OnBnClickedButton1()
{
UINT port_number;
BOOL status;
int last_error = 0;port\_number = GetDlgItemInt( IDC\_EDIT1, &status ); if (status == FALSE) last\_error = GetLastError();
// ...
// store the port number somewhereWhen you prefix your call to
GetDlgItemInt
withm_box_get_port_number
(the edit box variable name) you are trying to find the itemIDC_EDIT1
within the edit control. But the edit control does not have a child window with that ID so the call fails.Hello Richard,
Quote:
You then say, "A right click on the edit box produced a drop down and "Add variable" was selected.". That part I don't understand, an edit box is just that, a box that you type text into which allows simple editing.
My understanding was that to get the value from a control a variable had to be attached to the control. A right click on that control solicits a dialog to add said variable. This method works when I want to get the state of a check box. However, Now it is clear that this method does not work with the edit control. Following your template, heck, the exact code you wrote, I am able to get the value entered. I need to take care when examining the results. A zero return value is legitimate only when status is also TRUE. If status is FALSE, then the returned integer is to be regarded as invalid. OK, I will work with that. I thank you for the time you spent explaining this. Edit: Now I realize, or think I do, that my code was trying to reach inside that edit box, which is really a window itself, and try to find another control with that ID of IDC_EDIT1.
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
-
Hello Richard,
Quote:
You then say, "A right click on the edit box produced a drop down and "Add variable" was selected.". That part I don't understand, an edit box is just that, a box that you type text into which allows simple editing.
My understanding was that to get the value from a control a variable had to be attached to the control. A right click on that control solicits a dialog to add said variable. This method works when I want to get the state of a check box. However, Now it is clear that this method does not work with the edit control. Following your template, heck, the exact code you wrote, I am able to get the value entered. I need to take care when examining the results. A zero return value is legitimate only when status is also TRUE. If status is FALSE, then the returned integer is to be regarded as invalid. OK, I will work with that. I thank you for the time you spent explaining this. Edit: Now I realize, or think I do, that my code was trying to reach inside that edit box, which is really a window itself, and try to find another control with that ID of IDC_EDIT1.
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
good
Sankarsan Parida
-
Hello Richard,
Quote:
You then say, "A right click on the edit box produced a drop down and "Add variable" was selected.". That part I don't understand, an edit box is just that, a box that you type text into which allows simple editing.
My understanding was that to get the value from a control a variable had to be attached to the control. A right click on that control solicits a dialog to add said variable. This method works when I want to get the state of a check box. However, Now it is clear that this method does not work with the edit control. Following your template, heck, the exact code you wrote, I am able to get the value entered. I need to take care when examining the results. A zero return value is legitimate only when status is also TRUE. If status is FALSE, then the returned integer is to be regarded as invalid. OK, I will work with that. I thank you for the time you spent explaining this. Edit: Now I realize, or think I do, that my code was trying to reach inside that edit box, which is really a window itself, and try to find another control with that ID of IDC_EDIT1.
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
bkelly13 wrote:
A right click on that control solicits a dialog
I get it now, you were talking about the MFC Class Wizard being used when you develop the application; a long time since I used MFC.
bkelly13 wrote:
Now I realize, or think I do, that my code was trying to reach inside that edit box ...
Yes, you got it. Glad you got things working.