GIDForums

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Aug-2005, 16:58
pixienick pixienick is offline
New Member
 
Join Date: Aug 2005
Posts: 23
pixienick is on a distinguished road

Transferring Data between documents


Hi there
I have been working awhile with my mfc multiple document interface program, and have reached a point where i would like it to include a different type of document in the program and also to be able to transfer data from instances of the original document type to it. I have made a new document and view type and can open it, this was simple. But i've found it quite difficult to see where in the whole program one can access the different instances of the docs running within the program. Is this not a common task? Do you need to transfer data back to the main appplication object and then trasfer it out to other documents that way? Or will i be forced to just use a view with splitter windows and just go between them. It seems as if each view is like a completely separate program. Any rough pointers as to how i might go about this would be a great help.
Cheers
Nick
  #2  
Old 15-Aug-2005, 17:01
pixienick pixienick is offline
New Member
 
Join Date: Aug 2005
Posts: 23
pixienick is on a distinguished road

Forgot to mention!


I'm using mfc with Visual C++ 6.0 by the way!
  #3  
Old 16-Aug-2005, 12:53
aie0 aie0 is offline
Member
 
Join Date: Dec 2004
Posts: 246
aie0 is a jewel in the roughaie0 is a jewel in the rough
As I understood you have different kind of documents and you want to access form one doc to data of another. If that what it is then here is how you do it:

CPP / C++ / C Code:

// theApp - is a CWinApp instance

POSITION curTemplatePos = theApp.GetFirstDocTemplatePosition();

	while(curTemplatePos != NULL)
	{
		CDocTemplate* curTemplate =
			theApp.GetNextDocTemplate(curTemplatePos);
		CString str;
		curTemplate->GetDocString(str, CDocTemplate::docName);
// Here you determine which template you want to access ( kind of doc)
// "SomeName" is passed to program in CWinApp::InitInstance(..) when you 
// register doc templates by declaring CMultiDocTemplate classes

		if(str == _T("SomeName"))
		{
			
			POSITION pos = curTemplate->GetFirstDocPosition();
			while (pos != NULL)
			{
				CDocument* pDoc = curTemplate->GetNextDoc(pos);
// Do with pDoc what ever you wish
			}
			return;    
		}
	}
AfxMessageBox("Wrong template name");
  #4  
Old 16-Aug-2005, 16:23
pixienick pixienick is offline
New Member
 
Join Date: Aug 2005
Posts: 23
pixienick is on a distinguished road
Well that looks blooming marvelous thankyou so much, i couldn't find that info anywhere.
  #5  
Old 16-Aug-2005, 17:26
pixienick pixienick is offline
New Member
 
Join Date: Aug 2005
Posts: 23
pixienick is on a distinguished road
Yeah i got the info from one doc to another, that's great, but could you tell me where i specify the name ("SomeName"). In fact in my app the little box that comes up asking which document type you want to open has the same name twice in it, though they do create different documents. Obviously i have diffferent names for the Doc and View though this dosent show in the aforementioned box. Is it done somewhere with new CMultiDocTemplate()?
Any more help much appreciated!
Nick
  #6  
Old 17-Aug-2005, 13:20
aie0 aie0 is offline
Member
 
Join Date: Dec 2004
Posts: 246
aie0 is a jewel in the roughaie0 is a jewel in the rough
Quote:
// "SomeName" is passed to program in CWinApp::InitInstance(..) when you
// register doc templates by declaring CMultiDocTemplate classes


CPP / C++ / C Code:
BOOL CSomeProjectApp::InitInstance()
{
	// Register the application's document templates.  Document templates
	// serve as the connection between documents, frame windows and views.

	CMultiDocTemplate* pSomeNameTemplate;
	pSomeNameTemplate = new CMultiDocTemplate(
		IDR_SOMENAMETYPE,
		RUNTIME_CLASS(CSomeNameDoc),
		RUNTIME_CLASS(CSomeNameFrame), // custom MDI child frame
		RUNTIME_CLASS(CSomeNameView));
	AddDocTemplate(pSomeNameTemplate);

// Add AnotherName template to list

	CMultiDocTemplate* pAnotherNameTemplate;
	pAnotherNameTemplate = new CMultiDocTemplate(
		IDR_ANOTHERNAMETYPE,
		RUNTIME_CLASS(CAnotherNameDoc),
		RUNTIME_CLASS(CAnotherNameFrame), // custom MDI child frame
		RUNTIME_CLASS(CAnotherNameView));
	AddDocTemplate(pAnotherNameTemplate);

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;

	// The main window has been initialized, so show and update it.
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

	return TRUE;
}

IDR_ANOTHERNAMETYPE and IDR_SOMENAMETYPE are both strings and menus. Menu I suppose you know how to do, but string is a bit tricky.
Example for IDR_SOMENAMETYPE string and SomeName doc name:

\nSomeName\nSomeName\nSomeName Files (*.aaa)\n.aaa\nSomeProject.Document\SomeName Document

Look in CDocTemplate::GetDocString(..) explanation for more details.
  #7  
Old 18-Aug-2005, 05:34
pixienick pixienick is offline
New Member
 
Join Date: Aug 2005
Posts: 23
pixienick is on a distinguished road
Hmm, still having some trouble changing that string but i'll work something out.
Cheers again my friend, you've been a great help.
 

Recent GIDBlogMaster?s Degree by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
Mrs stacy12 C Programming Language 14 05-Feb-2005 18:02
Transferring data between arrays butters C Programming Language 3 07-Jul-2004 22:55
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 15:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:50.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.