How to change/append the text of edit control box in that dialog when i pressed the push button in dialog window

mfcvisual c++

I am doing calculator program by using dialog based vc++/MFC application. In a dialog box, I added a edit text control and a push button. So I need to change/append the text of the edit control box in that dialog when I click the button on the dialog. To display the text am using Setsel() and ReplaceSel() methods in ButtonClicked method, but it's not working.

Show the relevant portion of your code and relevent artical.

basu

Best Answer

If all you want to do is display some text in a CEdit control then why not use it's SetWindowText function?

The following replaces the contents using your SetSel/ReplaceSel method:

void CTextCtrlAddDlg::OnBnClickedButton1()
{
    int start = 0;
    int end = m_editControl.GetWindowTextLength();
    m_editControl.SetSel(start, end);
    m_editControl.ReplaceSel(L"Test");
}

...where m_editControl is the edit control. If you want to append the text at the end, simply set the selection to the end:

void CTextCtrlAddDlg::OnBnClickedButton1()
{
    int end = m_editControl.GetWindowTextLength();
    m_editControl.SetSel(end, end);
    m_editControl.ReplaceSel(L"Test");
}

I agree with Goz though; some example code frmo you would help us identify what isn't working for you.

Related Topic