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 Generate and use the ssh key on Gerrit, github.io, gitlab, and bitbucket.

 Details can be found here -