Passing datas from an editbox in the toolbar to the view.cpp
-
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 onceclass 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__;
#endifIMPLEMENT_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**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:
-
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:
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
-
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
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
-
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
OK, OnChar is the wrong way ! :(( Could anybody help me ???:confused: Thanx for your help Best regards Croc
-
OK, OnChar is the wrong way ! :(( Could anybody help me ???:confused: Thanx for your help Best regards Croc
Hi, is my question too stupid, too difficult or have i made mistakes in my posting ? Thanx for your help Best regards Croc
-
Hi, is my question too stupid, too difficult or have i made mistakes in my posting ? Thanx for your help Best regards Croc
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
-
Hi, is my question too stupid, too difficult or have i made mistakes in my posting ? Thanx for your help Best regards Croc
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:
-
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:
Hi. Mr Salsbery ;), thanx for your reply , i will try the first option now ! Thank for your help Best regards Croc
-
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:
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
-
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
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: