Click here to Skip to main content
16,018,534 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am doing calculator program by using dialog based VC++/MFC application. In a diaolg box, added a edit text control and a push button. So I need to change/append the text of edit control box in that dialog when I pressed the push button in dialog window. To display the text am using Setsel() and ReplaceSel() methos in ButtonClicked method, but it's not working.

Show the relevant portion of your code and relevent artical.
If you always want to change all the text, use SetWindowText.

basu
Posted
Updated 22-Jun-10 22:06pm
v2

1 solution

void operator += (LPCSTR str)
{
	CString CurrText;
        GetWindowText (CurrText);
        if(CurrText!="0")
            CurrText += str;
        else
           CurrText = str;
        SetWindowText (CurrText);
}

void CCalciDlg::OnBnClickedCbutton0()
{
	
	if(eqflg==TRUE)
	{
		SetDlgItemText(IDCRESULT,_T("0"));
		eqflg=FALSE;
	}
	resu += "0";
	
}
void CCalciDlg::OnBnClickedCbutton1()
{
	if(eqflg==TRUE)
	{
		SetDlgItemText(IDCRESULT,_T("0"));
		eqflg=FALSE;
	}
	resu += "1";
}
void CCalciDlg::OnBnClickedCbutton2()
{
	if(eqflg==TRUE)
	{
		SetDlgItemText(IDCRESULT,_T("0"));
		eqflg=FALSE;
	}
	resu += "2";
}
void CCalciDlg::OnBnClickedCbutton3()
{
	if(eqflg==TRUE)
	{
		SetDlgItemText(IDCRESULT,_T("0"));
		eqflg=FALSE;
	}
	resu += "3";
}
void CCalciDlg::OnBnClickedCbutton4()
{
	if(eqflg==TRUE)
	{
		SetDlgItemText(IDCRESULT,_T("0"));
		eqflg=FALSE;
	}
	resu += "4";
}
void CCalciDlg::OnBnClickedCbutton5()
{
	if(eqflg==TRUE)
	{
		SetDlgItemText(IDCRESULT,_T("0"));
		eqflg=FALSE;
	}
	resu += "5";
}
void CCalciDlg::OnBnClickedCbutton6()
{
	if(eqflg==TRUE)
	{
		SetDlgItemText(IDCRESULT,_T("0"));
		eqflg=FALSE;
	}
	resu += "6";
}
void CCalciDlg::OnBnClickedCbutton7()
{
	if(eqflg==TRUE)
	{
		SetDlgItemText(IDCRESULT,_T("0"));
		eqflg=FALSE;
	}
	resu += "7";
}
void CCalciDlg::OnBnClickedCbutton8()
{
	if(eqflg==TRUE)
	{
		SetDlgItemText(IDCRESULT,_T("0"));
		eqflg=FALSE;
	}
	resu += "8";
}
void CCalciDlg::OnBnClickedCbutton9()
{
	if(eqflg==TRUE)
	{
		SetDlgItemText(IDCRESULT,_T("0"));
		eqflg=FALSE;
	}
	resu += "9";
}
void CCalciDlg::OnBnClickedCbuttonpoint()
{
	CString msg;
	GetDlgItemText(IDCRESULT,msg);
	if(flg==TRUE)
	{
		msg=msg+'.';
		SetDlgItemText(IDCRESULT,msg);
		flg=FALSE;
	}
	pctrl.EnableWindow(FALSE);
	//SetProperty(IDCBUTTONPOINT,WS_VISIBLE,FALSE);
	
}
void CCalciDlg::OnBnClickedCbuttondiv()
{
	num=0;
	opflg=4;
	UpdateData(TRUE);
	num=num1;
	SetDlgItemText(IDCRESULT,_T("0"));
}
void CCalciDlg::OnBnClickedCbuttonmul()
{
	num=0;
	opflg=3;
	UpdateData(TRUE);
	num=num1;
	SetDlgItemText(IDCRESULT,_T("0"));
}
void CCalciDlg::OnBnClickedCbuttonplus()
{
	num=0;
	opflg=1;
	UpdateData(TRUE);
	num=num1;
	SetDlgItemText(IDCRESULT,_T("0"));
}
void CCalciDlg::OnBnClickedCbuttonminus()
{
	num=0;
	opflg=2;
	UpdateData(TRUE);
	num=num1;
	SetDlgItemText(IDCRESULT,_T("0"));
}
void CCalciDlg::OnBnClickedCbuttonequal()
{
	eqflg=TRUE;
	
	if(num1!=0)
	{
		UpdateData(TRUE);
		switch(opflg)
		{
		case 1:
			num=num+num1;
			break;
		case 2:
			num=num-num1;
			break;
		case 3:
			num=num*num1;
			break;
		case 4:
			num=num/num1;
			break;
		case 0:
			AfxMessageBox(_T("Please Select The Operation"),MB_OK);
			break;
		}
		CString str;
		str.Format(_T("%.2f"), num);
		SetDlgItemText(IDCRESULT,str);
		resu.SetSel(0,-1);
	}
	else
	{
		AfxMessageBox(_T("Enter The Second Value"),MB_OK);
	}
}
 
Share this answer
 

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