Edit Edit window contents when button is pressed in mfc

I have an edit box and a button in a dialog box. How can I change the contents while the edit window is running when I click the button? I have to read the new entry from the file and publish it in the "Edit Window" window when the button is clicked, and I use mfc.

+4
source share
2 answers

You can set the text of the Edit control (wrapped in the CEdit class in MFC) by calling SetWindowText , which it inherits from the CWnd base class.

So, all you have to do is respond to the click event on your button control. You do this by listening to the BN_CLICKED notification from the corresponding button control in your parent OnCommand method window.

Sort of:

 BOOL CMyDialog::OnCommand(WPARAM wParam, LPARAM lParam) { if (HIWORD(wParam) == BN_CLICKED && LOWORD(lParam) == IDC_MYBUTTON) { m_Edit.SetWindowText(TEXT("My string")); } return CWnd::OnCommand(wParam, lParam); } 

Getting and reading a book about MFC would be very helpful. This is pretty straightforward stuff, but it can cover one answer if you don't already understand the fundamental concepts.

Using the class wizard will make it even easier ... Call it using the keys Ctrl + W and follow the instructions on the screen. You will get something like:

 void CMyDialog::OnMyButton() { m_Edit.SetWindowText(TEXT("My string")); } 
+8
source

Once you clicked the button by clicking the button, in most cases the easiest way to change the text in the edit control is:

 SetDlgItemText(IDC_EDIT_ID, "Desired Text String") 

Where IDC_EDIT_ID is the ID of the Edit control (set in the properties window)

+6
source

Source: https://habr.com/ru/post/1393910/


All Articles