Switching views : season 2

Hi,

In my SDI application I have defined a CBaseFrame deriving from 
CFrameWnd and that allow me to switch between view dynamically 
created.Here is the code I suse


//CREATE_ONCE means view is create once and never deleted when switching
//CREATE_AND_DESTROY means views are deleted/recreated on switch
CBaseFrame::stViewInfo CBaseFrame::m_ViewInfo[] =
{
	{ IDD_MAIN_FORM,		CBaseFrame::CREATE_ONCE,		AFX_IDW_PANE_FIRST + 0,	NULL },
	{ IDD_WELCOME_DLG,		CBaseFrame::CREATE_AND_DESTROY, 
AFX_IDW_PANE_FIRST + 1,	NULL },
	{ IDD_WIZZARD_DLG,		CBaseFrame::CREATE_AND_DESTROY,	AFX_IDW_PANE_FIRST 
+ 2, NULL },
	{ IDD_OPTIONS_DLG,		CBaseFrame::CREATE_AND_DESTROY,	AFX_IDW_PANE_FIRST 
+ 3, NULL },
	{ IDD_CNX_DLG,			CBaseFrame::CREATE_AND_DESTROY,	AFX_IDW_PANE_FIRST + 
4, NULL },
	{ IDD_SCHEDULE_DLG,		CBaseFrame::CREATE_AND_DESTROY,	AFX_IDW_PANE_FIRST 
+ 5, NULL },
	{ IDD_HISTORY_DLG,		CBaseFrame::CREATE_AND_DESTROY,	AFX_IDW_PANE_FIRST 
+ 6, NULL },
	{ IDD_ABOUT_DLG,		CBaseFrame::CREATE_AND_DESTROY,	AFX_IDW_PANE_FIRST + 
7, NULL },
};

LRESULT CBaseFrame::OnSwitchView( WPARAM wParam, LPARAM lParam )
//CView* CBaseFrame::SwitchView( UINT a_ViewId )
{
	int		iCurViewIdx	= 0;
	int		iNewViewIdx	= 0;
	CView*	pCurView = NULL;
	CView*	pNewView	= NULL;
	BOOL	bDestroyOldView = FALSE;
	UINT	ViewId = (UINT) wParam;


	//Get current active view
	pCurView = m_pFrame->GetActiveView();
	TRACE( _T("CViewMgr::SwitchView : pCurView = 0x%x\r\n"), pCurView );
	if ( pCurView == NULL)
		return 0L;

	//Get Curview and NextView index
	iCurViewIdx = GetIndexFromView( pCurView );
	iNewViewIdx = GetIndexFromId( wParam );
	if ((iCurViewIdx == -1) || (iNewViewIdx == -1))
		return 0L;


	pNewView = m_ViewInfo[iNewViewIdx].pView;

	// View is already displayed
	if ( pNewView == pCurView ){
		return 0L/*pCurView*/;
	}

	// New view is NULL - we must create it
	if ( pNewView == NULL ){
		pNewView = CreateView( ViewId, iNewViewIdx);
		TRACE( _T("pNewView = 0x%x\r\n"), pNewView );
		if (pNewView != NULL){
			// Save new created view
			m_ViewInfo[iNewViewIdx].pView = pNewView;
		}
	}//pView == NULL
	
	//Make sure that the document won't be destroyed when the view is 
destroyed.
	//m_bAutoDelete is a public, but non-documented member of CDocument.
	CDocument* pCurrentDoc = m_pFrame->GetActiveDocument();
	pCurrentDoc->m_bAutoDelete = FALSE;

	// exchange view window ID's so RecalcLayout() works
	UINT temp = ::GetWindowLong(pCurView->m_hWnd, GWL_ID);
	::SetWindowLong(pCurView->m_hWnd, GWL_ID,
		::GetWindowLong(pNewView->m_hWnd, GWL_ID));
	::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);

	// Hide Old view
	pCurView->ShowWindow(SW_HIDE);

	//OnInitialUpdate() is not called as a result of calling CreateView() 
