Click here to Skip to main content
15,925,868 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: SendMessage to Worker thread Pin
Stephen Hewitt9-May-07 19:34
Stephen Hewitt9-May-07 19:34 
AnswerRe: SendMessage to Worker thread Pin
SandipG 9-May-07 22:57
SandipG 9-May-07 22:57 
GeneralRe: SendMessage to Worker thread Pin
Ajay L D10-May-07 6:10
Ajay L D10-May-07 6:10 
AnswerRe: SendMessage to Worker thread Pin
ThatsAlok16-May-07 21:07
ThatsAlok16-May-07 21:07 
QuestionA DirectX Question Pin
Rom Manic9-May-07 18:01
Rom Manic9-May-07 18:01 
AnswerRe: A DirectX Question Pin
Hamid_RT9-May-07 19:26
Hamid_RT9-May-07 19:26 
QuestionMFC Document View - how to clone a View class Pin
Vaclav_9-May-07 16:27
Vaclav_9-May-07 16:27 
AnswerRe: MFC Document View - how to clone a View class Pin
Nelek9-May-07 23:10
protectorNelek9-May-07 23:10 
Hi,

I had more o less the same problem. I had my "MainView" (derived from CScrollView) to design the system and afterwards I wanted a new View for every kind of element. After many tests and time I was able to make it. I put some pieces of code here. This is made under VC++ 6

//The default View made by the assistant
pDocTemplate = new CMultiDocTemplate(
	IDR_FPSIITYPE,
	RUNTIME_CLASS(CFPSDoc),
	RUNTIME_CLASS(CChildFrame),
	RUNTIME_CLASS(CFPSView));
AddDocTemplate(pDocTemplate);

//One of the added views
pParamObj1Template = new CMultiDocTemplate(
	IDR_VIEWTYPE,			//Added Menu
	RUNTIME_CLASS(CFPSDoc),		//Same Doc
	RUNTIME_CLASS(CChildFrame),	//Same frame (but with differences in)
	RUNTIME_CLASS(CParamObj1View));	//New View from CFormView derived
AddDocTemplate(pParamObj1Template);

//Other 3 templates


Then I create the new View with this:
void CMainFrame::CreateOrActivateObject1Frame(CDocTemplate* pTemplate, const CString szName)
{	//Get necessary connections
	CMDIChildWnd* pMDIActive = MDIGetActive();
	CDocument* pDoc = pMDIActive->GetActiveDocument();
	CParamObj1View* pNewView;

	POSITION pos = pDoc->GetFirstViewPosition();
	while (pos)
	{	pNewView = (CParamObj1View*) pDoc->GetNextView(pos);
		if ((pNewView->IsKindOf(RUNTIME_CLASS(CParamObj1View))) && (pNewView->m_pObjParent->m_szName == szName))
		{	pNewView->GetParentFrame()->ActivateFrame();
			return;
		}
	}
	
	CChildFrame* pNewFrame = NULL;
	pNewFrame = (CChildFrame*)(pTemplate->CreateNewFrame(pDoc, pNewFrame));
	if (pNewFrame == NULL)
		return;

	pTemplate->InitialUpdateFrame(pNewFrame, pDoc);
	return;
}


Then I determine the parameters for the new View in:

BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{	if( !CMDIChildWnd::PreCreateWindow(cs) )
		return FALSE;

	CMDIChildWnd* pMDIActive = MDIGetActive();
	CDocument* pDoc = pMDIActive->GetActiveDocument();

	//Set the configuration for the ParamViews
	if ((pDoc) && (pDoc->m_szNewFrameName != ""))
	{	cs.style = WS_SYSMENU | WS_CAPTION | WS_OVERLAPPED;

		if (pDoc->m_pParent1 || pDoc->m_pObject2)
		{	cs.cx = 415;				cs.cy = 260;	}
		else if (pDoc->m_pObject3->m_nObj3Type == 0)
		{	cs.cx = 517;				cs.cy = 421;	}
		else if (pDoc->m_pObject3->m_nObj3Type == 2)
		{	cs.cx = 610;				cs.cy = 435;	}

		cs.lpszName = pDoc->m_szNewFrameName;
	}
	return TRUE;
}


