Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting variables from a window 1

Status
Not open for further replies.

Bones3

Programmer
Jul 27, 2003
151
US
How can I interact with variables in my CChildView class from other objects? I have tried AfxGetMainWnd()->int GetVariable(), which compiled fine, but does not return the correct number. While debugging I noticed that somehow it changed from 5 to 0 once CChildView::GetVariable was called. I don't think my CChildView is the main window, (CMainFrame is) so how do I get ahold of it properly?

thx in advance

-Bones
 
sorry, what kind of variable would you like to get?

Ion Filipski
1c.bmp
 
Integer.

Here is what I did that didn't work; don't know if it will help or not.

CChildView* pView = (CChildView*)AfxGetMainWnd();
// member function returning int
m_reputation = pView->GetReputation();

I believe CMainFrame is the actual MainWnd(), so does that mean AfxGetMainWnd() only works for CMainFrame? If so, what is the best way to call CChildView:: int GetReputation()?





-Bones
 
I believe you should get some window text, use GetWindowText for control you want to see the value

Ion Filipski
1c.bmp
 
Document/View relationships:
1. A document keeps a list of the views of that document and a pointer to the document template that created the document.

2. A view keeps a pointer to its document and is a child of its parent frame window.


3. A document frame window keeps a pointer to its current active view.


4. A document template keeps a list of its open documents.


5. The application keeps a list of its document templates.



These relationships are established during document/view creation. The table "Gaining Windows OS keeps track of all open windows so it can send messages to them.
***Any object can obtain a pointer to the application object by calling the global function AfxGetApp.

Here are the ways to navigate and access the Document/View objects:

-From CDocument call GetFirstViewPosition and GetNextView to access the document's view list because a Document could have many views. Call GetDocTemplate to get the document template.

-From CView call GetDocument to get the document and call GetParentFrame to get the frame window of this view.

-From CFrameWnd call GetActiveView to get the current view and call GetActiveDocument to get the document attached to the current view.

-From CMDIFrameWnd frame window call MDIGetActive to get the currently active CMDIChildWnd.
Also there are Afx* global functions AfxGetApp(), AfxGetMainWnd() ...
It is understood that you derive your proper classes from each above classes:
CDocument, Cview, CFrameWnd, CMDIFrameWnd, CMDIChildWnd

CWinApp* pApp = ::AfxGetApp();
CMDIFrameWnd *pFrame =(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMainFrame : public CMDIFrameWnd
{
}
CMainFrame * pMainFrame = (CMainFrame*)AfxGetMainWnd();
-obislavu-
 
O I am stupid. To do what I wanted to do was really quite simple:

CMainFrame* pFrame;
pFrame = (CMainFrame*)AfxGetMainWnd();
m_reputation = pFrame->m_wndView.GetReputation();
m_reputation = m_reputation * 18;

For some reason it took until just now for me to realize that CMainFrame holds the active CChildView object, and that CMainFrame can traditionally be obtained by AfxGetMainWnd(). Well, what I did is the simplest way, and probably the least sloppy as long as it is only used every once in a while in remote classes far up my heirarchy. It's also good if your not making a program that has anything to do with the document/view architechture.

-Bones
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top