above.
	//It is not always called by the framework, so it is called here:
	pNewView->OnInitialUpdate();

	// Now show the new view
	pNewView->ShowWindow(SW_SHOW);
	m_pFrame->SetActiveView(pNewView);
	m_pFrame->RecalcLayout();
	pNewView->Invalidate();

	// try to destroy old view
	if ( m_ViewInfo[iCurViewIdx].eCreationMode == CREATE_AND_DESTROY){
		pCurView->DestroyWindow();
		m_ViewInfo[iCurViewIdx].pView = NULL;
	}

	return 0L/*pNewView*/;
}

The problem happens when I try to destroy the old view :

// try to destroy old view
	if ( m_ViewInfo[iCurViewIdx].eCreationMode == CREATE_AND_DESTROY){
		pCurView->DestroyWindow();
		m_ViewInfo[iCurViewIdx].pView = NULL;
	}

I have the following assert :


Assert wincore.cpp(windows CE) 442
LRESULT CALLBACK
AfxWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
	// special message which identifies the window as using AfxWndProc
	if (nMsg == WM_QUERYAFXWNDPROC)
		return 1;

	// all other messages route through message map
	CWnd* pWnd = CWnd::FromHandlePermanent(hWnd);
	ASSERT(pWnd != NULL && pWnd->m_hWnd == hWnd);

....
}











0
5/18/2007 2:14:53 PM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
934 Views

Similar Articles

[PageSpeed] 20

