Problems with local data

I want to create a window, but the window needs data from upper class (CMainFrame). How can I be able to get data from this class outside into my CWnd-OnPaint function ?
Who is Participating?
Vinayak KumbarConnect With a Mentor Sr Program ManagerCommented:

I assume that, u have created the window. and u have the CWnd class for it. Then add a include as
#include "MainFrm.h" to its class

Then say u want to access the data in mainframe which is a string by name m_strData.

Then whenever u want to access the string do

CMainFrame *p_Main = (CMainFrame *)AfxGetMainWnd();
p_Main->m_strData will give u that variable.

Hope this helps.
set data in you window creation
Using a global variable.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.