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. Passing datas from an editbox in the toolbar to the view.cpp

Passing datas from an editbox in the toolbar to the view.cpp

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginghelp
11 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.
  • C CrocodileBuck

    Hi together, i coded a project (SDI) with an editbox in the toolbar. By pressing enter the value in the edit will be shown in a msgbox(with a lot of help of Mr. Salesbery ;) ). In my project the document will hande the datas an the view will show them ! Now i have to pass the value in the editbox to the view.cpp in order to show them ! But this won't work :(( Here are some codes;

    **// MyEdit.h
    #pragma once

    class CMyEdit : public CEdit
    {
    public:
    CMyEdit();
    ~CMyEdit();

    	 BOOL PreTranslateMessage(MSG\* pMsg);
    
    	 CString m\_MyEditAusgabe;
    
    protected:
    	DECLARE\_MESSAGE\_MAP()
    

    };**

    **// MyEdit.cpp

    #include "stdafx.h"
    #include "MyEdit.h"

    #include "Test.h"
    #include "NEW_cLoadFile.h"

    CMyEdit::CMyEdit()
    {
    }

    CMyEdit::~CMyEdit()
    {
    }

    BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
    END_MESSAGE_MAP()

    BOOL CMyEdit::PreTranslateMessage(MSG* pMsg)
    {
    NEW_cLoadFile mlf;
    cTest test;

    if (pMsg->message == WM\_KEYDOWN && VK\_RETURN == pMsg->wParam) 
    {
        return TRUE;
    }
    else if (pMsg->message == WM\_KEYUP && VK\_RETURN == pMsg->wParam) 
    {
    	CString cstrNumber;
    	GetWindowText(cstrNumber);
    
        test.testFunktion(cstrNumber);
    
    
        return TRUE;
    }
    
    return CEdit::PreTranslateMessage(pMsg);
    

    }**

    The view.cpp:

    **#include "stdafx.h"
    #include "NonButton Ctrl in ToolBar 1.h"

    #include "MyEdit.h"

    #include "NonButton Ctrl in ToolBar 1Doc.h"
    #include "NonButton Ctrl in ToolBar 1View.h"

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif

    IMPLEMENT_DYNCREATE(CNonButtonCtrlinToolBar1View, CView)

    BEGIN_MESSAGE_MAP(CNonButtonCtrlinToolBar1View, CView)
    //{{AFX_MSG_MAP(CNonButtonCtrlinToolBar1View)
    //}}AFX_MSG_MAP
    // Standard-Druckbefehle
    ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
    END_MESSAGE_MAP()

    CNonButtonCtrlinToolBar1View::CNonButtonCtrlinToolBar1View()
    {
    }

    CNonButtonCtrlinToolBar1View::~CNonButtonCtrlinToolBar1View()
    {
    }

    BOOL CNonButtonCtrlinToolBar1View::PreCreateWindow(CREATESTRUCT& cs)
    {
    return CView::PreCreateWindow(cs);
    }

    void CNonButtonCtrlinToolBar1View::OnDraw(CDC* pDC)
    {
    CNonButtonCtrlinToolBar1Doc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    }

    BOOL CNonButtonCtrlinToolBar1View::OnPreparePrinting(CPrintInfo* pInfo)
    {
    return DoP**

    M Offline
    M Offline
    Mark Salsbery
    wrote on last edited by
    #2

    CrocodileBuck wrote:

    test.testFunktion(cstrNumber);

    What is this? I'm not seeing any code that attempts to notify the view of the enter key being pressed in the edit control. Mark

    Mark Salsbery Microsoft MVP - Visual C++ :java:

    C 1 Reply Last reply
    0
    • M Mark Salsbery

      CrocodileBuck wrote:

      test.testFunktion(cstrNumber);

      What is this? I'm not seeing any code that attempts to notify the view of the enter key being pressed in the edit control. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

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

      Hi Mr.Salsbery, i tried to include the view in the MyEdit.cpp and then to pass the value to the OnUpdate :( I tried different possibilities but no one worked, so i cleaned up the functions ! I know that i have to notify the view, i've read it in the book from swanke but i don't know how to do that ? Thanx for your help best regards Croc

      C 1 Reply Last reply
      0
      • C CrocodileBuck

        Hi Mr.Salsbery, i tried to include the view in the MyEdit.cpp and then to pass the value to the OnUpdate :( I tried different possibilities but no one worked, so i cleaned up the functions ! I know that i have to notify the view, i've read it in the book from swanke but i don't know how to do that ? Thanx for your help best regards Croc

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

        P.S.: I also tried this

        void CNonButtonCtrlinToolBar1View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
        {
        if (VK_RETURN)
        {
        MessageBox("test","test",MB_OK);
        }
        CView::OnChar(nChar, nRepCnt, nFlags);
        }

        I think that thie code will work but there is still don't know how to notify the view in the right way :confused: Thanx for your help hopefully croc

        C 1 Reply Last reply
        0
        • C CrocodileBuck

          P.S.: I also tried this

          void CNonButtonCtrlinToolBar1View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
          {
          if (VK_RETURN)
          {
          MessageBox("test","test",MB_OK);
          }
          CView::OnChar(nChar, nRepCnt, nFlags);
          }

          I think that thie code will work but there is still don't know how to notify the view in the right way :confused: Thanx for your help hopefully croc

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

          OK, OnChar is the wrong way ! :(( Could anybody help me ???:confused: Thanx for your help Best regards Croc

          C 1 Reply Last reply
          0
          • C CrocodileBuck

            OK, OnChar is the wrong way ! :(( Could anybody help me ???:confused: Thanx for your help Best regards Croc

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

            Hi, is my question too stupid, too difficult or have i made mistakes in my posting ? Thanx for your help Best regards Croc

            N M 2 Replies Last reply
            0
            • C CrocodileBuck

              Hi, is my question too stupid, too difficult or have i made mistakes in my posting ? Thanx for your help Best regards Croc

              N Offline
              N Offline
              Nelek
              wrote on last edited by
              #7

              There are another options as different time zones, people works or sleeps and so on. Be patient. Somebody will help you

              Greetings. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

              1 Reply Last reply
              0
              • C CrocodileBuck

                Hi, is my question too stupid, too difficult or have i made mistakes in my posting ? Thanx for your help Best regards Croc

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #8

                Plus if you reply to your own posts, I never get an email notifying me that you posted :) You have the enter key event at the edit control class. Now you need to somehow relay that info to the view. There's an infinite amount of ways to do that.  The easiest thing to do would be to post a user-defined message to the parent of the edit control's parent. You could also post the message to the app's main window - depends on your window hierarchy. Let's say your window hierarchy is like this: FrameWindow    ToolBar       Edit Control    View To get a message to the view from the edit control, post the message to the parent of the edit control's parent, which is the frame window.  Add a handler for the message in the framewindow class.  In that handler, GetActiveView() can be used to get the view window to forward the message on to. That's one example using window messages. Another alternative is to pass window object pointers down to the edit control at creation time, and call methods of the window class directly from the edit control class.  This solution is much less elegant because it binds a bunch of window classes together in a way they can't be reused easily...not a good object-oriented design. Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                C 2 Replies Last reply
                0
                • M Mark Salsbery

                  Plus if you reply to your own posts, I never get an email notifying me that you posted :) You have the enter key event at the edit control class. Now you need to somehow relay that info to the view. There's an infinite amount of ways to do that.  The easiest thing to do would be to post a user-defined message to the parent of the edit control's parent. You could also post the message to the app's main window - depends on your window hierarchy. Let's say your window hierarchy is like this: FrameWindow    ToolBar       Edit Control    View To get a message to the view from the edit control, post the message to the parent of the edit control's parent, which is the frame window.  Add a handler for the message in the framewindow class.  In that handler, GetActiveView() can be used to get the view window to forward the message on to. That's one example using window messages. Another alternative is to pass window object pointers down to the edit control at creation time, and call methods of the window class directly from the edit control class.  This solution is much less elegant because it binds a bunch of window classes together in a way they can't be reused easily...not a good object-oriented design. Mark

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

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

                  Hi. Mr Salsbery ;), thanx for your reply , i will try the first option now ! Thank for your help Best regards Croc

                  1 Reply Last reply
                  0
                  • M Mark Salsbery

                    Plus if you reply to your own posts, I never get an email notifying me that you posted :) You have the enter key event at the edit control class. Now you need to somehow relay that info to the view. There's an infinite amount of ways to do that.  The easiest thing to do would be to post a user-defined message to the parent of the edit control's parent. You could also post the message to the app's main window - depends on your window hierarchy. Let's say your window hierarchy is like this: FrameWindow    ToolBar       Edit Control    View To get a message to the view from the edit control, post the message to the parent of the edit control's parent, which is the frame window.  Add a handler for the message in the framewindow class.  In that handler, GetActiveView() can be used to get the view window to forward the message on to. That's one example using window messages. Another alternative is to pass window object pointers down to the edit control at creation time, and call methods of the window class directly from the edit control class.  This solution is much less elegant because it binds a bunch of window classes together in a way they can't be reused easily...not a good object-oriented design. Mark

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

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

                    Hi Mr. Salsbery, my new MyEdit.cpp :

                    **BOOL CMyEdit::PreTranslateMessage(MSG* pMsg)
                    {
                    NEW_cLoadFile mlf;
                    cTest test;

                    if (pMsg->message == WM\_KEYDOWN && VK\_RETURN == pMsg->wParam) 
                    {
                        return TRUE;
                    }
                    else if (pMsg->message == WM\_KEYUP && VK\_RETURN == pMsg->wParam) 
                    {
                    
                    	CView\* pView = (((CMainFrame\*)AfxGetMainWnd())->GetActiveView());
                     	pView->SendMessage(WM\_SETTEXT,0,'test');
                    	
                        return TRUE;
                    }
                    
                    return CEdit::PreTranslateMessage(pMsg);
                    

                    }**

                    And here is the View.cpp of the project:

                    **.
                    .
                    .
                    .
                    .
                    void CNonButtonCtrlinToolBar1View::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
                    {

                    	CString text;
                    	MessageBox(text,text,MB\_OK);
                    

                    }**

                    This won't work :( Unfortunately i don't know much about the message handling in the mfc :( Could yo perhaps correct the code ???:confused: ;) P.S.:i really forgot the time zone :doh: Thanx for your help Best regards Croc

                    M 1 Reply Last reply
                    0
                    • C CrocodileBuck

                      Hi Mr. Salsbery, my new MyEdit.cpp :

                      **BOOL CMyEdit::PreTranslateMessage(MSG* pMsg)
                      {
                      NEW_cLoadFile mlf;
                      cTest test;

                      if (pMsg->message == WM\_KEYDOWN && VK\_RETURN == pMsg->wParam) 
                      {
                          return TRUE;
                      }
                      else if (pMsg->message == WM\_KEYUP && VK\_RETURN == pMsg->wParam) 
                      {
                      
                      	CView\* pView = (((CMainFrame\*)AfxGetMainWnd())->GetActiveView());
                       	pView->SendMessage(WM\_SETTEXT,0,'test');
                      	
                          return TRUE;
                      }
                      
                      return CEdit::PreTranslateMessage(pMsg);
                      

                      }**

                      And here is the View.cpp of the project:

                      **.
                      .
                      .
                      .
                      .
                      void CNonButtonCtrlinToolBar1View::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
                      {

                      	CString text;
                      	MessageBox(text,text,MB\_OK);
                      

                      }**

                      This won't work :( Unfortunately i don't know much about the message handling in the mfc :( Could yo perhaps correct the code ???:confused: ;) P.S.:i really forgot the time zone :doh: Thanx for your help Best regards Croc

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #11

                      You should probably be sending a user-defined message. The receiving window will need to have a handler for that user-defined message.

                      CrocodileBuck wrote:

                      Unfortunately i don't know much about the message handling in the mfc

                      It's actually Windows messaging - that's essential knowledge for Windows programming. I'd definitely recommend studying that and knowing it if you're going to do Windows GUI programming :) Mark

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      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