On May 18, 10:14 am, mosfet <john....@anonymous.org> wrote:
> Hi,
>
> In my SDI application I have defined a CBaseFrame deriving from
> CFrameWnd and that allow me to switch between view dynamically
> created.Here is the code I suse
>
> //CREATE_ONCE means view is create once and never deleted when switching
> //CREATE_AND_DESTROY means views are deleted/recreated on switch
> CBaseFrame::stViewInfo CBaseFrame::m_ViewInfo[] =
> {
>         { IDD_MAIN_FORM,                CBaseFrame::CREATE_ONCE,                AFX_IDW_PANE_FIRST + 0, NULL },
>         { IDD_WELCOME_DLG,              CBaseFrame::CREATE_AND_DESTROY,
> AFX_IDW_PANE_FIRST + 1, NULL },
>         { IDD_WIZZARD_DLG,              CBaseFrame::CREATE_AND_DESTROY, AFX_IDW_PANE_FIRST
> + 2, NULL },
>         { IDD_OPTIONS_DLG,              CBaseFrame::CREATE_AND_DESTROY, AFX_IDW_PANE_FIRST
> + 3, NULL },
>         { IDD_CNX_DLG,                  CBaseFrame::CREATE_AND_DESTROY, AFX_IDW_PANE_FIRST +
> 4, NULL },
>         { IDD_SCHEDULE_DLG,             CBaseFrame::CREATE_AND_DESTROY, AFX_IDW_PANE_FIRST
> + 5, NULL },
>         { IDD_HISTORY_DLG,              CBaseFrame::CREATE_AND_DESTROY, AFX_IDW_PANE_FIRST
> + 6, NULL },
>         { IDD_ABOUT_DLG,                CBaseFrame::CREATE_AND_DESTROY, AFX_IDW_PANE_FIRST +
> 7, NULL },
>
> };
>
> LRESULT CBaseFrame::OnSwitchView( WPARAM wParam, LPARAM lParam )
> //CView* CBaseFrame::SwitchView( UINT a_ViewId )
> {
>         int             iCurViewIdx     = 0;
>         int             iNewViewIdx     = 0;
>         CView*  pCurView = NULL;
>         CView*  pNewView        = NULL;
>         BOOL    bDestroyOldView = FALSE;
>         UINT    ViewId = (UINT) wParam;
>
>         //Get current active view
>         pCurView = m_pFrame->GetActiveView();
>         TRACE( _T("CViewMgr::SwitchView : pCurView = 0x%x\r\n"), pCurView );
>         if ( pCurView == NULL)
>                 return 0L;
>
>         //Get Curview and NextView index
>         iCurViewIdx = GetIndexFromView( pCurView );
>         iNewViewIdx = GetIndexFromId( wParam );
>         if ((iCurViewIdx == -1) || (iNewViewIdx == -1))
>                 return 0L;
>
>         pNewView = m_ViewInfo[iNewViewIdx].pView;
>
>         // View is already displayed
>         if ( pNewView == pCurView ){
>                 return 0L/*pCurView*/;
>         }
>
>         // New view is NULL - we must create it
>         if ( pNewView == NULL ){
>                 pNewView = CreateView( ViewId, iNewViewIdx);
>                 TRACE( _T("pNewView = 0x%x\r\n"), pNewView );
>                 if (pNewView != NULL){
>                         // Save new created view
>                         m_ViewInfo[iNewViewIdx].pView = pNewView;
>                 }
>         }//pView == NULL
>
>         //Make sure that the document won't be destroyed when the view is
> destroyed.
>         //m_bAutoDelete is a public, but non-documented member of CDocument.
>         CDocument* pCurrentDoc = m_pFrame->GetActiveDocument();
>         pCurrentDoc->m_bAutoDelete = FALSE;
>
>         // exchange view window ID's so RecalcLayout() works
>         UINT temp = ::GetWindowLong(pCurView->m_hWnd, GWL_ID);
>         ::SetWindowLong(pCurView->m_hWnd, GWL_ID,
>                 ::GetWindowLong(pNewView->m_hWnd, GWL_ID));
>         ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);
>
>         // Hide Old view
>         pCurView->ShowWindow(SW_HIDE);
>
>         //OnInitialUpdate() is not called as a result of calling CreateView()
> above.
>         //It is not always called by the framework, so it is called here:
>         pNewView->OnInitialUpdate();
>
>         // Now show the new view
>         pNewView->ShowWindow(SW_SHOW);
>         m_pFrame->SetActiveView(pNewView);
>         m_pFrame->RecalcLayout();
>         pNewView->Invalidate();
>
>         // try to destroy old view
>         if ( m_ViewInfo[iCurViewIdx].eCreationMode == CREATE_AND_DESTROY){
>                 pCurView->DestroyWindow();
>                 m_ViewInfo[iCurViewIdx].pView = NULL;
>         }
>
>         return 0L/*pNewView*/;
>
> }
>
> The problem happens when I try to destroy the old view :
>
> // try to destroy old view
>         if ( m_ViewInfo[iCurViewIdx].eCreationMode == CREATE_AND_DESTROY){
>                 pCurView->DestroyWindow();
>                 m_ViewInfo[iCurViewIdx].pView = NULL;
>         }
>
> I have the following assert :
>
> Assert wincore.cpp(windows CE) 442
> LRESULT CALLBACK
> AfxWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
> {
>         // special message which identifies the window as using AfxWndProc
>         if (nMsg == WM_QUERYAFXWNDPROC)
>                 return 1;
>
>         // all other messages route through message map
>         CWnd* pWnd = CWnd::FromHandlePermanent(hWnd);
>         ASSERT(pWnd != NULL && pWnd->m_hWnd == hWnd);
>
> ...
>
> }

Too much code to comprehend whats going on. It would appear that your
view is not valid. How did you create the view? Also, dont call
DestroyWindow on the view. Use PostMessage(WM_CLOSE). Is it MDI or
SDI?

---
Ajay

0
ajaykalra (6842)
5/20/2007 2:26:20 PM
Reply:

Similar Artilces:

CRM 3.0/4.0: Views to show record that is created X Days Ago
I have a simple requirement to create a View with condition that the record is created x days ago, for example the record that is created 3 days ago. The only operator that is available for datetime (e.g. createdon) is only Last X Days, which if i show Last 3 Days, will show the records that were created today, yesterday, and 2 days ago. Is there any operator or any way to show the record that were created 3 days ago? I try to put condition "createdon Last 3 Days" and "NOT createdon Last 2 days", but there is no "NOT" operator in CRM. I try to insert new attribut...

"TOOLS" menu missing from menu bar #2
"TOOLS" menu is completely missing from the menu bar in Publisher 2003. How do I put it back? Might try a "detect and repair" Meanwhile, right-click a toolbar, click customize, scroll down to built-in menus, drag the tools menu to your toolbar. -- Mary Sauer MS MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Anil Gupta" <AnilGupta@discussions.microsoft.com> wrote in message news:5C7ADC1E-A6E9-4F01-8C06-01B92AC7B97B@microsoft.com... > "TOOLS" menu is completely missing from the menu bar in Publisher 20...

