CoderSource.net
Search
CSplitterWnd SwitchView Exception
Started by adnanshafique at 04-03-2006 3:12 PM. Topic has 0 replies.

Print Search « Previous Thread Next Thread »
   04-03-2006, 3:12 PM
adnanshafique is not online. Last active: 4/3/2006 7:46:34 PM adnanshafique

Top 75 Posts
Joined on 04-03-2006
Posts 1
CSplitterWnd SwitchView Exception

Hi,

 I need some help in MFC splitter windows. I create an user interface (GUI) which is look like new outloook application. I create a splitter window which have 3 panes, like the shape below.

        +-----+------------+
        |     |            |
        |     |            |
        |  1  |     2      |
        |     |            |
        +-----|            |
        |  3  |            |
        +-----+------------+


I place some buttons on pane 3 and when i click on button i switch views of pane 1 and pane 2 to some different views. Below is the code that i place in different modules of application:

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
 // SIZE OF CLIENT AREA
 CRect clientRect;
 GetClientRect(&clientRect); 
 int Col1Width = clientRect.Width()/4;
 int Col2Width = clientRect.Width() - Col1Width;
 /*==========================================================
 SPLIT CLIENT AREA INTO 2 SEPARATE COLUMNS
 ============================================================*/
 VERIFY (
  m_wndSpltForCols.CreateStatic (
   this,
   1,  // NUMBER OF ROWS
   2  // NUMBER OF COLUMNS
  )
 );
 /*=======================================
  VIEW FOR 2ND COLUMN
 ========================================*/
 VERIFY ( 
  m_wndSpltForCols.CreateView (0,  // ROW POSITION
  1,     // COLUMN POSITION   
  RUNTIME_CLASS(CSplitFrame),  // VIEW CLASS FOR PANE
  CSize(Col2Width, clientRect.Height()), // SIZE OF PANE
  pContext    //
  )
 );
 /*=======================================
 SPLITTING 1ST COLUMNS INTO 2 COLUMNS
 ========================================*/
 VERIFY (
  m_wndSpltForRows.CreateStatic (
   &m_wndSpltForCols,   // PARENT OBJECT
   2,     // NUMBER OF ROWS
   1,     // NUMBER OF COLUMNS
   WS_CHILD|WS_VISIBLE,   // STYLES
   m_wndSpltForCols.IdFromRowCol(0,0) // WHICH COLUMN IS TO BE SPLITTED
  )
 );
 /*=======================================
 VIEW FOR FIRST ROW - CONTAINS CTreeCtrl
 ========================================*/
 VERIFY  (
  m_wndSpltForRows.CreateView (
   0,
   0,    
   RUNTIME_CLASS(CNavOptionsView),
   CSize(10,10),
   pContext
  )
 );
 /*=============================================
 VIEW FOR SECOND ROW - MAIN NAVIGATION BUTTONS
 ===============================================*/
 VERIFY (
  m_wndSpltForRows.CreateView (
   1,
   0,    
   RUNTIME_CLASS(CNavigateView),
   CSize(10,10),
   pContext
  )
 );  
 m_wndSpltForCols.RecalcLayout();
 //SPLITTER WINDOW INITIALIZATION FLAG
 m_isWndSpltsInitialize = true;
 return true; 
}


The actual problem that i face in below function....By logic i think it fails but below function works 100% when i run application in Debug mode but when i run it in Release mode...application popups an Unhandle Exception.


bool CSagsDoc::SwitchToView(CView* pOldViewClass, CRuntimeClass* pNewViewClass)

 if (pOldViewClass->IsKindOf(pNewViewClass)) return TRUE;

 CFrameWnd* pMainWnd = (CFrameWnd*)AfxGetMainWnd(); 
 
 CEnhSplitterWnd* pSplitter = (CEnhSplitterWnd *)pOldViewClass->GetParent();

 int row = 0, col= 0;
 ASSERT(pSplitter->IsChildPane(pOldViewClass, &row, &col));
 
 CRect viewrect;
 pOldViewClass->GetWindowRect(&viewrect);

 // DELETEING PANE VIEW
 m_bAutoDelete = FALSE;    
 pOldViewClass->DestroyWindow();  
 m_bAutoDelete = TRUE;    

 
 CCreateContext context;
 context.m_pNewViewClass  = pNewViewClass;
 context.m_pCurrentDoc  = this;

 if (!pSplitter->CreateView(row, col, pNewViewClass, viewrect.Size(),&context))
  return false; 

 // Set active
 CView* pNewView = (CView *)pSplitter->GetPane(row, col);
 if (pNewView)
 {
  pNewView->GetParentFrame()->RecalcLayout();
 }
 
 // EXCEPTION In Release Version
 if (pSplitter)
 {
  pSplitter->GetParentFrame()->SetActiveView(pNewView); /** EXCEPTION OCCUR HERE **/  
  pSplitter->SetActivePane(row, col);
  pSplitter->RecalcLayout();  
  
 } 

 pNewView->OnInitialUpdate();
 pNewView->SendMessage(WM_PAINT);
 pNewView->SendMessage(WM_SIZE); 
 return true;
}


and last i am new in MFC world and feel lot of confusion and conflicts about MFC i spend more then 6 months in MFC but i still not satisfied with my MFC skills. if someone knows best MFC or any other related book please refer to me.


Regards,
Adnan


   Report 
Codersource.Net » Programming » MFC Programming » CSplitterWnd SwitchView Exception

MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Welcome to Codersource.Net Login | Register | Faq  

Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us