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. how to update StatusBar?

how to update StatusBar?

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorialannouncement
11 Posts 6 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Howdy! I've managed to build a status bar and I can assign it a value when the application starts, but how can I update it while the application is running? In the CMainFrame::OnCreate I can use m_wndStatusBar.GetStatusBarCtrl() to get the address of the StatusBarCtrl, but how could I get it outside CMainFrame class? -Marko H. :confused:

    T R 2 Replies Last reply
    0
    • A Anonymous

      Howdy! I've managed to build a status bar and I can assign it a value when the application starts, but how can I update it while the application is running? In the CMainFrame::OnCreate I can use m_wndStatusBar.GetStatusBarCtrl() to get the address of the StatusBarCtrl, but how could I get it outside CMainFrame class? -Marko H. :confused:

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      If you want to set the text in leftmost part of status bar, use CFrameWnd::SetMessageText. For other statusbar panes, use normal ON_UPDATE_CMD_UI mechanism. Tomasz Sowinski -- http://www.shooltz.com

      ** Putt knot yore thrust inn spel chequers. **

      A 1 Reply Last reply
      0
      • T Tomasz Sowinski

        If you want to set the text in leftmost part of status bar, use CFrameWnd::SetMessageText. For other statusbar panes, use normal ON_UPDATE_CMD_UI mechanism. Tomasz Sowinski -- http://www.shooltz.com

        ** Putt knot yore thrust inn spel chequers. **

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        uh-oh... I'm a newbie. What I meant is that from a CDocument class function I want to change the status bar first pane text. How can I write status bar from there? I don't have inside CDOcument class the address of the CFrameWnd class object to use CFrameWnd::SetMessageText.

        T M 2 Replies Last reply
        0
        • A Anonymous

          uh-oh... I'm a newbie. What I meant is that from a CDocument class function I want to change the status bar first pane text. How can I write status bar from there? I don't have inside CDOcument class the address of the CFrameWnd class object to use CFrameWnd::SetMessageText.

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          Use this:

          static_cast<CFrameWnd *>(AfxGetMainWnd())->SetMessageText("I'm on status bar now");

          Keep in mind that this changes the status bar text until next idle update UI cycle is executed. Do you want to change this text permantently? Tomasz Sowinski -- http://www.shooltz.com

          ** Putt knot yore thrust inn spel chequers. **

          L 1 Reply Last reply
          0
          • T Tomasz Sowinski

            Use this:

            static_cast<CFrameWnd *>(AfxGetMainWnd())->SetMessageText("I'm on status bar now");

            Keep in mind that this changes the status bar text until next idle update UI cycle is executed. Do you want to change this text permantently? Tomasz Sowinski -- http://www.shooltz.com

            ** Putt knot yore thrust inn spel chequers. **

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

            Still baffled... I added the code, no effect. I want to show on the status bar when the data was last time saved successfully. Now it just shows the date & time once, when CFrameWnd is created. CDocument object function should be able to update the information permanently.

            T L 2 Replies Last reply
            0
            • L Lost User

              Still baffled... I added the code, no effect. I want to show on the status bar when the data was last time saved successfully. Now it just shows the date & time once, when CFrameWnd is created. CDocument object function should be able to update the information permanently.

              T Offline
              T Offline
              Tomasz Sowinski
              wrote on last edited by
              #6

              Anonymous wrote: I want to show on the status bar when the data was last time saved successfully Instead of standard 'Ready' message, right? If this is the case, override CFrameWnd::GetMessageString:

              void CMainFrame::GetMessageString(UINT nID, CString & rMessage) const
              {
              if (AFX_IDS_IDLEMESSAGE == nID)
              {
              rMessage = "I'm on status bar";
              return;
              }

              CMDIFrameWnd::GetMessageString(nID, rMessage);
              }

              Tomasz Sowinski -- http://www.shooltz.com

              ** Putt knot yore thrust inn spel chequers. **

              1 Reply Last reply
              0
              • L Lost User

                Still baffled... I added the code, no effect. I want to show on the status bar when the data was last time saved successfully. Now it just shows the date & time once, when CFrameWnd is created. CDocument object function should be able to update the information permanently.

                L Offline
                L Offline
                lucy 0
                wrote on last edited by
                #7

                have a look at this article http://www.codeproject.com/script/Submit/ViewHTML.asp?guid=%2Fuseritems%2Fstatusbar%2Easp%2D2%2F20%2F2002 HTH.

                A 1 Reply Last reply
                0
                • A Anonymous

                  Howdy! I've managed to build a status bar and I can assign it a value when the application starts, but how can I update it while the application is running? In the CMainFrame::OnCreate I can use m_wndStatusBar.GetStatusBarCtrl() to get the address of the StatusBarCtrl, but how could I get it outside CMainFrame class? -Marko H. :confused:

                  R Offline
                  R Offline
                  RalfPeter
                  wrote on last edited by
                  #8

                  I take that you're able to create a status bar in MainFrame (including setting pane # and size). Once outside of MainFrame, youneed to get a pointer to it to modify the status bar remotely. #include "MainFrm.h"//or equivalent .h . . . CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;//pointer to mainframe object . . . pFrame->UpdateStatus(1, "1st panel message...");//and so on ralf.riedel@usm.edu

                  A 1 Reply Last reply
                  0
                  • R RalfPeter

                    I take that you're able to create a status bar in MainFrame (including setting pane # and size). Once outside of MainFrame, youneed to get a pointer to it to modify the status bar remotely. #include "MainFrm.h"//or equivalent .h . . . CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;//pointer to mainframe object . . . pFrame->UpdateStatus(1, "1st panel message...");//and so on ralf.riedel@usm.edu

                    A Offline
                    A Offline
                    Anonymous
                    wrote on last edited by
                    #9

                    Aaaahh... I'm a moron (but not moron enough not to write under anonymous ;-) 1st: status bar has this default feature to show "ready" or tooltip on it. I forgot that. I had made my own simple status bar, and I mixed on the way SetMessageText and SetPaneText. 2nd: I couldn't get my hands on the CMainFrame object. Thanks to the replies, now I could! 3rd: (back to the being stupid) When I was instructed to use pFrame->UpdateStatus(1, "1st panel message...") I was just baffled ".. but there is no UpdateStatus in CFrameWnd class..." :-) Ok, here is how it works now, in case this helps someone else. I am NOT updating the default message text on the status bar, I have created my own pane with a text: in MainFrm.h must be lines public: void UpdateStatusBar(CString sMessage = ""); - - - - - - int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } UpdateStatusBar(); return 0; } - - - - - - void CMainFrame::UpdateStatusBar(CString sMessage) { CWinApp* pApp = AfxGetApp(); // the values are read from the registry CString strValue, strValue2; strValue = pApp->GetProfileString("Latest update","Date"); strValue2 = pApp->GetProfileString("Latest update","State"); if (strValue.IsEmpty()) { m_sPaneText = "Data saved: n/a"; } else { m_sPaneText.Format("Data saved: %s, %s", strValue, strValue2); } CStatusBarCtrl &stCtrl = m_wndStatusBar.GetStatusBarCtrl(); // Let's keep it simple... stCtrl.SetSimple(); // in case you want send a different message to the status bar // m_sPaneText is a member of CMainFrame if (sMessage.IsEmpty()) stCtrl.SetText(m_sPaneText,255,0); else stCtrl.SetText(sMessage,255,0); } - - - - - - ...and then at the same in another class... In AppDoc.cpp must be line #include "MainFrm.h" - - - - - - void CAppDoc::SaveDataToServer() { // blah blah blah... save data and other dull jobs... // in my case write to registry. The values are read in // UpdateStatusBar later on and displayed. // update the status bar from CDocument class object CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;//pointer to mainframe object

                    1 Reply Last reply
                    0
                    • L lucy 0

                      have a look at this article http://www.codeproject.com/script/Submit/ViewHTML.asp?guid=%2Fuseritems%2Fstatusbar%2Easp%2D2%2F20%2F2002 HTH.

                      A Offline
                      A Offline
                      Anonymous
                      wrote on last edited by
                      #10

                      The link is a dead end...? Or is it just my Netscape Navigator 4.75?

                      1 Reply Last reply
                      0
                      • A Anonymous

                        uh-oh... I'm a newbie. What I meant is that from a CDocument class function I want to change the status bar first pane text. How can I write status bar from there? I don't have inside CDOcument class the address of the CFrameWnd class object to use CFrameWnd::SetMessageText.

                        M Offline
                        M Offline
                        MarkDoubson
                        wrote on last edited by
                        #11

                        Use ((CFrameWnd*) AfxGetMainWnd())->SetMessageText("...");

                        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