Hi I'm creating my own type of addressbook program using MFC and OBDC. In my program there are 2 view classes. PersonalView and Homeview. In my MainFrm.cpp file I have this function:
void CMainFrame::SelectView(UINT ViewID)
{
CView* pOldActiveView = GetActiveView;// Get current View
// Get pointer to new view if it exists
// if it doesn't the pointer will be null
CView* pNewActiveView = (CView*)GetDlgItem(ViewID);
// If this is 1st time around for the new view
// the new view won't exist, so it must be created
if (pNewActiveView == NULL)
{
switch(ViewID)
{
case HOME_VIEW: // Create a Home view
pNewActiveView = (CView*)new CHomeview;
break; // Ends case
default:
AfxMessageBox("Invalid View ID"
return; // Ends switch statement
};
// Switching the views
// Obtain the current view context to apply the new view
CCreateContext context;
context.m_pCurrentDoc = pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault,
this, ViewID, &context);
pNewActiveView->OnInitialUpdate();
}
SetActiveView(pNewActiveView); // Activate new view
pOldActiveView->ShowWindow(SW_HIDE); // Hide old view
pNewActiveView->ShowWindow(SW_SHOW); // Show new view
pOldActiveView->SetDlgCtrlID(m_CurrentviewID); // Set old view ID
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_CurrentviewID = ViewID; // Save the new view ID
RecalcLayout();
}
in that it gave me an error in case HOME_VIEW on this line:
pNewActiveView = (CView*)new CHomeview;
The error said:
syntax error : CHomeview : Identifier
After that I added the include file for CHomeview and it fixed that problem but gave me a new error:
c:\program files\microsoft visual studio\myprojects\addbookdb\homeview.cpp(17) : error C2370: 'THIS_FILE' : redefinition; different storage class
c:\program files\microsoft visual studio\myprojects\addbookdb\homeset.cpp(11) : see declaration of 'THIS_FILE'
This error I do not understand at all and was wondering what could be wrong with the program.
Please help if you know what is wrong.
Tim
Occupation: Currently Studying C++ in High School
void CMainFrame::SelectView(UINT ViewID)
{
CView* pOldActiveView = GetActiveView;// Get current View
// Get pointer to new view if it exists
// if it doesn't the pointer will be null
CView* pNewActiveView = (CView*)GetDlgItem(ViewID);
// If this is 1st time around for the new view
// the new view won't exist, so it must be created
if (pNewActiveView == NULL)
{
switch(ViewID)
{
case HOME_VIEW: // Create a Home view
pNewActiveView = (CView*)new CHomeview;
break; // Ends case
default:
AfxMessageBox("Invalid View ID"
return; // Ends switch statement
};
// Switching the views
// Obtain the current view context to apply the new view
CCreateContext context;
context.m_pCurrentDoc = pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault,
this, ViewID, &context);
pNewActiveView->OnInitialUpdate();
}
SetActiveView(pNewActiveView); // Activate new view
pOldActiveView->ShowWindow(SW_HIDE); // Hide old view
pNewActiveView->ShowWindow(SW_SHOW); // Show new view
pOldActiveView->SetDlgCtrlID(m_CurrentviewID); // Set old view ID
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_CurrentviewID = ViewID; // Save the new view ID
RecalcLayout();
}
in that it gave me an error in case HOME_VIEW on this line:
pNewActiveView = (CView*)new CHomeview;
The error said:
syntax error : CHomeview : Identifier
After that I added the include file for CHomeview and it fixed that problem but gave me a new error:
c:\program files\microsoft visual studio\myprojects\addbookdb\homeview.cpp(17) : error C2370: 'THIS_FILE' : redefinition; different storage class
c:\program files\microsoft visual studio\myprojects\addbookdb\homeset.cpp(11) : see declaration of 'THIS_FILE'
This error I do not understand at all and was wondering what could be wrong with the program.
Please help if you know what is wrong.
Tim
Occupation: Currently Studying C++ in High School