How to update a view from toolbar in the right way !
-
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
-
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
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.
-
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.
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
-
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
Hi :( ; is there really no hope :confused: best regards CrocodileBuck
-
Hi :( ; is there really no hope :confused: best regards CrocodileBuck
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.
-
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.
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() ;)