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. How to update a view from toolbar in the right way !

How to update a view from toolbar in the right way !

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++helptutorialannouncement
6 Posts 2 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.
  • C Offline
    C Offline
    CrocodileBuck
    wrote on last edited by
    #1

    Hi, i have got the following questin: I have a SDI Project with a RichTextControl and an editbox in the toolbar. I want to pass the value in the editboc(user input) to a funktion in the document.cpp. I want to load some data in the document and then i want to update te view with this datas. I know how to update the view with datas coming fram the document, but i don't know the right way to pass a value from the editbox in my toolbar to the document !!!??? Here is some code :

    **BOOL NEW_cToolBar::PreTranslateMessage(MSG* pMsg)
    {
    if (pMsg->message == WM_KEYDOWN && VK_RETURN == pMsg->wParam)
    {
    return TRUE;
    }
    else if (pMsg->message == WM_KEYUP && VK_RETURN == pMsg->wParam)
    {

    	CString chrBuf;
    	m\_Ctrl\_EDIT.GetWindowText(chrBuf); //<-- The Value
    // 	MessageBox(chrBuf, chrBuf ,MB\_OK);
    
    
    	//((CMainFrame\*)AfxGetMainWnd())->GetActiveView()->GetDocument()->UpdateAllViews(NULL);
    
        return TRUE;
    }
    return false;
    

    }**

    **void CApplicationView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
    {
    CTheReaderDoc *pDoc = GetDocument ();
    CRichEditCtrl &rCtrl = GetRichEditCtrl();
    rCtrl.SetWindowText (pDoc->m_cstrAusgabe);

    rCtrl.SetFont(pDoc->m\_ptrFont);
    rCtrl.SetModify(TRUE);		
    

    }**

    Or is it better to pass the Value directly to the View without using a document ?:confused: And when yes, how can I do that ? Please help me ! Many thanx Croc

    I 1 Reply Last reply
    0
    • C CrocodileBuck

      Hi, i have got the following questin: I have a SDI Project with a RichTextControl and an editbox in the toolbar. I want to pass the value in the editboc(user input) to a funktion in the document.cpp. I want to load some data in the document and then i want to update te view with this datas. I know how to update the view with datas coming fram the document, but i don't know the right way to pass a value from the editbox in my toolbar to the document !!!??? Here is some code :

      **BOOL NEW_cToolBar::PreTranslateMessage(MSG* pMsg)
      {
      if (pMsg->message == WM_KEYDOWN && VK_RETURN == pMsg->wParam)
      {
      return TRUE;
      }
      else if (pMsg->message == WM_KEYUP && VK_RETURN == pMsg->wParam)
      {

      	CString chrBuf;
      	m\_Ctrl\_EDIT.GetWindowText(chrBuf); //<-- The Value
      // 	MessageBox(chrBuf, chrBuf ,MB\_OK);
      
      
      	//((CMainFrame\*)AfxGetMainWnd())->GetActiveView()->GetDocument()->UpdateAllViews(NULL);
      
          return TRUE;
      }
      return false;
      

      }**

      **void CApplicationView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
      {
      CTheReaderDoc *pDoc = GetDocument ();
      CRichEditCtrl &rCtrl = GetRichEditCtrl();
      rCtrl.SetWindowText (pDoc->m_cstrAusgabe);

      rCtrl.SetFont(pDoc->m\_ptrFont);
      rCtrl.SetModify(TRUE);		
      

      }**

      Or is it better to pass the Value directly to the View without using a document ?:confused: And when yes, how can I do that ? Please help me ! Many thanx Croc

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      You have loads of ways to do this, really, depending on your application. What it looks like you should do is have a function in your document, eg:?

      BOOL CMyDoc::UpdateSomeTextField (CString s)
      {
      if ( !some validation here )
      return FALSE;

      m\_KeepString = s;
      UpdateAllViews (NULL);
      return TRUE;
      

      }

      and in your PreTranslateMessage function, call this member function. This will decouple your document from the toolbar, and remove the view from the equation. Also, CFrameWnd has a function GetActiveDocument which will be a bit safer for you - and may make it easier when you move to an MDI model (if you choose). Iain.

      Iain Clarke appears because CPallini still cares.

      C 1 Reply Last reply
      0
      • I Iain Clarke Warrior Programmer

        You have loads of ways to do this, really, depending on your application. What it looks like you should do is have a function in your document, eg:?

        BOOL CMyDoc::UpdateSomeTextField (CString s)
        {
        if ( !some validation here )
        return FALSE;

        m\_KeepString = s;
        UpdateAllViews (NULL);
        return TRUE;
        

        }

        and in your PreTranslateMessage function, call this member function. This will decouple your document from the toolbar, and remove the view from the equation. Also, CFrameWnd has a function GetActiveDocument which will be a bit safer for you - and may make it easier when you move to an MDI model (if you choose). Iain.

        Iain Clarke appears because CPallini still cares.

        C Offline
        C Offline
        CrocodileBuck
        wrote on last edited by
        #3

        Hi Mr.Clarke, thank you very much for your reply. I added this to the document.h:

        **.
        .
        .
        .
        public:
        CString m_KeepString;

        public:
        BOOL bUpdatetextField(CString);**

        And this in the document.cpp:

        **BOOL CDocumentDoc::bUpdatetextField(CString s)
        {
        m_KeepString = s;
        UpdateAllViews(NULL);

        return TRUE;
        

        }**

        But how can I call the bUpdatetextFiled from my toolbar :

        **BOOL New_cToolBar::PreTranslateMessage(MSG* pMsg)
        {
        if (pMsg->message == WM_KEYDOWN && VK_RETURN == pMsg->wParam)
        {
        return TRUE;
        }
        else if (pMsg->message == WM_KEYUP && VK_RETURN == pMsg->wParam)
        {

        ????????? function call ???????????
        
        // ((CMainFrame\*)AfxGetMainWnd())->GetActiveView()->GetDocument();
        
        
            return TRUE;
        }
        return false;
        

        }**

        :confused::confused::confused::confused: Many many thx best regards croc

        C 1 Reply Last reply
        0
        • C CrocodileBuck

          Hi Mr.Clarke, thank you very much for your reply. I added this to the document.h:

          **.
          .
          .
          .
          public:
          CString m_KeepString;

          public:
          BOOL bUpdatetextField(CString);**

          And this in the document.cpp:

          **BOOL CDocumentDoc::bUpdatetextField(CString s)
          {
          m_KeepString = s;
          UpdateAllViews(NULL);

          return TRUE;
          

          }**

          But how can I call the bUpdatetextFiled from my toolbar :

          **BOOL New_cToolBar::PreTranslateMessage(MSG* pMsg)
          {
          if (pMsg->message == WM_KEYDOWN && VK_RETURN == pMsg->wParam)
          {
          return TRUE;
          }
          else if (pMsg->message == WM_KEYUP && VK_RETURN == pMsg->wParam)
          {

          ????????? function call ???????????
          
          // ((CMainFrame\*)AfxGetMainWnd())->GetActiveView()->GetDocument();
          
          
              return TRUE;
          }
          return false;
          

          }**

          :confused::confused::confused::confused: Many many thx best regards croc

          C Offline
          C Offline
          CrocodileBuck
          wrote on last edited by
          #4

          Hi :( ; is there really no hope :confused: best regards CrocodileBuck

          I 1 Reply Last reply
          0
          • C CrocodileBuck

            Hi :( ; is there really no hope :confused: best regards CrocodileBuck

            I Offline
            I Offline
            Iain Clarke Warrior Programmer
            wrote on last edited by
            #5

            Err, some of us go home, and have a life... Try:

            CMainFrame \*pMF = STATIC\_DOWNCAST(CMainFrame, AfxGetMainFrame ());
            CMyDoc \*pDoc = STATIC\_DOWNCAST(CMyDoc, pMF->GetActiveDocument ());
            pDoc->UpdateMyField (s);
            

            And check the debugger as you go, as this is from memory. Iain.

            Iain Clarke appears because CPallini still cares.

            C 1 Reply Last reply
            0
            • I Iain Clarke Warrior Programmer

              Err, some of us go home, and have a life... Try:

              CMainFrame \*pMF = STATIC\_DOWNCAST(CMainFrame, AfxGetMainFrame ());
              CMyDoc \*pDoc = STATIC\_DOWNCAST(CMyDoc, pMF->GetActiveDocument ());
              pDoc->UpdateMyField (s);
              

              And check the debugger as you go, as this is from memory. Iain.

              Iain Clarke appears because CPallini still cares.

              C Offline
              C Offline
              CrocodileBuck
              wrote on last edited by
              #6

              Hi Mr.Clarke, >> Err, some of us go home, and have a life...:cool: L*O*L yeah that's absolutely corect ;) Many, many, many thanx, now it will work ...:cool: ;) :laugh: :-D :) Thanx for your great help very best regards Croc P.S.: Instead of AfxGetMainFrame() i have to use AfxGetMainWnd() ;)

              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