Creating a Combination Bar Chart with 2 Lines
I am trying to create a bar chart with 2 line series. The Y-axis for the vertical bars would be on the left and the Y-axis for the 2 line series would be on the right (3 series were defined). The horizontal axis for all series are calendar months (Jan, Feb, etc.) Every time I setup the chart my chart only displays a single line, ignoring the other line series. The vertical bars come out fine. Any thoughts on what I am doing wrong? Thanks Bill Falzone Don't use the built in types. Make the chart using all columns. Select a series that you want to change (click on it right in th...

Vista, MS Access 2003 and MS ADO Ext 6.0 vs 2.x
I am running into an issue with MS Access 2003 installed on Vista. Apparantly in the MS ADO Ext 6.0 version either (format, round, or sum) is not in that DLL. However, when I link to v2.8 of the DLL, I don't have an issue. I am getting the following error message when running my query. "Function is not available in expressions in query expressions." Does anyone have other workarounds? I am distributing this application in an MDE format, so I was wondering if the end users may experience issues, if I link to my version of msadox.dll instead of the installed version. I tried s...

Viewing Message logs?
I am interested in viewing the log for all incoming and outgoing messages in exchange. Previously we were using Sendmail and i could view the /var/log/messages file to see when messages were received and what it did with the message. However i have not been able to find anything like that with exchange. How can i view messages that are sent and received in real time? On Wed, 25 Oct 2006 13:45:05 -0400, "Jef A" <jef.aldrich@tatumllc.com> wrote: >I am interested in viewing the log for all incoming and outgoing messages in >exchange. Previously we were using Sendm...

URGENT!!! Problem with row data being truncated in a copy worksheet sub #2
Dave, Thanks for responding. I tried this but I could not get it t work in conjunction with the entire module. It dies right afte copying and PasteSpecial Values It does not kill the temp file or loa the newly created sheet into an e-mail. Any Ideas -- Doctor ----------------------------------------------------------------------- DoctorV's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=514 View this thread: http://www.excelforum.com/showthread.php?threadid=26863 You may want to post your current procedure. DoctorV wrote: > > Dave, Thanks for respon...

Cannot Start Outlook #2
I have just run the auomatic windows update on my local PC and now Outlook 2000 will not start. It just hangs at the splash screen. Outlook is configured to connect to Exchange. Other PCs on the same Lan which have not been updated can still connect. The updates installed were 824141, 823182, 826232, 825119, 828035, 828749. I have unistalled all of these updates and Outlook still will not start. Any ideas? Does it start if you run this command from the command line, go to Start > Run > type "outlook /safe" without the quotes but with the space before the Forward slash &...

2 Email domains w/2 Act. Dir. Domains - Same Forest
Hello, Scenario: We've had domain1.com (AD) setup and running in exchange 2003 for a year now w/mixed win2k and win2k3 servers - email domain name is the same, domain1. OWA works great and haven't had any problems. Our company is branching out into a new business segment and I've created a new active dir. domain within the same forest, domain2.local. It is NOT a child domain, but does sit under the same forest. I need to configure my front end/back end exchange 2003 boxes to do the following: -receive email for both email domains (domain1.com and domain2.com) -let users...

Search Multiple Worksheets #2
Is there a way to search trough multiple worksheets for a specific value? Other posts have mentioned to use VBA, but I have never used that before. If anyone can give me some advice on using that or a type of formula to perform that can search multiple worksheets. Thank You There may be other ways but, while holding down the ctrl key select each of the worksheet tabs you want to search in then select Edit|Find from the menu. Type in the value you want and it will go to the first instance of that value. Now if you are wanting to preserve a specifice value for reference or ???, then...

