Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Stack Overflow on Edit Box

Stack Overflow on Edit Box

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structures
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Grahamfff
    wrote on last edited by
    #1

    I have an Edit box on a dialog and check the input and arrange for it to be set to the Max or Min value if data entered is out of range. But I get a Stack Overflow error if say I enter say 999, the routine set the input to 180 which is OK. But I now enter -999 and the stack overflow problem occurs and I dont know why. The Event Routine on the Edit box is show below:- #define Value_MAX 180 #define Value_MIN -180 void CDataInput::OnEnChangeValue() { // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // Get the New Value string m_cValue.GetWindowText(m_strEditValue); // Convert from string to double (floating) m_fValue = atof(m_strEditValue.GetBuffer()); if(m_fValue > Value_MAX) { m_fValue = Value_MAX; g_strNewDataStr.Format("%0.2f", m_fValue); m_cValue.SetWindowText(g_strNewDataStr); } else if(m_fValue <= Value_MIN) { m_fValue = Value_MIN; g_strNewDataStr.Format("%0.2f", m_fValue); m_cValue.SetWindowText(g_strNewDataStr); } } Also if I just enter -999 I get the Stack Overflow problem. Can someone explain what I am doing wrong. grahamfff

    B G 3 Replies Last reply
    0
    • G Grahamfff

      I have an Edit box on a dialog and check the input and arrange for it to be set to the Max or Min value if data entered is out of range. But I get a Stack Overflow error if say I enter say 999, the routine set the input to 180 which is OK. But I now enter -999 and the stack overflow problem occurs and I dont know why. The Event Routine on the Edit box is show below:- #define Value_MAX 180 #define Value_MIN -180 void CDataInput::OnEnChangeValue() { // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // Get the New Value string m_cValue.GetWindowText(m_strEditValue); // Convert from string to double (floating) m_fValue = atof(m_strEditValue.GetBuffer()); if(m_fValue > Value_MAX) { m_fValue = Value_MAX; g_strNewDataStr.Format("%0.2f", m_fValue); m_cValue.SetWindowText(g_strNewDataStr); } else if(m_fValue <= Value_MIN) { m_fValue = Value_MIN; g_strNewDataStr.Format("%0.2f", m_fValue); m_cValue.SetWindowText(g_strNewDataStr); } } Also if I just enter -999 I get the Stack Overflow problem. Can someone explain what I am doing wrong. grahamfff

      B Offline
      B Offline
      Blake Miller
      wrote on last edited by
      #2

      Your SetWindowText is generating another EN Change event, you never get out of the loop! You could maybe set yourself a monitor variable, like m_bInEnChange, and if that is TRUE, don't do your own processing again! You are probably also in trouble because you have the else if(m_fValue <= Value_MIN) which will always be true once you set value to Value_MIN, so you get into recursive loop.

      1 Reply Last reply
      0
      • G Grahamfff

        I have an Edit box on a dialog and check the input and arrange for it to be set to the Max or Min value if data entered is out of range. But I get a Stack Overflow error if say I enter say 999, the routine set the input to 180 which is OK. But I now enter -999 and the stack overflow problem occurs and I dont know why. The Event Routine on the Edit box is show below:- #define Value_MAX 180 #define Value_MIN -180 void CDataInput::OnEnChangeValue() { // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // Get the New Value string m_cValue.GetWindowText(m_strEditValue); // Convert from string to double (floating) m_fValue = atof(m_strEditValue.GetBuffer()); if(m_fValue > Value_MAX) { m_fValue = Value_MAX; g_strNewDataStr.Format("%0.2f", m_fValue); m_cValue.SetWindowText(g_strNewDataStr); } else if(m_fValue <= Value_MIN) { m_fValue = Value_MIN; g_strNewDataStr.Format("%0.2f", m_fValue); m_cValue.SetWindowText(g_strNewDataStr); } } Also if I just enter -999 I get the Stack Overflow problem. Can someone explain what I am doing wrong. grahamfff

        G Offline
        G Offline
        Gary R Wheeler
        wrote on last edited by
        #3

        Rather than validating on the EN_CHANGE notification, try using the EN_KILLFOCUS notification. With EN_CHANGE, your user will get very frustrated trying to enter a valid value. Every keypress, you will try and validate what they are entering. With EN_KILLFOCUS, you validate only when they leave the control (which implies they are ready to commit the value).


        Software Zen: delete this;

        1 Reply Last reply
        0
        • G Grahamfff

          I have an Edit box on a dialog and check the input and arrange for it to be set to the Max or Min value if data entered is out of range. But I get a Stack Overflow error if say I enter say 999, the routine set the input to 180 which is OK. But I now enter -999 and the stack overflow problem occurs and I dont know why. The Event Routine on the Edit box is show below:- #define Value_MAX 180 #define Value_MIN -180 void CDataInput::OnEnChangeValue() { // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // Get the New Value string m_cValue.GetWindowText(m_strEditValue); // Convert from string to double (floating) m_fValue = atof(m_strEditValue.GetBuffer()); if(m_fValue > Value_MAX) { m_fValue = Value_MAX; g_strNewDataStr.Format("%0.2f", m_fValue); m_cValue.SetWindowText(g_strNewDataStr); } else if(m_fValue <= Value_MIN) { m_fValue = Value_MIN; g_strNewDataStr.Format("%0.2f", m_fValue); m_cValue.SetWindowText(g_strNewDataStr); } } Also if I just enter -999 I get the Stack Overflow problem. Can someone explain what I am doing wrong. grahamfff

          G Offline
          G Offline
          Gary R Wheeler
          wrote on last edited by
          #4

          Something else: You don't need to call m_strEditValue.GetBuffer() in your atof() function call. Just pass m_strEditValue, and the built in cast to a LPCTSTR will take care of the required conversion. Something else #2: In other circumstances, if you have to use GetBuffer() with a CString value, make sure you call ReleaseBuffer(). This ensures that the CString manages the buffer memory correctly.


          Software Zen: delete this;

          G 1 Reply Last reply
          0
          • G Gary R Wheeler

            Something else: You don't need to call m_strEditValue.GetBuffer() in your atof() function call. Just pass m_strEditValue, and the built in cast to a LPCTSTR will take care of the required conversion. Something else #2: In other circumstances, if you have to use GetBuffer() with a CString value, make sure you call ReleaseBuffer(). This ensures that the CString manages the buffer memory correctly.


            Software Zen: delete this;

            G Offline
            G Offline
            Grahamfff
            wrote on last edited by
            #5

            Thanks will use OnKillFocus, works better that way. Graham. grahamfff

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups