Access control variables and methods of other classes in SDI Application
-
Hi, In a SDI Application, I have three Classes CMainFrame, CLeftView(Derived from CTreeView) and CMyPrgView(Derived from CFormView). Now I want to access all class member, function and control variables of each class from rest of classes. Like when I click on tree items(LeftView), Controls placed on FormView should respond or clicking on menu(MainFrame) both TreeView items and Formview controls respond and vice versa. Please tell me any standard way to access other class members and function in SDI Application. Regards, Maxim.
-
Hi, In a SDI Application, I have three Classes CMainFrame, CLeftView(Derived from CTreeView) and CMyPrgView(Derived from CFormView). Now I want to access all class member, function and control variables of each class from rest of classes. Like when I click on tree items(LeftView), Controls placed on FormView should respond or clicking on menu(MainFrame) both TreeView items and Formview controls respond and vice versa. Please tell me any standard way to access other class members and function in SDI Application. Regards, Maxim.
Write your controling function in Application class (Derived from CWinApp).
class CYourApp : public CWinApp { public: void YourControlingFunction(); } //Wherever required use like this, CYourApp* pApp = (CYourApp*)AfxGetApp(); if(NULL != pApp) { pApp->YourControlingFunction(); }
Hope this will serve your purpose. Regards, Paresh.
-
Write your controling function in Application class (Derived from CWinApp).
class CYourApp : public CWinApp { public: void YourControlingFunction(); } //Wherever required use like this, CYourApp* pApp = (CYourApp*)AfxGetApp(); if(NULL != pApp) { pApp->YourControlingFunction(); }
Hope this will serve your purpose. Regards, Paresh.
Thanks for your reply. I tried following code in my
CLeftView
class on Tree item selection(OnTvnSelchanged
).CMyPrgView* pView= (CMyPrgView*)AfxGetApp();
if(NULL!=pView)
{
pView->m_Edit1.SetWindowText(L"P");
}But getting "Debug Assertion Failed" error on
SetWindowText()
. -
Thanks for your reply. I tried following code in my
CLeftView
class on Tree item selection(OnTvnSelchanged
).CMyPrgView* pView= (CMyPrgView*)AfxGetApp();
if(NULL!=pView)
{
pView->m_Edit1.SetWindowText(L"P");
}But getting "Debug Assertion Failed" error on
SetWindowText()
. -
The AfxGetApp() will return your application class poniter not view. Here you have casted the AppClass to ViewClass poniter. This is not possible.
akt
I did it as suggested by "Paresh". I have also tried
CMyPrgView* pView = new CMyPrgView();
but still Assertion error comes. What i do, please suggest me. -
Hi, In a SDI Application, I have three Classes CMainFrame, CLeftView(Derived from CTreeView) and CMyPrgView(Derived from CFormView). Now I want to access all class member, function and control variables of each class from rest of classes. Like when I click on tree items(LeftView), Controls placed on FormView should respond or clicking on menu(MainFrame) both TreeView items and Formview controls respond and vice versa. Please tell me any standard way to access other class members and function in SDI Application. Regards, Maxim.
-
I did it as suggested by "Paresh". I have also tried
CMyPrgView* pView = new CMyPrgView();
but still Assertion error comes. What i do, please suggest me.