📄 svmainframe.cpp
字号:
//
//
// C++ Source Code File Name: SVMainFrame.cpp
// C++ Compiler Used: Microsoft eVC++ 3.0
// Produced By: SofTech Systems Inc, New Baden, Il 62265
// File Creation Date: 2 July 2003
// Date Last Modified: 2 July 2003
// Copyright (c) 2003 SofTech Systems Inc.
// ----------------------------------------------------------- //
// ------------- Program Description and Details ------------- //
// ----------------------------------------------------------- //
/*
This file is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
// ----------------------------------------------------------- //
#include "stdafx.h"
#include "resource.h"
#include "SVMainFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSVMainFrame
IMPLEMENT_DYNCREATE(CSVMainFrame, CFrameWnd)
CSVMainFrame::CSVMainFrame()
{
m_pos = NULL;
m_pObj = NULL;
m_iID = 1;
m_pRootWindow = NULL;
}
CSVMainFrame::~CSVMainFrame()
{
DestroyViewList();
}
BEGIN_MESSAGE_MAP(CSVMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CSVMainFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSVMainFrame message handlers
BOOL CSVMainFrame::PreTranslateMessage(MSG* pMsg)
{
switch(pMsg->message)
{
case WM_CLOSE:
if(pMsg->wParam == 0)
{
// This message probably from hitting the 'X' button
// Change it to act like the Cancel button.
pMsg->wParam = AIT_HIDE_WINDOW;
pMsg->message = AIT_CLOSE;
}
else
{
break;
}
// Fall through to the next case statement.
case AIT_CLOSE:
// Cancel button was pressed. So select the previous view already
// in memory.
if(m_Views.GetCount() > 0)
{
OnSelectPrevView(pMsg->wParam);
return FALSE;
}
// If the program gets to here, then there are no previous views so
// exit the program.
pMsg->message = WM_CLOSE;
break;
case MAINFRAME_CLOSE:
// Second half of window close (Cancel button). This message is sent
// after the CView has had a chance to save the data.
ShutdownWindow();
return TRUE;
case WM_QUIT:
// Don't know under what circumstances this message is received.
break;
case WM_HIBERNATE:
break;
default:
// Check to see if the root window is in our linked list.
// If not, then add it.
if(m_Views.GetCount() == 0)
{
CView* pView = GetActiveView();
// make sure the window has been created yet.
if(pView != NULL && pView->m_hWnd != NULL)
{
WINDOW_OBJECTS* pNewActiveObj = new WINDOW_OBJECTS;
pNewActiveObj->iMenuID = IDR_MAINFRAME;
pNewActiveObj->pView = (CFormView *)pView;
pNewActiveObj->IsModifiedFlag = pView->GetDocument()->IsModified();
pNewActiveObj->pClass = pView->GetRuntimeClass();
m_Views.AddHead(pNewActiveObj);
m_pRootWindow = pNewActiveObj->pClass;
}
}
break;
}
return CFrameWnd::PreTranslateMessage(pMsg);
}
void CSVMainFrame::ResetMenuBar(int iMenuID)
{
if(iMenuID > 0)
{
// Delete all existing menu's
m_wndCommandBar.ResetCommandBar();
// Add new menu to menu bar
m_wndCommandBar.InsertMenuBar(iMenuID);
// Replace the 'X' on the menu bar
m_wndCommandBar.AddAdornments();
}
}
void CSVMainFrame::OnSelectNextView(CRuntimeClass* pClass,int bHide, int iMenuID)
{
CView* pNewActiveView;
// This method is called from the application program to
// pop up another view on top of the current view. First
// we create the new view then hide the old view.
ASSERT(pClass);
CView* pOldActiveView = (CView *)GetActiveView();
ASSERT(pOldActiveView);
ASSERT(pOldActiveView->m_hWnd);
CDocument* pDoc;
WINDOW_OBJECTS *pOldActiveObj;
WINDOW_OBJECTS *pNewActiveObj;
pOldActiveObj = GetActiveWindow();
pNewActiveObj = FindWindow(pClass);
// Create the new view object. This only creates the object,
// not the CView view.
if(pNewActiveObj == NULL)
{
pNewActiveView = (CView *)pClass->CreateObject();
ASSERT(pNewActiveView);
CCreateContext context;
context.m_pCurrentDoc = pOldActiveView->GetDocument();
ASSERT(context.m_pCurrentDoc);
// Create the CView view.
pNewActiveView->Create(NULL,NULL,0L, CFrameWnd::rectDefault,
this, m_iID++, &context);
// Allow the new view to perform some initialization code
// before the window is displayed.
pNewActiveView->OnInitialUpdate();
pNewActiveObj = new WINDOW_OBJECTS;
pNewActiveObj->iMenuID = iMenuID;
pNewActiveObj->pView = (CFormView *)pNewActiveView;
pNewActiveObj->IsModifiedFlag = FALSE;
pNewActiveObj->pClass = pClass;
m_Views.AddHead(pNewActiveObj);
}
else
{
pNewActiveView = pNewActiveObj->pView;
}
// We need to hide the current view and put another one on top of it.
if(bHide == AIT_HIDE_WINDOW)
pOldActiveView->ShowWindow(SW_HIDE);
else
{
pOldActiveObj->pView->DestroyWindow();
RemoveWindow(pOldActiveObj);
delete pOldActiveObj;
}
pDoc = pNewActiveView->GetDocument();
pNewActiveView->ShowWindow(SW_SHOW); // Show the new view
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
SetActiveView(pNewActiveView); // Activate the new view
RecalcLayout();
if(iMenuID >= 0)
ResetMenuBar(iMenuID);
}
void CSVMainFrame::ShutdownWindow()
{
CView* pView = (CView *)GetActiveWindow();
WINDOW_OBJECTS *pActiveObj = GetActiveWindow();
WINDOW_OBJECTS *pNewObj = GetNextWindow(pActiveObj);
// Delete the top-most window
pActiveObj->pView->DestroyWindow();
// Pop off all but the last view on the m_Views stack.
// The last view is the main window.
if( m_Views.GetCount() > 0)
{
RemoveWindow(pActiveObj);
delete pActiveObj;
m_pObj = NULL;
}
// If we have a valid window, then activate it. If not, we have
// probably just destroyed the last active window and any other
// windows are now unusable anyway.
if( pNewObj != NULL && m_Views.GetCount() > 0 && ::IsWindow(pNewObj->pView->m_hWnd))
{
// get the next view and re-show it
pNewObj->pView->ShowWindow(SW_SHOW);
pNewObj->pView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
CDocument* pDoc = pNewObj->pView->GetDocument();
pDoc->SetModifiedFlag(pNewObj->IsModifiedFlag);
SetActiveView(pNewObj->pView); // Activate the new view
RecalcLayout();
ResetMenuBar(pNewObj->iMenuID);
m_pos = NULL;
m_pObj = NULL;
}
}
void CSVMainFrame::RemoveWindow(WINDOW_OBJECTS* pObj)
{
POSITION pos = m_Views.GetHeadPosition();
while(pos)
{
POSITION oldPos = pos;
WINDOW_OBJECTS* p = (WINDOW_OBJECTS*)m_Views.GetNext(pos);
if(p->pView == pObj->pView)
{
m_Views.RemoveAt(oldPos);
return;
}
}
}
WINDOW_OBJECTS *CSVMainFrame::GetActiveWindow()
{
CView* pView = (CView *)GetActiveView();
m_pos = m_Views.GetHeadPosition();
m_pObj = NULL;
while(m_pos)
{
m_pObj = (WINDOW_OBJECTS *)m_Views.GetNext(m_pos);
if(m_pObj->pView->m_hWnd == pView->m_hWnd)
break;
}
if(m_pObj == NULL)
{
m_pObj = new WINDOW_OBJECTS;
m_pObj->pView = (CFormView *)pView;
CDocument* pDoc = pView->GetDocument();
m_pObj->IsModifiedFlag = pDoc->IsModified();
m_pObj->pClass = pView->GetRuntimeClass();
m_pRootWindow = m_pObj->pClass;
m_pObj->iMenuID = m_uiMenuID;
m_Views.AddHead(m_pObj);
}
return m_pObj;
}
WINDOW_OBJECTS * CSVMainFrame::FindWindow(CRuntimeClass* pClass)
{
m_pos = m_Views.GetHeadPosition();
m_pObj = NULL;
WINDOW_OBJECTS* pObj;
while(m_pos)
{
pObj = (WINDOW_OBJECTS *)m_Views.GetNext(m_pos);
if(pObj->pClass == pClass)
{
m_pObj = pObj;
break;
}
}
return m_pObj;
}
WINDOW_OBJECTS * CSVMainFrame::GetNextWindow(WINDOW_OBJECTS *pCurWindow)
{
m_pos = m_Views.GetHeadPosition();
m_pObj = NULL;
while(m_pos)
{
m_pObj = (WINDOW_OBJECTS *)m_Views.GetNext(m_pos);
ASSERT(m_pObj);
if(m_pObj == pCurWindow && m_pos != NULL)
{
m_pObj = (WINDOW_OBJECTS *)m_Views.GetNext(m_pos);
break;
}
}
return m_pObj;
}
void CSVMainFrame::DestroyViewList()
{
POSITION pos = m_Views.GetHeadPosition();
while(pos)
{
WINDOW_OBJECTS *pObj = (WINDOW_OBJECTS *)m_Views.GetNext(pos);
delete pObj;
}
m_Views.RemoveAll();
}
void CSVMainFrame::OnSelectPrevView(int nCmdShow)
{
// This function is only called by our OnTranslateMessage()
// method. It destroyes the top-most window and re-displays
// the next window.
CDocument* pDoc;
CView* pActiveView = (CView *)GetActiveView();
ASSERT(pActiveView);
// make sure there are more than one view in memory
if(m_Views.IsEmpty() == FALSE && m_Views.GetCount() > 0)
{
// pop the top-most view off the stack
m_pObj = GetActiveWindow();
pDoc = m_pObj->pView->GetDocument();
BOOL bModified = pDoc->IsModified();
if(bModified)
{
int iResponse = MessageBox(_T("Data has not been saved. Do you want to save it now?"),
_T("Warning"), MB_YESNOCANCEL | MB_ICONQUESTION);
if(iResponse == IDCANCEL)
return;
::PostMessage(pActiveView->m_hWnd,AIT_NOTIFY,iResponse,nCmdShow);
}
if(m_pRootWindow == NULL || m_pRootWindow == pActiveView->GetRuntimeClass())
{
DestroyViewList();
PostQuitMessage(0);
}
if(nCmdShow == AIT_HIDE_WINDOW)
{
m_pObj = GetActiveWindow();
m_pObj->IsModifiedFlag = pDoc->IsModified();
pActiveView->ShowWindow(SW_HIDE);
m_pObj = GetNextWindow(m_pObj);
if(m_pObj)
{
m_pObj->pView->ShowWindow(SW_SHOW);
pDoc = m_pObj->pView->GetDocument();
pDoc->SetModifiedFlag(m_pObj->IsModifiedFlag);
SetActiveView(m_pObj->pView); // Activate the new view
RecalcLayout();
ResetMenuBar(m_pObj->iMenuID);
m_pos = NULL;
m_pObj = NULL;
}
m_pos = NULL;
m_pObj = NULL;
}
else
{
// destroy the window
if(!bModified)
ShutdownWindow();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -