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. MFC STATUS BAR PROBLEM

MFC STATUS BAR PROBLEM

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++tools
10 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.
  • T Offline
    T Offline
    T RATHA KRISHNAN
    wrote on last edited by
    #1

    I've created a menu called Tools where in I have created a menu item called Preferences. If we click the Prefernces menu item Preferences Dialog Box will open. In that Dialog Box I have an edit box. The message entered in this edit box is displayed in the second panel of the status bar (i.e) panel no.1. My Requirement is: The second panel should be of a default size and it should grow according to the length of the message entered in the edit box. How can I achieve this in MFC? Can any one help? I have tried this also. But it didn't work. CStatusBar::SetPaneInfo( int nIndex, UINT nID, UINT nStyle, int cxWidth ); The function that displays the message is: void CPerspectiveDoc::OnShowMsg(CCmdUI* pCmdUI) { char str1[150]; //int len = message.GetLength(); sprintf(str1, "%s",message.GetString()); pCmdUI->Enable(TRUE); pCmdUI->SetText((const char *)str1); //m_wndStatusBar.SetPaneInfo(1, IDS_MESSAGE, SBPS_STRETCH, len); } When I remove the comment from the following code, it shows me an exception stating that "Unhandled exception at 0x7c1d71bb (MFC71.dll) in Perspective.exe: 0xC0000005: Access violation writing location 0x00000014." The commented out line of code is: //m_wndStatusBar.SetPaneInfo(1, IDS_MESSAGE, SBPS_STRETCH, len); Any one Please help.

    K realJSOPR 3 Replies Last reply
    0
    • T T RATHA KRISHNAN

      I've created a menu called Tools where in I have created a menu item called Preferences. If we click the Prefernces menu item Preferences Dialog Box will open. In that Dialog Box I have an edit box. The message entered in this edit box is displayed in the second panel of the status bar (i.e) panel no.1. My Requirement is: The second panel should be of a default size and it should grow according to the length of the message entered in the edit box. How can I achieve this in MFC? Can any one help? I have tried this also. But it didn't work. CStatusBar::SetPaneInfo( int nIndex, UINT nID, UINT nStyle, int cxWidth ); The function that displays the message is: void CPerspectiveDoc::OnShowMsg(CCmdUI* pCmdUI) { char str1[150]; //int len = message.GetLength(); sprintf(str1, "%s",message.GetString()); pCmdUI->Enable(TRUE); pCmdUI->SetText((const char *)str1); //m_wndStatusBar.SetPaneInfo(1, IDS_MESSAGE, SBPS_STRETCH, len); } When I remove the comment from the following code, it shows me an exception stating that "Unhandled exception at 0x7c1d71bb (MFC71.dll) in Perspective.exe: 0xC0000005: Access violation writing location 0x00000014." The commented out line of code is: //m_wndStatusBar.SetPaneInfo(1, IDS_MESSAGE, SBPS_STRETCH, len); Any one Please help.

      K Offline
      K Offline
      kasturi_haribabu
      wrote on last edited by
      #2

      I have tried with an and this code works. May be something else is wrong... CString message; message = "A LOOOOOOOOOOOOOOOOOOOOONG MESSAGE000000"; int len = message.GetLength(); m_wndStatusBar.SetPaneText(1,(LPCTSTR)message,FALSE); m_wndStatusBar.SetPaneInfo(1, 1, SBPS_STRETCH, len);

      T 1 Reply Last reply
      0
      • T T RATHA KRISHNAN

        I've created a menu called Tools where in I have created a menu item called Preferences. If we click the Prefernces menu item Preferences Dialog Box will open. In that Dialog Box I have an edit box. The message entered in this edit box is displayed in the second panel of the status bar (i.e) panel no.1. My Requirement is: The second panel should be of a default size and it should grow according to the length of the message entered in the edit box. How can I achieve this in MFC? Can any one help? I have tried this also. But it didn't work. CStatusBar::SetPaneInfo( int nIndex, UINT nID, UINT nStyle, int cxWidth ); The function that displays the message is: void CPerspectiveDoc::OnShowMsg(CCmdUI* pCmdUI) { char str1[150]; //int len = message.GetLength(); sprintf(str1, "%s",message.GetString()); pCmdUI->Enable(TRUE); pCmdUI->SetText((const char *)str1); //m_wndStatusBar.SetPaneInfo(1, IDS_MESSAGE, SBPS_STRETCH, len); } When I remove the comment from the following code, it shows me an exception stating that "Unhandled exception at 0x7c1d71bb (MFC71.dll) in Perspective.exe: 0xC0000005: Access violation writing location 0x00000014." The commented out line of code is: //m_wndStatusBar.SetPaneInfo(1, IDS_MESSAGE, SBPS_STRETCH, len); Any one Please help.

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #3
        1. There are several status bar articles on CP. Check one of them to see if they have the info you need. I used one that makes it a bit simpler to add custom panes and update them when necessary. In fact, there's one article here that allows better control over the status bar than the default MFC class allows. Try here: http://www.codeproject.com/statusbar/ExtStatusControlBar.asp[^] 2) This comment is based on a complete lack of knowledge where your requirements are concerned - It seems to me that you're approaching this incorrectly. If it were me I'd be setting the status bar pane text when the dialog box exists with IDOK. Handling it in a command update function is beyond funky. If you set the text in the dialog box, there's no reason for it to change in the status bar until you change it in the dialog box again.

        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        1 Reply Last reply
        0
        • K kasturi_haribabu

          I have tried with an and this code works. May be something else is wrong... CString message; message = "A LOOOOOOOOOOOOOOOOOOOOONG MESSAGE000000"; int len = message.GetLength(); m_wndStatusBar.SetPaneText(1,(LPCTSTR)message,FALSE); m_wndStatusBar.SetPaneInfo(1, 1, SBPS_STRETCH, len);

          T Offline
          T Offline
          T RATHA KRISHNAN
          wrote on last edited by
          #4

          The method that displays message is: The function that displays the message is: void CPerspectiveDoc::OnShowMsg(CCmdUI* pCmdUI) { char str1[150]; //int len = message.GetLength(); sprintf(str1, "%s",message.GetString()); pCmdUI->Enable(TRUE); pCmdUI->SetText((const char *)str1); //m_wndStatusBar.SetPaneInfo(1, IDS_MESSAGE, SBPS_STRETCH, len); } I can't use SetPaneText and SetPaneInfo with this CCmdUI* (pCmdUI) object pointer. If I comment out this: //m_wndStatusBar.SetPaneInfo(1, IDS_MESSAGE, SBPS_STRETCH, len);I got an exeption. More over we should not initialize the string "message" in the code. We should get it through GetString method for edit box. The status bar pane should grow according to the length of the string. static UINT indicators[] = { 0,// ID_SEPARATOR IDS_MESSAGE, ID_SHOWFPS, }; This method is in some other source file. Is this a reason for this error?

          1 Reply Last reply
          0
          • T T RATHA KRISHNAN

            I've created a menu called Tools where in I have created a menu item called Preferences. If we click the Prefernces menu item Preferences Dialog Box will open. In that Dialog Box I have an edit box. The message entered in this edit box is displayed in the second panel of the status bar (i.e) panel no.1. My Requirement is: The second panel should be of a default size and it should grow according to the length of the message entered in the edit box. How can I achieve this in MFC? Can any one help? I have tried this also. But it didn't work. CStatusBar::SetPaneInfo( int nIndex, UINT nID, UINT nStyle, int cxWidth ); The function that displays the message is: void CPerspectiveDoc::OnShowMsg(CCmdUI* pCmdUI) { char str1[150]; //int len = message.GetLength(); sprintf(str1, "%s",message.GetString()); pCmdUI->Enable(TRUE); pCmdUI->SetText((const char *)str1); //m_wndStatusBar.SetPaneInfo(1, IDS_MESSAGE, SBPS_STRETCH, len); } When I remove the comment from the following code, it shows me an exception stating that "Unhandled exception at 0x7c1d71bb (MFC71.dll) in Perspective.exe: 0xC0000005: Access violation writing location 0x00000014." The commented out line of code is: //m_wndStatusBar.SetPaneInfo(1, IDS_MESSAGE, SBPS_STRETCH, len); Any one Please help.

            realJSOPR Offline
            realJSOPR Offline
            realJSOP
            wrote on last edited by
            #5

            By the way, I think you're going to have to calculate the new size manually and then pass that value into the status bar.

            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

            T 1 Reply Last reply
            0
            • realJSOPR realJSOP

              By the way, I think you're going to have to calculate the new size manually and then pass that value into the status bar.

              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
              -----
              "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

              T Offline
              T Offline
              T RATHA KRISHNAN
              wrote on last edited by
              #6

              Not only manually, the status bar pane should grow dynamically i.e as and when I enter one character in to the edit box the status bar pane should grow one character length. This way the status pane will have to grow for hundred characters length that is entered via the edit box.How can I do?

              realJSOPR 1 Reply Last reply
              0
              • T T RATHA KRISHNAN

                Not only manually, the status bar pane should grow dynamically i.e as and when I enter one character in to the edit box the status bar pane should grow one character length. This way the status pane will have to grow for hundred characters length that is entered via the edit box.How can I do?

                realJSOPR Offline
                realJSOPR Offline
                realJSOP
                wrote on last edited by
                #7

                Well, I wouldn't change the statusbar until AFTER the user clicks OK, but that's just me. However... 1) In your dialog box, you would have to handle the EN_CHANGE message for the edit control. Every time the user types a character you have to calculate the new width of the string in pixels. 2) I would send a message to the parent view that contained a pointer to the string, and let the parent view do the width calculations. This message would probably be one you have to define (WM_APP+n) and manually add a handler for in your view. 3) When the view gets the message, it gets the string from the passed-in pointer value and creates a CPaintDC object. This dc object can then provide the width of the string via the GetTextExtent() function. This new width would be passed to the status bar for the appropriate pane, and the text would be applied to that pane. If you decide to handle the status bar update after the user clicks the OK button in your dialog box, you can skip steps 1 and 2, and just retrieve the string from the dialog box itself, and do step 3. I assume you're a programmer (and you obviously have access to the internet, so you can look stuff up on your own), so I leave it to you to work out the specifics.

                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                -----
                "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                T 1 Reply Last reply
                0
                • realJSOPR realJSOP

                  Well, I wouldn't change the statusbar until AFTER the user clicks OK, but that's just me. However... 1) In your dialog box, you would have to handle the EN_CHANGE message for the edit control. Every time the user types a character you have to calculate the new width of the string in pixels. 2) I would send a message to the parent view that contained a pointer to the string, and let the parent view do the width calculations. This message would probably be one you have to define (WM_APP+n) and manually add a handler for in your view. 3) When the view gets the message, it gets the string from the passed-in pointer value and creates a CPaintDC object. This dc object can then provide the width of the string via the GetTextExtent() function. This new width would be passed to the status bar for the appropriate pane, and the text would be applied to that pane. If you decide to handle the status bar update after the user clicks the OK button in your dialog box, you can skip steps 1 and 2, and just retrieve the string from the dialog box itself, and do step 3. I assume you're a programmer (and you obviously have access to the internet, so you can look stuff up on your own), so I leave it to you to work out the specifics.

                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                  -----
                  "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                  T Offline
                  T Offline
                  T RATHA KRISHNAN
                  wrote on last edited by
                  #8

                  When I add the EN_CHANGE message the following error occurs. error C2440: cannot convert from CSize to int error C2440:'static_cast':cannot covert from 'int(__thiscall CPreferences::*)(void)' to 'AFX_PMSG' the code I added was, int CPreferences::OnEnChangeEditmessage() { CPaintDC *pDC; int size; size = pDC->GetTextExtent(m_strMessage); return size; } The message map I added was, ON_EN_CHANGE(IDC_EDITMESSAGE, OnEnChangeEditmessage) The afx message I added was, afx_msg int OnEnChangeEditmessage(); What to do? -- modified at 4:00 Tuesday 6th February, 2007

                  realJSOPR 1 Reply Last reply
                  0
                  • T T RATHA KRISHNAN

                    When I add the EN_CHANGE message the following error occurs. error C2440: cannot convert from CSize to int error C2440:'static_cast':cannot covert from 'int(__thiscall CPreferences::*)(void)' to 'AFX_PMSG' the code I added was, int CPreferences::OnEnChangeEditmessage() { CPaintDC *pDC; int size; size = pDC->GetTextExtent(m_strMessage); return size; } The message map I added was, ON_EN_CHANGE(IDC_EDITMESSAGE, OnEnChangeEditmessage) The afx message I added was, afx_msg int OnEnChangeEditmessage(); What to do? -- modified at 4:00 Tuesday 6th February, 2007

                    realJSOPR Offline
                    realJSOPR Offline
                    realJSOP
                    wrote on last edited by
                    #9

                    Did you look on MSDN for documentation on GetTextExtent()? It returns a CSize structure, NOT an int.

                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                    -----
                    "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                    T 1 Reply Last reply
                    0
                    • realJSOPR realJSOP

                      Did you look on MSDN for documentation on GetTextExtent()? It returns a CSize structure, NOT an int.

                      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                      -----
                      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                      T Offline
                      T Offline
                      T RATHA KRISHNAN
                      wrote on last edited by
                      #10

                      Ya! It's true. When I use the following code, void CPerspectiveDoc::OnShowMsg(CCmdUI* pCmdUI) { //char str1[150]; CString strValue; strValue.Format("%s", message.GetString()); //strValue.SetLength(100); //sprintf(str1, "%s",message.GetString()); pCmdUI->Enable(TRUE); pCmdUI->SetText(strValue); CDC* pDC = m_wndStatusBar.GetDC(); CSize mSize = pDC->GetTextExtent(strValue); m_wndStatusBar.SetPaneInfo(1, IDS_MESSAGE, SBPS_NORMAL, mSize.cx); //m_wndStatusBar.SetPaneInfo(1, IDS_MESSAGE, SBPS_STRETCH, len); } I got the following exception. 'Unhandled exception at 0x7c1d71bb (MFC71.dll) in Perspective.exe: 0xC0000005: Access violation writing location 0x00000014.' If I break this exception, it ends in a class barstat.cpp If I comment out this line, m_wndStatusBar.SetPaneInfo(1, IDS_MESSAGE, SBPS_NORMAL, mSize.cx); exception didn't arise. I have declared m_wndStatusBar variable in some other class. How do I make this variable visible to this class CPerspectiveDoc. -- modified at 23:42 Tuesday 6th February, 2007

                      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