CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Mar 2011
    Posts
    60

    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!!!

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

  3. #3
    Join Date
    Mar 2011
    Posts
    60

    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...

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: display hex in an edit box

    Quote Originally Posted by Gregorina View Post
    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.

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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
  •  





Click Here to Expand Forum to Full Width

Featured