classes in VC++

P

Piotr Getka

Hi

I have 3 classes:
- CMainFrame
- CPitApp
- CPitView

In class CPitApp i create object CMainFrame* pMainFrame = new
CMainFrame
and in class CMainFrame there is:
public:
int nIndex

And now the question

How can I refer in method OnPrint in class CPitView, that is
CPitView::OnPrint,
to a value of variable nIndex from class CMainFrame??

Is there a way of doing this without creating an object of class
CMainFrame or do i have to create it, and if so how to create it that
it will contains the same data that have object pMainFrame from
CPitApp??

I'm using MF. CMainFrame contains toolbar:
protected: CStyleBar m_wndStyleBar;
and CStyleBar have:
public:
CComboBox m_comboBox;

I simply want to use value returned by
m_wndStyleBar.m_comboBox.GetCurSel()
in method
void CPitView::OnPrint(CDC* pDC, CPrintInfo* pInfo)

Thanks.
 
L

lallous

Piotr Getka said:
Hi

I have 3 classes:
- CMainFrame
- CPitApp
- CPitView

In class CPitApp i create object CMainFrame* pMainFrame = new
CMainFrame
and in class CMainFrame there is:
public:
int nIndex

And now the question

How can I refer in method OnPrint in class CPitView, that is
CPitView::OnPrint,
to a value of variable nIndex from class CMainFrame??

Is there a way of doing this without creating an object of class
CMainFrame or do i have to create it, and if so how to create it that
it will contains the same data that have object pMainFrame from
CPitApp??

I'm using MF. CMainFrame contains toolbar:
protected: CStyleBar m_wndStyleBar;
and CStyleBar have:
public:
CComboBox m_comboBox;

I simply want to use value returned by
m_wndStyleBar.m_comboBox.GetCurSel()
in method
void CPitView::OnPrint(CDC* pDC, CPrintInfo* pInfo)

Thanks.

Inappropriate newsgroup, try "microsoft.public.vc.mfc"
 
J

jeffc

Piotr Getka said:
Hi

I have 3 classes:
- CMainFrame
- CPitApp
- CPitView

In class CPitApp i create object CMainFrame* pMainFrame = new
CMainFrame
and in class CMainFrame there is:
public:
int nIndex

And now the question

How can I refer in method OnPrint in class CPitView, that is
CPitView::OnPrint,
to a value of variable nIndex from class CMainFrame??
Is there a way of doing this without creating an object of class
CMainFrame or do i have to create it, and if so how to create it that
it will contains the same data that have object pMainFrame from
CPitApp??

I would not create it. CPitApp and CPitView have to have a way of
communicating with each other. Are they related in any way right now? Does
one inherit from the other? Does one include the other? If not, then you
need to give one of them a pointer to the other one, or you need to do it
from some main() or other function that has both of them in it. Then you
can add functions to them so that you can get pMainFrame from CPitApp and
pass it to CPitView.
 
J

jeffc

lallous said:
Inappropriate newsgroup, try "microsoft.public.vc.mfc"

<bzzzzzt> Knee-jerk response, and wrong answer. The real question doesn't
have anything to do with MFC.
 
K

Karl Heinz Buchegger

jeffc said:
<bzzzzzt> Knee-jerk response, and wrong answer. The real question doesn't
have anything to do with MFC.

If we are nitpicking then it has everything to do with MFC
(The name of the classes are a strong indication that the OP is
using MFC. If on the other hand he built the classes on his own,
he wouldn't have that problem) and how the object hierarchy of MFC
works. The only thing the OP is missing are the functions AfxGetApp()
and AfxGetMainWnd() which open up the door to what the OP wants to do.
 
J

jeffc

Karl Heinz Buchegger said:
If we are nitpicking then it has everything to do with MFC
(The name of the classes are a strong indication that the OP is
using MFC. If on the other hand he built the classes on his own,
he wouldn't have that problem) and how the object hierarchy of MFC
works.

Only superficially. You would need to know the hierarchy regardless of
whether those are MFC classes. The fact that they are MFC classes are
incidental. The problem would be exactly the same if I inserted my made up
class names in there. It doesn't matter if he's using third party software
or his own - a valid response might be that we need to see the rest of the
code, but his question is still an OO C++ question, not an MFC question.
It's unnecessarily off-putting when people read little more than the subject
line and immediately decide to play net-nanny.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,417
Latest member
DarrenGaun

Latest Threads

Top