Click here to Skip to main content
15,888,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I am pretty new to the Document/View based MFC programs.
I am searching for 2 days now to an answer to my problem.

1 I have a toolbar derived class called CToolBarEditor
2 I have derived one so I could replace one of the buttons with an CEdit
3 CToolBarEditor is a member of the Mainframe
4 My main form is a Document/View derived from CFormView called CPC_applicationView

As the view is not a DIRECT member of the Mainframe I can not acces the data in it through the MainFrame.

I want:
- the event handler of the toolbar buttons in CPC_applicationView (already done)
- from here accesing the MainFrame and so the toolbar (caption of edit box)

OR:
- the event handler of the toolbar buttons in MainFrame (already tried)
- from here I can access the toolbar.
- from here accesing the CPC_applicationView and so the members/varibales within.

Concluded: I want bidirection communication between CToolBarEditor and CPC_applicationView

GetParent() does not work because I used DERIVED classes and not the base ones.
also (CMainFrame*)GetParent()->... does not work because of design time.

Please help, even the sample of MFC: document/view doesn't give the solution....
Posted

1) make your CXXXtoolbar member a public member in mainfrm.h
2) include mainfrm.h in your view class cpp
3) use code like this below to access your toolbar:
CMainFrame *pFrame = (CMainFrame *)GetApp()->m_pMainWnd;
if (pFrame)
pFrame->m_wndToolBar.DoSomeFunction();
 
Share this answer
 
Thank you for your reply.
How does it come that I couldn't find a solution like this on internet?
Or why does the example project not have this?
Anyway, Now I know how to do it, thank you, it worked.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900