Click here to Skip to main content
15,844,904 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
How can I make an edit control updating itself in MFC App? I want to write down data in three edit controls (void CServicesDlg::EdtCompanyName(), void CServicesDlg::EdtServiceName() and void CServicesDlg::EdtPortTCP()) and make one edit control void CServicesDlg::EdtDescription() that updates, shows three data in one.

P.S. Sorry for my English.

What I have tried:

I've tried to question AI and search some guides in Youtube, but I didn't find what I want.
Posted
Updated 29-Aug-23 2:49am
v4
Comments
Richard MacCutchan 23-Aug-23 7:11am    
You have just dumped all your code without explaining which parts you need to work on. Please edit your question and remove the code that is not relevant to the problem, and explain which edit control(s) you are trying to manage. Note: it may be that you can write your question in your native language and use Google translate to convert it to English.
Richard MacCutchan 23-Aug-23 10:55am    
Now you have removed all the code so we have no idea what you are trying to do.

Rick has already written the basic solution in Solution1, here again in more detail:

To display a summary of three other text fields in the text field EdtDescription, a simple solution would be to react on EN_CHANGE of the three fields and call a member function there, which updates the EdtDescription text field.

Since it seems to be a dialog, message map entries like the following would be needed first:
C++
ON_EN_CHANGE(IDC_EDT_COMPANYNAME, &CServicesDlg::OnEnChangeEdtCompanyname)
ON_EN_CHANGE(IDC_EDT_SERVICENAME, &CServicesDlg::OnEnChangeEdtServicename)
ON_EN_CHANGE(IDC_EDT_PORTTCP, &CServicesDlg::OnEnChangeEdtPorttcp)

An extension of DoDataExchange() would be recommended, even if it would work without. First arrange a variable in the class for each control:
C++
private:
  CEdit m_EdtCompanyName, m_EdtServiceName, m_EdtPortTCP, m_EdtDescription;

then add the following entries to DoDataExchange():

C++
DDX_Control(pDX, IDC_EDT_COMPANYNAME, m_EdtCompanyName);
DDX_Control(pDX, IDC_EDT_SERVICENAME, m_EdtServiceName);
DDX_Control(pDX, IDC_EDT_PORTTCP, m_EdtPortTCP);
DDX_Control(pDX, IDC_EDT_DESCRIPTION, m_EdtDescription);

In each of the three handlers you could now call a common function:
C++
void CServicesDlg::OnEnChangeEdtCompanyname()
{
  RenewDescription(); // Display summary
}

After that you only need a function that creates the text field with the summary:

C++
void CServicesDlg::RenewDescription()
{
  CString companyName, serviceName, portTCP, description;  
  m_EdtCompanyName.GetWindowText(companyName);  
  m_EdtServiceName.GetWindowText(serviceName);  
  m_EdtPortTCP.GetWindowText(portTCP);  
  description.Format( TEXT("Company: %s\nService: %s\nPort: %s\n") ,companyName, serviceName, portTCP);
  m_EdtDescription.SetWindowText(description);
 
Share this answer
 
Comments
Inczu 29-Aug-23 5:17am    
Thank you for helping me. Yesterday I've found good solution in AI :)
It is not entirely clear what you are trying to do. You state you want to have an edit control update itself but then you list it as CServicesDlg::EdtCompanyName(). That is clearly a method of a dialog class and it is unclear what relationship it has with the edit control(s).

Regardless, if you want an edit control to update based on input to another edit control the usual way is to write one or more ON_EN_CHANGE handlers in your dialog class and map those to handle messages from one or more edit controls. In one dialog I have the handler responds to changes from three edit controls. That complicates the processing a bit but it's still manageable. What happens is any time a key is pressed for the given edit controls that method is called. It can grab data from one edit control and then update another if you want to. In my case, I make sure all edit controls have data before I enable a button but you can do what you need to with it.

Note that there are similar notification messages for practically all of the controls so you can respond almost any changes made in dialogs.
 
Share this answer
 
Comments
Inczu 29-Aug-23 5:17am    
Thank you for helping me. Yesterday I've found good solution in AI :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900