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 05-Jan-2009, 06:50
jothi1611 jothi1611 is offline
New Member
 
Join Date: Jan 2009
Posts: 2
jothi1611 is on a distinguished road
Lightbulb

Invoking a FormView through Button


Hi,

Im using Visual Studio 6.0. In MFC, On the click of the button, i need a formview to be in view.

so, i coded like,
CPP / C++ / C Code:
// On the click of the button, OnNewView will get invoked.
BOOL MyView::OnNewView()
{
    GetParentFrame()->SendMessage(WM_COMMAND, UM_CHANGENEWVIEW);
    return TRUE;
}

this will call,
CPP / C++ / C Code:
void RFSMDIChildWnd::SwitchToNewView()
{
	CRuntimeClass* pNewViewClass = RUNTIME_CLASS(CNewView);
	
	if(pNewViewClass)
		ReplaceView(pNewViewClass);
	else
		AfxMessageBox("Failed to Create New View");
}

In Replace View im calling the view and replacing it.
CPP / C++ / C Code:
ReplaceView(CRuntimeClass *pViewClass)
{
  CCreateContext context;
  CView * pCurrentView;    
  
   if ((pCurrentView= this->GetActiveView())==NULL)
     return FALSE;               
  
  if ((pCurrentView->IsKindOf(pViewClass))==TRUE)
     return TRUE;
           
   CDocument * pDoc= pCurrentView->GetDocument();
   
    BOOL bAutoDelete=pDoc->m_bAutoDelete;
  	pDoc->m_bAutoDelete=FALSE; 
	
    // Delete existing view 
    pCurrentView->DestroyWindow();

    // restore flag  
    pDoc->m_bAutoDelete=bAutoDelete;

    //Create a new View
	CView * pNewView = (CView *) pViewClass->CreateObject();

    // Redraw the new view
   
   context.m_pNewViewClass=pViewClass;
   context.m_pCurrentDoc=pDoc;
   context.m_pNewDocTemplate=NULL;
   context.m_pLastView=NULL;
   context.m_pCurrentFrame=this;
                             

   if (pNewView == NULL)
	{
    	TRACE1("Warning: Dynamic create of view type %Fs failed\n",
				pViewClass->m_lpszClassName);
		return FALSE;
	}
	
    if (!pNewView->Create(NULL, NULL, WS_CHILD,
		CRect(0,0,0,0), this, AFX_IDW_PANE_FIRST, &context))
		{
	    	TRACE0("Warning: couldn't create view for frame\n");
			return FALSE;  // programmer can assume FALSE return value 
			               // from this function means that there 
			               //isn't a view
		}                                      

	// Attach new view
    //pDoc->AddView(pNewView);

   // WM_INITIALUPDATE is define in AFXPRIV.H		
   pNewView->SendMessage(WM_INITIALUPDATE, 0, 0); 
   
   RecalcLayout();                
   
   pNewView->UpdateWindow();
   
   SetActiveView(pNewView);
   
   pNewView->PostMessage(RFSAppsView::UM_UPDATEVIEW, (WPARAM) 0, (LPARAM) 0);

   return TRUE;
}

Im getting error in 
if (!pNewView->Create(NULL, NULL, WS_CHILD,
		CRect(0,0,0,0), this, AFX_IDW_PANE_FIRST, &context))
		{
	    	TRACE0("Warning: couldn't create view for frame\n");
			return FALSE;  // programmer can assume FALSE return value 
			               // from this function means that there 
			               //isn't a view
		}

like debug assertion failed! File: ViewForm.cpp
Line 69.

I could understand that the template that im sending to CFormView is wrong. so i changed the Dialog Template settings to Style =Child and Border = None.

Could any one help me in this?
Is this is the rt way or is there any other simple way to invoke a new FormView through buttons?
Last edited by LuciWiz : 05-Jan-2009 at 07:28. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
 
 

Recent GIDBlogProgramming ebook direct download available 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
Change the caption on button when clicked drewdaman MS Visual C++ / MFC Forum 5 31-May-2009 21:56
to close Console using close button crash sankari27 MS Visual C++ / MFC Forum 0 22-Apr-2008 04:11
Button class Spidy08 FLTK Forum 8 25-Aug-2006 02:52
Server Button Control execute twice bluebeta .NET Forum 2 12-Jun-2006 10:25
Group Round buttons (radio buttons) toaster FLTK Forum 1 03-Jan-2006 07:57

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

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


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