How can I get the ID code for
-
I put some CEdit to the dialog, use the same function OnChangeEdit1, when the context of edit box is changed, such as, ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1) ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit1) ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit1) the problem is, I can not decide which edit box has called the function, How can I get the ID for it?
-
I put some CEdit to the dialog, use the same function OnChangeEdit1, when the context of edit box is changed, such as, ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1) ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit1) ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit1) the problem is, I can not decide which edit box has called the function, How can I get the ID for it?
Does this code helpful?
void CdddDlg::OnEnChangeEdit1()
{
if(GetFocus()==GetDlgItem(IDC_EDIT1))
MessageBox(_T("editbox1"));if(GetFocus()==GetDlgItem(IDC_EDIT2))
MessageBox(_T("editbox2"));
} -
Does this code helpful?
void CdddDlg::OnEnChangeEdit1()
{
if(GetFocus()==GetDlgItem(IDC_EDIT1))
MessageBox(_T("editbox1"));if(GetFocus()==GetDlgItem(IDC_EDIT2))
MessageBox(_T("editbox2"));
} -
...and for a syntactical point of view, you should always put curved braces for if statements, even it then contains only one instruction...
toxcct wrote:
...and for a syntactical point of view, you should always put curved braces for if statements, even it then contains only one instruction...
I always put curly braces for if statements, even if it would only be a one-liner. About a month ago, however, I started doing one-liners without the braces. I ran into so many problems from doing this. It took me quite a while to get re-accustomed to my old ways. It's funny, you would think it wouldn't cause any problems, but it did for me.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
-
...and for a syntactical point of view, you should always put curved braces for if statements, even it then contains only one instruction...
Thank you for your advice.;)
-
I put some CEdit to the dialog, use the same function OnChangeEdit1, when the context of edit box is changed, such as, ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1) ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit1) ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit1) the problem is, I can not decide which edit box has called the function, How can I get the ID for it?
Step 1. Ensure that IDC_EDIT1,IDC_EDIT2,IDC_EDIT3 are consecutive ID's ie 1001,1002,1003 Step 2. instead of 3 separate ON_EN_CHANGE's inside the ClassWizard part of the MESSAGE_MAP use on ON_CONTROL_RANGE outside of the ClassWizard part of the MESSAGE_MAP ON_CONTROL_RANGE(EN_CHANGE, IDC_EDIT1, IDC_EDIT3, OnChangeEdit1) Step 3. change the declaration of OnChangeEdit1 to void YourClass::OnChangeEdit1(UINT nIDCtl) see ON_CONTROL_RANGE[^]