Monday, August 19, 2013

How to take input from a MFC Edit Control as string, convert it to integer and append text to it

 Take input from a MFC Control as string :

CString txtname;
GetDlgItemText(IDC_EDIT1, txtname);

Here IDC_EDIT1 is the Control Edit Text and txtname is the input at the moment we call.

Convert it to integer or int :

int iPort = _atoi( txtname.GetString() );

int iPort = _wtoi( txtname.GetString() );
// if you use wide charater formats
 
 
Append text to Edit Control :
 
void CServerDlg::AppendTextToEditCtrl(CEdit& edit, LPCTSTR pszText)
{
   // get the initial text length
   int nLength = edit.GetWindowTextLength();
   // put the selection at the end of text
   edit.SetSel(nLength, nLength);
   // replace the selection
   edit.ReplaceSel(pszText);
}

No comments:

Post a Comment

How to enable hotspot in TPG iPhone

 By default, the hotspot does not work on the phone. It will ask you to contact the provider. This video will help you bypass the network ...