-
September 24th, 2013, 03:20 AM
#1
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!!!
-
September 24th, 2013, 03:54 AM
#2
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.
-
September 24th, 2013, 08:59 AM
#3
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...
-
September 24th, 2013, 10:44 AM
#4
Re: display hex in an edit box
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
Last edited by Paul McKenzie; September 24th, 2013 at 10:46 AM.
-
September 25th, 2013, 06:39 AM
#5
Re: display hex in an edit box
Considering the 'A' at the end of Get/SetWindowText ... it's ansi
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|