Restricting number of viewings?
Without using macros, is there a way to allow someone to view an application only once or twice, after which point they could no longer view the spreadsheet (for example, if I want to send a worksheet sample that I don't want to be used permenantly). I don't think so, you can restrict access with macros but this can be overcome by opening the workbook with macros disabled. You can also write code to prevent a workbook being opened unless macros are enabled, but this is overcome quite easily by anyone with a little knowledge of Excel and VBA. In short, Excel is not designed for securit...

print area #2
i cannot clear print area. when i select the print area and 'file', 'print area',the options are not available. any suggestions? When you use this command, Excel creates a range "print_area". Try deleting that range. Stan Scott New York City "bronxxbabe" <anonymous@discussions.microsoft.com> wrote in message news:78dc01c476a2$31509280$a401280a@phx.gbl... > i cannot clear print area. when i select the print area > and 'file', 'print area',the options are not available. > any suggestions? Perhaps you have two or more ...

HTTP Error 401.2
Hi, I have installed MS CRM 1.2 on my Domain controller running windows 2003 standard server and email router on exchange 2003. My local ip subnet is 172.0.0.x With ms vpn connection, I can access to ms crm by using outlook 2003 or internet explorer by opening the default ms crm page remotely. However, if i connect to ms crm with different subnet 10.0.0.x, i cannot connect to ms crm. 10.0.0.x subnet is routed to 172.0.0.x, where my users normally login email from the exchange 2003. What puzzle me is why i can authenticate from exchange 2003 but not ms crm server on using the same...

backup same set of servers from 2 DPM 2007 servers
I am changing the DPM server 2007. However, I would like to take this opportunity to revise all protection groups so that I can restore bare-metal any server from a single lTO-4 tape if possible. During this "transitional period," I would like to leave the existing backup settings on the older DPM server to continue to run while adding jobs to the new DPM server. Looks like to me that I have to re-install the agent on all servers so that they can be recognized by the new DPM server. IS there a better way to do this if my plan is possible at all? Thanks Bill ...

moving publisher #2
I bought a computer with publisher bundled (no cd). Now I want to put it on my new laptop. How do I move it from the desktop computer to the laptop???? Cliff without the source CD...you don't. -- ~~~~~~~~~~~~~~~~~~ Rob Giordano Microsoft MVP Expression "Cliff" <Cliff@discussions.microsoft.com> wrote in message news:336C1CBE-2A51-4B62-B83D-46C35C557B74@microsoft.com... > I bought a computer with publisher bundled (no cd). Now I want to put it > on > my new laptop. How do I move it from the desktop computer to the > laptop???? > > Cliff I...

Average speed #2
Hi all Having trouble working out average speed. miles in a1 =14.3 time in B1 = 0:50:23 this cell has been formatted to HH:MM:SS The formula A1/B1 brings back the wrong answer if I alter to A1/(B1*24) still does not work correctly. Advise please. Thanks Jon "jon" <jon@nospam.com> schrieb im Newsbeitrag news:4659eb9a$1_1@glkas0286.greenlnk.net... > Hi all > Having trouble working out average speed. > > miles in a1 =14.3 > time in B1 = 0:50:23 this cell has been formatted to HH:MM:SS > > The formula A1/B1 brings back the wrong answer if I al...

Y Axis #2
I have two questions regarding the 'y' axis - in a normal line graph Firstly, how do i get the 'y' axis to appear in the middle of the graph IE to cross the 'x' axis at (0,0) instead of currently (in my graph) (-10,0) Secondly how do i plot the line "X =2" which should just be a vertical line on the graph? I'm using Microsoft Excel 2007 any help would be appreciated. Thanks Hi, Not able to test in xl2007 but from memory it should be the same as xl2003. For a line chart, select the x axis and open the format dialog. On the scale tab set Value (Y) axi...

Printing on 2 sides of a page?
How can I print a 2 page spreadsheet on the front and back of the same sheet of paper? Using Excel 2008. Thanks! It depends on whether your printer supports duplex printing. Check your printer's features to find out. If it does, the setting will be available in the Print dialog. You can also do a "manual duplex" job by printing page 1 (or 'Odd pages'), flipping the paper yourself, then print page 2 (or 'Even pages')... If it's only 2 pages that might be the simplest approach. -- HTH |:>) Bob Jones [MVP] Office:Mac "Rick"...

