Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to programatically close a current view in MFC at Start up?
Posted

Instead of closing it why not create it in the first place? If you really must have the whole document/view thing happening then defer the creation of the first document until the user choose File->New or File->Open from the menu. Without a document the view (and MDI child frame window) won't be created.

The article codeBegins should give you some clues as to where to start and, one of the few good thing about MFC, is that it comes with full source code so you can work out where program's initial empty document is created, override the function that does the creation and stop it happening.
 
Share this answer
 
Comments
nv3 1-Jun-12 11:07am    
Good point!
JackDingler 1-Jun-12 16:48pm    
In a complex application, it isn't uncommon to take some of the MFC modules and bring them up to the app level for customization.
Harmanjeet Singh 1-Jun-12 18:30pm    
First I tried what u said. I tried a lot, but couldn't do that. Even i left a post for it on codeproject. Anyways, how to skip the doc-view from creating first time, as what u said above..?
Try this..

AfxGetMainWnd()->SendMessage(WM_CLOSE);
or
AfxGetApp()->m_pMainWnd->SendMessage(WM_CLOSE);
or
PostMessage(hWnd, WM_CLOSE, NULL, NULL);
 
Share this answer
 
Comments
Aescleal 1-Jun-12 2:15am    
That won't close the view, that'll close the top level frame window and the entire application.
Harmanjeet Singh 1-Jun-12 2:23am    
yeah! i just want to close that view, not frame..
Before closing, set is as unactive:
::SetWindowLong(pviewclose->m_hWnd, GWL_ID, 0);
::SetWindowLong(pnewviewactive->m_hWnd, GWL_ID, AFX_IDW_PANE_FIRST);


If using new MFC, call a recalc (refresh) after done:
((CMDIFrameWndEx*)AfxGetMainWnd())->RecalcLayout();


If the view is doing things (executing a loop animation for example), end the loop before closing the view. Use a variable quit in the loop:
while (!quit)
{
     MyCustomDraw();
     CheckMessagesView();
}


void CMyView::CheckMessagesView()
{
	MSG dispatch;
	::PeekMessage( &dispatch, NULL, 0, 0, PM_NOREMOVE);
	if (dispatch.message == WM_QUIT || dispatch.message == WM_CLOSE)
		quit = TRUE;
	AfxGetThread()->PumpMessage();
}


If you want a splash, you should use a Dialog.

Hope it helps.
 
Share this answer
 
1) Get a pointer to the view (pView) e.g. call GetActiveView() or whatever is easiest;
2) (IMPORTANT) Set pDoc->m_bAutoDelete to FALSE or the document will be automatically destroyed when the view is destroyed;
3) Call pView->DestroyWindow();

You might want to create another view object as Doc/View model will not work too well without a view.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900