display hex in an edit box
I'm trying to take a value from an edit box and display it in the edit box as hex. I'm using this code:
CString buffer;
int intbuf;
m_edit[5]->GetWindowTextA(buffer);
intbuf = atoi(buffer);
buffer.Format("%02X", intbuf);
m_edit[5]->SetWindowTextA(buffer);
If I include the last line of code here I get a stack overflow error. If I don't include it, I can run through the debugger and the buffer CString is converted to hex just like I want, I just can't display it because I get that error. Any help is appreciated as to why I get the error. Thanks for the help!!!
Re: display hex in an edit box
are you doing this in an EN_CHANGE handler ? Then that's normal.
the SetWindowText triggers a new EN_CHANGE while you're still busy handling the old one.
which changes the editcontrol again which triggers another EN_CHANGE
etc etc etc.
stack overflow.
Re: display hex in an edit box
Yes, it is in a change handler. But I have the following code in another change handler:
void Comm::OnEnChangeEdit1()
{
CString buffer;
m_edit[0]->GetWindowTextA(buffer);
if(atoi(buffer) < 0)
m_edit[0]->SetWindowTextA("0");
}
And there's no error if the if statement is triggered. Oh...but I guess it wouldn't go into the if statement again if the value was changed to 0...hm...
Re: display hex in an edit box
Quote:
Originally Posted by
Gregorina
Yes, it is in a change handler. But I have the following code in another change handler:
A side question --
Is your project Unicode or MBCS? I ask this, since you're using CString and supplying that as an argument to atoi(). Just to let you know, that code will not work if your project is Unicode (it may not even compile).
Regards,
Paul McKenzie
Re: display hex in an edit box
Considering the 'A' at the end of Get/SetWindowText ... it's ansi :)