And last I open them from the "MainView", if double-click on an element, this function is called

void CMainView::ManageNewView (const CString szParName)
{	CMyDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	extern CMyApp theApp;
	CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
	CString szRes = "";

	//To avoid interferences between elements...
	pDoc->m_pObject1 = NULL;		pDoc->m_pObject2 = NULL;		pDoc->m_pObject3 = NULL;

	//All elements’ names are unique, so it must be only one valid pointer
	pDoc->FindObj3Named (szParName);
	if (pDoc->m_pObject3)
		goto ManageObj3ViewLabel;

	pDoc->FindObj2Named (szParName);
	if (pDoc->m_pObject2)
		goto ManageOutViewLabel;

	pDoc->FindObj1Named (szParName);
	if (!pDoc->m_pObject1)
		return;

	pDoc->m_szNewFrameName = pDoc->m_pObject1->m_szName+" ("+pDoc->m_pObject1->m_szUnit+")";
	pFrame->CreateOrActivate Object1Frame (theApp.pParamObj1Template, pDoc->m_pObject1->m_szName);
	return;

ManageObj2ViewLabel:
//More or less the same (just some changes in pDoc->m_szNewFrameName

ManageRegViewLabel:
//More or less the same (just some changes in pDoc->m_szNewFrameName and
// checking something before creating the new view)

	return;
}


Afterwards you can made whatever you want in every view taking the datas you need from the document and working with them independantly of the view you are in that moment. The problems I had... I can't get the OnKeyDown in the new views, only in the main (I don't know if other messages can be affected). If you close the MainView you won't get the "Save changes?" MessageBox if any other view is opened and one or two things more (but are relative easy to fix)

Sorry for the extension, maybe there is a shorter or easier way to do the same. But it works.

--------
M.D.V.

If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

Questionwhich is better ? Pin
*Roxanna*9-May-07 16:22
*Roxanna*9-May-07 16:22 
AnswerRe: which is better ? Pin
Vaclav_9-May-07 17:09
Vaclav_9-May-07 17:09 
AnswerRe: which is better ? [modified] Pin
kakan9-May-07 19:56
professionalkakan9-May-07 19:56 
AnswerRe: which is better ? Pin
ThatsAlok16-May-07 21:03
ThatsAlok16-May-07 21:03 
Questionname of the table in database Pin
hero19959-May-07 14:17
hero19959-May-07 14:17 
AnswerRe: name of the table in database Pin
toxcct9-May-07 15:38
toxcct9-May-07 15:38 
GeneralRe: name of the table in database Pin
hero19959-May-07 16:27
hero19959-May-07 16:27 
QuestionRe: name of the table in database Pin
Hamid_RT9-May-07 19:37
Hamid_RT9-May-07 19:37 
AnswerRe: name of the table in database Pin
David Crow10-May-07 2:16
David Crow10-May-07 2:16 
QuestionQuestion about compression Pin
godspeed1239-May-07 12:22
godspeed1239-May-07 12:22 
AnswerRe: Question about compression Pin
Paresh Chitte9-May-07 18:15
Paresh Chitte9-May-07 18:15 
QuestionDLL's and external dependencies Pin
l_d9-May-07 10:17
l_d9-May-07 10:17 
AnswerRe: DLL's and external dependencies Pin
Hans Dietrich9-May-07 20:35
mentorHans Dietrich9-May-07 20:35 
AnswerRe: DLL's and external dependencies Pin
ThatsAlok16-May-07 21:00
ThatsAlok16-May-07 21:00 
QuestionStep through in VC++ Pin
Software_Specialist9-May-07 9:40
Software_Specialist9-May-07 9:40 
AnswerRe: Step through in VC++ Pin
Mark Salsbery9-May-07 10:08
Mark Salsbery9-May-07 10:08 
GeneralRe: Step through in VC++ Pin
Software_Specialist9-May-07 13:09
Software_Specialist9-May-07 13:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.