MFC, CEdit En_Change get Current Ctrl ID

Fleµve Relentless.resærch.lab 81 Reputation points
2023-11-27T15:51:54.4533333+00:00

Hello,

Before I begin, let me tell you that Microsoft Q & A forms was totally Sh**, if you compare to MSDN forms. It's the third time a re-begin this message because Code Block window give some trouble when it's time to edit.

  • Back space not at the good place. You will out Code block and still backspace inside. Select around text and erase it.
  • Don't try Ctrl-Z, you gonna cry
  • Copy/paste inside block Split code block in two
  • I never feel so frustrate to send a post.

Ok..

What I try to done it's plug EN_CHANGE to the same Function. Unfortunately this message map have no input parameter like OnCtlColor, that you can call pWnd->GetDlgCtrlID(). Does it Possible to get IDC (#1)?

BEGIN_MESSAGE_MAP(CTopSleeveDlg, CDialogEx)
//{{AFX_MSG_MAP(CTopSleeveDlg)

	ON_EN_CHANGE(IDC_EDTCENTER2CENTER, &CTopSleeveDlg::SameFunction)

	ON_EN_CHANGE(IDC_EDTSLEEVETHICK, &CTopSleeveDlg::SameFunction)

//}}AFX_MSG_MAP
END_MESSAGE_MAP()

int CTopSleeveDlg::OnEditChange(int Index)

{
UpdateData(TRUE);

double Value;

long hr = m_piLogic->GetValueFromExpression(m_Param[Index].Expression, &Value, m_Param[Index].UnitType);

m_Param[Index].IsValid = SUCCEEDED(hr) ? 1 : 0;

return m_Param[Index].IsValid;

}

void CTopSleeveDlg::SameFunction()

{

#1 Get IDC of current Control;

for (long i = 0; i < m_NbElem; i++)

{

	if (CtrlID == m_Param[i].IDD)

	{

		OnEditChange(i);

		break;

	}

}

}


/*** To Remove

void CTopSleeveDlg::OnChangeEdtcenter2center()

{

OnEditChange(0);

}

void CTopSleeveDlg::OnChangeEdtsleevethick()

{

OnEditChange(1);

}

*/

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,675 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,780 questions
{count} votes

Accepted answer
  1. Viorel 118.4K Reputation points
    2023-11-27T16:19:10.3866667+00:00

    Try this:

    const MSG* pm = GetCurrentMessage( );
    int id = LOWORD( pm->wParam );
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. RLWA32 45,716 Reputation points
    2023-11-27T16:17:45.3266667+00:00

    You can use the ON_CONTROL_RANGE message map macro. You must manually insert it into the message map. The range of control id's must be contiguous. For example, in a dialog that has two edit controls IDC_EDIT1 (1000) and IDC_EDIT2 (1001) -

    ON_CONTROL_RANGE(EN_CHANGE, IDC_EDIT1, IDC_EDIT2, &CMFCRangeTestDlg::OnChange)
    

    Header declaration -

    void OnChange(UINT nId);
    

    Implementation -

    void CMFCRangeTestDlg::OnChange(UINT nId)
    {
        TRACE(_T("Received EN_CHANGE from control id %d\n"), nId);
    }
    
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.