How to get access to CMyView variables from CMainFrame in MFC
-
Hi Everybody I have a SDI project. I have created some dynamics ComboBoxes in my toolbar by ".Create" in my CMainFrame Class. My ComboBoxes are working properly in CMainFrame but I want to set some of my variables in CMyView class by void CMainFrame::OnSelchange_My_Dynamics_Combo_1(). I did my best but I was not successful to send/set data to/at CMyView class. I am beginner in MFC, Please guide me. Best Regards
-
Dear David I meant: I have some public variables in CMyView class.These variables must be updated from INSIDE the CMyMainFrame class. How can I get access from CMyMainFrame to public variables in CMyView class? In fact,how can I update public variables I have in CMyView class from CMyMainFrame class? Best Regads
Member 15033704 wrote:
How can I get access from CMyMainFrame to public variables in CMyView class?
Have you tried calling
GetActiveView()
?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Your
CMyView
object should be a member of theCMainFrame
, so you just need to add apublic
method toCMyView
that does what you want.Dear Friend I did it,Because it seemed very easy, but then I get CDocument ERROR! After adding #include "CMyView.h" into CMyMainFrame, I get CDocument ERROR! I searched a lot on the internet, all say use GetActiveView() but it does not work! Best Regards
-
Dear Friend I did it,Because it seemed very easy, but then I get CDocument ERROR! After adding #include "CMyView.h" into CMyMainFrame, I get CDocument ERROR! I searched a lot on the internet, all say use GetActiveView() but it does not work! Best Regards
-
Member 15033704 wrote:
How can I get access from CMyMainFrame to public variables in CMyView class?
Have you tried calling
GetActiveView()
?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
Yes, dear friend I write the following code inside MyCMainFrame file : MyCView*pView = static_cast (GetActiveWindow()); then when I include MyCView.h file inside MyCMainFrame file to use GetActiveView(), then I get CDocument ERROR!!!
-
Sorry, we cannot guess what you are doing. You need to show the code that that you are running, and explain exactly what error(s) you see and where it happens.
Dear friend I write the following code inside MyCMainFrame.cpp file : MyCView*pView = static_cast (GetActiveWindow()); pView->m_CMyView_Pulic_Variable; To get access to public variables inside CMyview class. But when I include MyCView.h file inside MyCMainFrame file to use GetActiveView(), then I get CDocument ERROR! In fact, I just want to change a public variable inside CMyView class from MyCMainFrame. How can I get access to CMyView class public variables, from MyCMainFrame? Best Regards
-
Dear friend I write the following code inside MyCMainFrame.cpp file : MyCView*pView = static_cast (GetActiveWindow()); pView->m_CMyView_Pulic_Variable; To get access to public variables inside CMyview class. But when I include MyCView.h file inside MyCMainFrame file to use GetActiveView(), then I get CDocument ERROR! In fact, I just want to change a public variable inside CMyView class from MyCMainFrame. How can I get access to CMyView class public variables, from MyCMainFrame? Best Regards
-
Why are you using
GetActiveWindow
rather thanGetActiveView
? And what is the exact text of the error you receive and where does it occur?Dear Richard Firstly "HAPPY NEW YEAR" Many thanks for your help, I was engaged with the CMyDoc error, finally I found it, simply it was redefinition of CMyDoc header in 2 different classes that I never guessed such mistake. Best Regards
-
Dear Richard Firstly "HAPPY NEW YEAR" Many thanks for your help, I was engaged with the CMyDoc error, finally I found it, simply it was redefinition of CMyDoc header in 2 different classes that I never guessed such mistake. Best Regards
-
Hi Everybody I have a SDI project. I have created some dynamics ComboBoxes in my toolbar by ".Create" in my CMainFrame Class. My ComboBoxes are working properly in CMainFrame but I want to set some of my variables in CMyView class by void CMainFrame::OnSelchange_My_Dynamics_Combo_1(). I did my best but I was not successful to send/set data to/at CMyView class. I am beginner in MFC, Please guide me. Best Regards
For future use: MFC Doc/View: How to obtain a pointer to various objects?[^]
-
For future use: MFC Doc/View: How to obtain a pointer to various objects?[^]
Excellent, Thanks