Carl Hartman
2015-02-11 19:21:18 UTC
I am having an issue with a CEdit control and using setwindowtext() to put text in the box. I have tried this in VS 2010, 2012, and 2013. I have a simple windows form program with an edit box. During the OnChange call I want to grab the text out of the edit box, change everything to upper case and put it back into the box. The control has been assigned to a variable:
CEdit m_edit1;
added to DoDataExchange
DDX_Control(pDX, IDC_EDIT1, m_edit1);
In the FormView cpp file example:
void CTestView::OnEnChangeEdit1()
{
CString str;
m_edit1.GetWindowTextW(str); // get the string
if(!str.IsEmpty()) // string not empty
{
str = str.MakeUpper(); // change to upper case
m_edit1.SetWindowTextW(str); // put it back
}
}
The line:
m_edit1.SetWindowTextW(str); // put it back
causes this:
First-chance exception at 0x5082D7A3 (mfc120ud.dll) in Test.exe: 0xC00000FD: Stack overflow (parameters: 0x00000001, 0x00322FFC).
Unhandled exception at 0x5082D7A3 (mfc120ud.dll) in Test.exe: 0xC00000FD: Stack overflow (parameters: 0x00000001, 0x00322FFC).
It doesn't matter if is x86, x64, debug, release compiled, it always fails. Desktop is running Win 7 Pro x64.
Is this not the correct way to set and reset text in an edit box?
CH
CEdit m_edit1;
added to DoDataExchange
DDX_Control(pDX, IDC_EDIT1, m_edit1);
In the FormView cpp file example:
void CTestView::OnEnChangeEdit1()
{
CString str;
m_edit1.GetWindowTextW(str); // get the string
if(!str.IsEmpty()) // string not empty
{
str = str.MakeUpper(); // change to upper case
m_edit1.SetWindowTextW(str); // put it back
}
}
The line:
m_edit1.SetWindowTextW(str); // put it back
causes this:
First-chance exception at 0x5082D7A3 (mfc120ud.dll) in Test.exe: 0xC00000FD: Stack overflow (parameters: 0x00000001, 0x00322FFC).
Unhandled exception at 0x5082D7A3 (mfc120ud.dll) in Test.exe: 0xC00000FD: Stack overflow (parameters: 0x00000001, 0x00322FFC).
It doesn't matter if is x86, x64, debug, release compiled, it always fails. Desktop is running Win 7 Pro x64.
Is this not the correct way to set and reset text in an edit box?
CH