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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Unusal Visual C++ behavior please help

Unusal Visual C++ behavior please help

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++questiondebuggingperformance
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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hello all I am wrestling with a strange occurance in Visual C++ and being a newby to it I hope you guys can help. What I have is 3 differant ways a usercan input the same data , either by a spin control, a slider bar or an edit control box. My goal is to have it where if one is adjused the others adjust as well. I have the code down for a change in the slider bar the edit and spin adjust to that value. If the editcontrol is box is used for entering data then both the sldier and the spinbox are updated as well BUT when i try and build the function for the ON_SpinChange function I encounter a new problem. The code compiles just fine, however when i run it I get a gray box that pops up saying the following DEBUG Assertion failed yadda yadda with 3 butons to IGNORE, RETRY or ABORT. and i do no know why this happens the code for on SpinControlChange is exactly the same as the OnEditControlChange , just differant data names. here s the code for both //on user inputting data into edit control box void CTripCalculatorDlg::OnChangeEdit1() { CString SomeValue; //value input into edit control = speed2 m_speed2.GetWindowText(SomeValue); //Convert to an int int speed2 = atoi(LPCSTR(SomeValue)); //adjust the progress bar position m_progress.SetPos(speed2); //adjust the slider bar position m_slider.SetPos(speed2); //Adjust the spinvalue m_spin.SetPos(speed2); m_spinvalue.SetWindowText(LPCTSTR(SomeValue)); } //THIS ALL WORKS FINE //on input intothe spincontrol instead of using the spin arrows void CTripCalculatorDlg::OnChangeSpeed() { CString SomeValue2; //value input into spin control = speed m_speed.GetWindowText(SomeValue2); //Convert to an int int speed = atoi(LPCSTR(SomeValue2)); //adjust the progress bar position m_progress.SetPos(speed); //adjust the slider bar position m_slider.SetPos(speed); //Adjust the editcontrol box m_speed2.SetWindowText(LPCTSTR(SomeValue2)); }//THIS GIVES ME THE ASSERTION ERROR BOX what is the differance betweent hese 2 codes that cause the assertion error? i am perplexed thank you in advance Ed Storey

    M R 2 Replies Last reply
    0
    • L Lost User

      Hello all I am wrestling with a strange occurance in Visual C++ and being a newby to it I hope you guys can help. What I have is 3 differant ways a usercan input the same data , either by a spin control, a slider bar or an edit control box. My goal is to have it where if one is adjused the others adjust as well. I have the code down for a change in the slider bar the edit and spin adjust to that value. If the editcontrol is box is used for entering data then both the sldier and the spinbox are updated as well BUT when i try and build the function for the ON_SpinChange function I encounter a new problem. The code compiles just fine, however when i run it I get a gray box that pops up saying the following DEBUG Assertion failed yadda yadda with 3 butons to IGNORE, RETRY or ABORT. and i do no know why this happens the code for on SpinControlChange is exactly the same as the OnEditControlChange , just differant data names. here s the code for both //on user inputting data into edit control box void CTripCalculatorDlg::OnChangeEdit1() { CString SomeValue; //value input into edit control = speed2 m_speed2.GetWindowText(SomeValue); //Convert to an int int speed2 = atoi(LPCSTR(SomeValue)); //adjust the progress bar position m_progress.SetPos(speed2); //adjust the slider bar position m_slider.SetPos(speed2); //Adjust the spinvalue m_spin.SetPos(speed2); m_spinvalue.SetWindowText(LPCTSTR(SomeValue)); } //THIS ALL WORKS FINE //on input intothe spincontrol instead of using the spin arrows void CTripCalculatorDlg::OnChangeSpeed() { CString SomeValue2; //value input into spin control = speed m_speed.GetWindowText(SomeValue2); //Convert to an int int speed = atoi(LPCSTR(SomeValue2)); //adjust the progress bar position m_progress.SetPos(speed); //adjust the slider bar position m_slider.SetPos(speed); //Adjust the editcontrol box m_speed2.SetWindowText(LPCTSTR(SomeValue2)); }//THIS GIVES ME THE ASSERTION ERROR BOX what is the differance betweent hese 2 codes that cause the assertion error? i am perplexed thank you in advance Ed Storey

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Where is the assert failing? When it fails, click Retry and the debugger will drop you at the failed assert. It's probably in MFC, so there should be comments there that explain what's wrong. --Mike-- http://home.inreach.com/mdunn/ "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."   --Buffy

      1 Reply Last reply
      0
      • L Lost User

        Hello all I am wrestling with a strange occurance in Visual C++ and being a newby to it I hope you guys can help. What I have is 3 differant ways a usercan input the same data , either by a spin control, a slider bar or an edit control box. My goal is to have it where if one is adjused the others adjust as well. I have the code down for a change in the slider bar the edit and spin adjust to that value. If the editcontrol is box is used for entering data then both the sldier and the spinbox are updated as well BUT when i try and build the function for the ON_SpinChange function I encounter a new problem. The code compiles just fine, however when i run it I get a gray box that pops up saying the following DEBUG Assertion failed yadda yadda with 3 butons to IGNORE, RETRY or ABORT. and i do no know why this happens the code for on SpinControlChange is exactly the same as the OnEditControlChange , just differant data names. here s the code for both //on user inputting data into edit control box void CTripCalculatorDlg::OnChangeEdit1() { CString SomeValue; //value input into edit control = speed2 m_speed2.GetWindowText(SomeValue); //Convert to an int int speed2 = atoi(LPCSTR(SomeValue)); //adjust the progress bar position m_progress.SetPos(speed2); //adjust the slider bar position m_slider.SetPos(speed2); //Adjust the spinvalue m_spin.SetPos(speed2); m_spinvalue.SetWindowText(LPCTSTR(SomeValue)); } //THIS ALL WORKS FINE //on input intothe spincontrol instead of using the spin arrows void CTripCalculatorDlg::OnChangeSpeed() { CString SomeValue2; //value input into spin control = speed m_speed.GetWindowText(SomeValue2); //Convert to an int int speed = atoi(LPCSTR(SomeValue2)); //adjust the progress bar position m_progress.SetPos(speed); //adjust the slider bar position m_slider.SetPos(speed); //Adjust the editcontrol box m_speed2.SetWindowText(LPCTSTR(SomeValue2)); }//THIS GIVES ME THE ASSERTION ERROR BOX what is the differance betweent hese 2 codes that cause the assertion error? i am perplexed thank you in advance Ed Storey

        R Offline
        R Offline
        Ron Russell
        wrote on last edited by
        #3

        Which line of code in OnChangeSpeed(..) is causing the assertion? When you get the assertion, the message in the Abort/Retry/Ignore message box should tell you where the assertion is coming from. You can then track it back through the call stack. Without knowing more about where the message is coming from and when you are receiving it, I would assume that it is coming off the initial dynamic data exchange operation when your dialog is being created. If this is the case, then you can try one (or both ) of: Replace: m_speed.GetWindowText(SomeValue2) With: if (::IsWindow(m_speed.GetSafeHwnd())) { m_speed.GetWindowText(SomeValue2) } Replace: m_speed2.SetWindowText((LPCTSTR)SomeValue2) With: if (::IsWindow(m_speed2.GetSafeHwnd())) { m_speed2.SetWindowText((LPCTSTR)SomeValue2) } If this fixes your problem, then you will no that your routine is getting called before your control windows are actually getting created. Ronald L. Russell Jr. (Ron) rrussell@ygrest.com

        L 1 Reply Last reply
        0
        • R Ron Russell

          Which line of code in OnChangeSpeed(..) is causing the assertion? When you get the assertion, the message in the Abort/Retry/Ignore message box should tell you where the assertion is coming from. You can then track it back through the call stack. Without knowing more about where the message is coming from and when you are receiving it, I would assume that it is coming off the initial dynamic data exchange operation when your dialog is being created. If this is the case, then you can try one (or both ) of: Replace: m_speed.GetWindowText(SomeValue2) With: if (::IsWindow(m_speed.GetSafeHwnd())) { m_speed.GetWindowText(SomeValue2) } Replace: m_speed2.SetWindowText((LPCTSTR)SomeValue2) With: if (::IsWindow(m_speed2.GetSafeHwnd())) { m_speed2.SetWindowText((LPCTSTR)SomeValue2) } If this fixes your problem, then you will no that your routine is getting called before your control windows are actually getting created. Ronald L. Russell Jr. (Ron) rrussell@ygrest.com

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          ok the lines of code it does not like are similar to this one _AFXCMN_INLINE int CProgressCtrl::SetPos(int nPos) { ASSERT(::IsWindow(m_hWnd)); return (int) ::SendMessage(m_hWnd, PBM_SETPOS, nPos, 0L); } where the ASSERT(::IsWindow(m_hWnd)); line exists. I did what you suggested andthrew in a couple message box warnings to see where it goes BONK I am guessing what is happening is that the code for OnChange is operating before the window is built. I can only assume the reason why this is happening is that when i declare the spin box my default value is 65 and so maybe at that moment it goes down to run this piece of code. However i can understand why it would do this because shouldnt the control box be fully built prior to the program running the onchange function. i can onl assume i have to go into where i first declare the spinbox and its default value and throw the code in after this but this will only work then once on the initial loading and not if the user changes it later. Or is there a way i can do this?

          R 1 Reply Last reply
          0
          • L Lost User

            ok the lines of code it does not like are similar to this one _AFXCMN_INLINE int CProgressCtrl::SetPos(int nPos) { ASSERT(::IsWindow(m_hWnd)); return (int) ::SendMessage(m_hWnd, PBM_SETPOS, nPos, 0L); } where the ASSERT(::IsWindow(m_hWnd)); line exists. I did what you suggested andthrew in a couple message box warnings to see where it goes BONK I am guessing what is happening is that the code for OnChange is operating before the window is built. I can only assume the reason why this is happening is that when i declare the spin box my default value is 65 and so maybe at that moment it goes down to run this piece of code. However i can understand why it would do this because shouldnt the control box be fully built prior to the program running the onchange function. i can onl assume i have to go into where i first declare the spinbox and its default value and throw the code in after this but this will only work then once on the initial loading and not if the user changes it later. Or is there a way i can do this?

            R Offline
            R Offline
            Ron Russell
            wrote on last edited by
            #5

            Note that the assertion is getting thrown because ::IsWindow() is failing in the CProgressControl::SetPos(..) member. This tells you for sure that the progress control has certainly not been created the first time this function has been called. Try the following: Replace: m_progress.SetPos(speed); With: if (::IsWindow(m_progress.GetSafeHwnd())) { m_progress.SetPos(speed); } Replace: m_slider.SetPos(speed); With: if (::IsWindow(m_slider.GetSafeHwnd())) { m_slider.SetPos(speed); } With these modifications, you should not have to alter you architecture too much, and it should work as soon as the controls are created. The code is being called before within the context of the dynamic data exchange function (i.e. your dialog's DoDataExchange(CDataExchange* pDX)). The first time this function is called, the controls have not yet been created, so the modifications I have suggested to not hurt you. Once the controls have been created and you can intereact with them, then the ::IsWindow() function will succeed for each and you should get the desired effect. Ronald L. Russell Jr. (Ron) rrussell@ygrest.com

            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