Keeps asking for password #2
I have followed all of the instructions given previously, I have deleted and recreated my e-mail account but Outlook 2002 (Windows XP) still keeps asking me for user ID and password every time it tries to send / recieve. The strange thing is that I have two accounts and this is only a problem with one of them. one of your accounts is set to ask formy outgoing server requires authentication, see under tools ...accounts... send...and then advanced email settings, or just double click on the email accunt , it wil give you the properties, take it from there it should be the settings should ...

Draft Folder problem #2
I'm running outlook 2000. My draft folder is called draft1. Can't seem to rename it! There isn't a folder named draft so what's happening? Isn't a big problem, but I should be able to solve it and I can't. Help. Thanks in advance Peter You could try to start Outlook from the run line with the /resetfoldernames switch. Start-->Run outlook.exe /resetfoldernames Reference: http://office.microsoft.com/en-gb/assistance/HP010031101033.aspx "Peter Brown" <peter.jennifer@gmail.com> wrote in message news:TErag.449$TF.2645@news-1.opaltelecom.net... &...

Inventory #2
How can I import an excel spreadsheet as inventory into Money...? -- Marie You're talking about the home inventory? It's not possible without using a macro (i.e., there's no import function). IMO, it's not desirable either, as the information is not easily usable in Money. I keep my home inventory in an asset account, which has the huge benefit of being a "normal" Money account. If you need to import the inventory, there are Excel to QIF converters available from third parties. I use the following: http://www.bigredconsulting.com/ -- "Marie" <...

how do i switch to a right to left worksheet
Do you mean this ? http://www.rondebruin.nl/sheetdirection.htm -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "li" <li@discussions.microsoft.com> wrote in message news:C02DC0F7-14E2-4424-8A62-8191E853C48B@microsoft.com... > under Excel Options -- Regards Dave Hawley www.ozgrid.com "li" <li@discussions.microsoft.com> wrote in message news:C02DC0F7-14E2-4424-8A62-8191E853C48B@microsoft.com... > ...

Saving data #2
Hi all, I need to save data (results) from a base spread sheet program that i use on a weekly basis. i am in the middle of building this program, and have just discovered macros, but this, along with links is about my current knowledge of excel how can i automate to accumulate data from the base spread sheet (program) when i clear all data from the program to produce fresh results the following week, and to keep past data up to date and available for further use. Any help would be appreciated. legepe With a combination of formulas and dynamic named ranges, it is possible to just add the ...

[ANN] Xinclude.NET 1.2 released
Hello! I'm glad to announce XInclude.NET 1.2 release. What is XInclude.NET ==================== XInclude.NET is free open-source implementation of XInclude 1.0 Working Draft of 10 November 2003 [1] and XPointer Framework Recommendation [2] written in C# for .NET platform. XInclude.NET supports XPointer element(), xmlns(), xpath1() and xpointer() (XPath subset only) schemes. XInclude.NET has been tested using The XInclude Test Suite under Microsoft .NET 1.0 and 1.1 on Windows 2000. Changes since 1.0 release: - Updated to new XInclude syntax and namespace according to new XInclude 1...

The connection was dropped by the remote host #2
All day I've been getting email stuck in the outbound queue with the below message recorded. Message delivery to the host '66.218.86.197' failed while delivering to the remote domain 'yahoo.com' for the following reason: The connection was dropped by the remote host. I've been able to send email to some domains but not all..... I've restarted the exchange 2003 server, flushed DNS Registered DNS Restarted DNS on DCs Reset our firewall... NSLOOKUP is good Pings by name resolve I can telnet to my mail server I can telnet to other mail servers. Can someo...

GP Upgrade #2
We just upgraded to GP 10.0. We want the salesmen to be able to enter their own orders, but we don't want them to be able to change the unit price or the extended price on the order. Is there a setting I can use for this? Thanks Angie I might be wrong but I think thats a security issue. -- Craig "Angie" wrote: > We just upgraded to GP 10.0. We want the salesmen to be able to enter their > own orders, but we don't want them to be able to change the unit price or > the extended price on the order. Is there a setting I can use for this? > > Than...