📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//////////////////////////////////////////////////////////////////////
// Copyright 2000. Moe Wheatley AE4JY <ae4jy@mindspring.com>
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or any later version.
//
//This program 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 General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "PathSim.h"
#include "PathSimDoc.h"
#include "PathSimView.h"
#include "time.h"
#include "setupDlg.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define ID_TIMER 5
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_CLOSE()
ON_COMMAND(ID_VIEW_STAYONTOP, OnViewStayontop)
ON_UPDATE_COMMAND_UI(ID_VIEW_STAYONTOP, OnUpdateViewStayontop)
ON_WM_TIMER()
ON_COMMAND(ID_INPUT_LEVEL_ADJ, OnInputLevelAdj)
ON_COMMAND(ID_OUTPUT_LEVEL_ADJ, OnOutputLevelAdj)
ON_COMMAND(ID_SETUP, OnSetup)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR,
IDS_STATUSBARX1,
IDS_STATUSBARX2,
ID_SEPARATOR,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
m_wp.length = 0;
m_StayOnTop = FALSE;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
m_wp.length = sizeof(WINDOWPLACEMENT);
// get screen size settings if they are saved in registry
if( !LoadWindowPlacement( &m_wp ) )
{
// set default sizes if none are loaded from the registry
m_wp.length = 0;
m_StayOnTop = FALSE;
}
LoadBarState("ControlBars\\State"); //restore status/toolbar states
m_TimerID = SetTimer( ID_TIMER, 1000, NULL); //start up status timer
if( m_TimerID == 0)
AfxMessageBox( "Can't Start Status Timer",MB_OK );
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
///////////////////////////////////////////////////////////////
// get registry screen size settings
///////////////////////////////////////////////////////////////
BOOL CMainFrame::LoadWindowPlacement(LPWINDOWPLACEMENT pwp)
{
CString strBuffer = AfxGetApp ()->GetProfileString ("WindowPos", "WindowPos");
if (strBuffer.IsEmpty ())
return FALSE;
int cRead = _stscanf (strBuffer, "%i:%i:%i:%i:%i:%i:%i:%i:%i:%i",
&pwp->flags, &pwp->showCmd,
&pwp->ptMinPosition.x, &pwp->ptMinPosition.y,
&pwp->ptMaxPosition.x, &pwp->ptMaxPosition.y,
&pwp->rcNormalPosition.left, &pwp->rcNormalPosition.top,
&pwp->rcNormalPosition.right, &pwp->rcNormalPosition.bottom);
if(pwp->flags & 0x8000)
m_StayOnTop = TRUE;
else
m_StayOnTop = FALSE;
pwp->flags &= ~0x8000;
if (cRead != 10)
return FALSE;
return TRUE;
}
///////////////////////////////////////////////////////////////
// save screen size settings to registry
///////////////////////////////////////////////////////////////
void CMainFrame::SaveWindowPlacement(LPWINDOWPLACEMENT pwp)
{
// SaveWindowPlacement
if(m_StayOnTop)
pwp->flags |= 0x8000;
else
pwp->flags &= ~0x8000;
CString strBuffer;
strBuffer.Format ("%i:%i:%i:%i:%i:%i:%i:%i:%i:%i",
pwp->flags, pwp->showCmd,
pwp->ptMinPosition.x, pwp->ptMinPosition.y,
pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
AfxGetApp()->WriteProfileString("WindowPos", "WindowPos", strBuffer);
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnClose()
{
WINDOWPLACEMENT wp;
wp.length = sizeof(WINDOWPLACEMENT);
if (GetWindowPlacement(&wp) )
{
if( IsZoomed() )
wp.flags |= WPF_RESTORETOMAXIMIZED;
SaveWindowPlacement( &wp );
}
SaveBarState("ControlBars\\State");
if( m_TimerID != 0 ) // stop timer if running
{
KillTimer( m_TimerID );
m_TimerID = 0;
}
CFrameWnd::OnClose();
}
void CMainFrame::ActivateFrame(int nCmdShow)
{
if( m_wp.length != 0) //if structure has been filled in
{
nCmdShow= m_wp.showCmd;
AfxGetApp ()->m_nCmdShow = nCmdShow;
SetWindowPlacement(&m_wp);
}
else
AfxGetApp ()->m_nCmdShow = nCmdShow;
CFrameWnd::ActivateFrame(nCmdShow);
}
void CMainFrame::OnViewStayontop()
{
if( m_StayOnTop )
m_StayOnTop = FALSE;
else
m_StayOnTop = TRUE;
StayOnTop();
}
void CMainFrame::OnUpdateViewStayontop(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_StayOnTop);
}
void CMainFrame::StayOnTop()
{
CWnd* pWnd = AfxGetMainWnd();
ASSERT_VALID(pWnd);
pWnd->SetWindowPos( (m_StayOnTop) ? &wndTopMost : &wndNoTopMost,
0,0,0,0, SWP_NOMOVE|SWP_NOSIZE);
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
if( nIDEvent == m_TimerID )
UpdateStatus();
CFrameWnd::OnTimer(nIDEvent);
}
///////////////////////////////////////////////////////////////////////
// Update the status bar info every timer period
///////////////////////////////////////////////////////////////////////
void CMainFrame::UpdateStatus()
{
CString sBuf;
UINT nID, nStyle;
INT nWidth, nIndex;
CSize szExtent;
CPathSimView* pView;
UINT percentdone = 0;
UINT OutLength;
CPathSimDoc* pDoc = (CPathSimDoc*)CMainFrame::GetActiveDocument();
ASSERT_VALID(pDoc);
CClientDC dc(&m_wndStatusBar);
CFont* pOldFont = dc.SelectObject(m_wndStatusBar.GetFont());
// Get current time and date
CTime time = CTime::GetCurrentTime();
sBuf = time.FormatGmt(_T(" %#d %b %Y %#H:%M:%S UTC "));
nIndex = m_wndStatusBar.CommandToIndex(IDS_STATUSBARX2);
szExtent = dc.GetTextExtent(sBuf, sBuf.GetLength() );
m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, nWidth);
m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, szExtent.cx);
m_wndStatusBar.SetPaneText(nIndex, sBuf);
// update the status pane
CTimeSpan elapsedTime;
struct tm* osTime; // A pointer to a structure containing time
// elements.
switch(pDoc->m_SimState)
{
case SIMSTATE_OFF:
sBuf = _T(" Stopped ");
break;
case SIMSTATE_ON:
if( pDoc->m_WaveToWave )
{
OutLength = pDoc->m_TimeLimit*8000;
percentdone = (100*pDoc->m_SamplesWritten)/OutLength;
sBuf.Format(_T("%d%% Complete"), percentdone);
}
else
{
elapsedTime = time - pDoc->m_StartTime;
sBuf = elapsedTime.Format(_T(" Elapsed Time = %H:%M:%S "));
if( elapsedTime.GetTotalSeconds() >= (INT)(pDoc->m_TimeLimit))
{
pView = (CPathSimView*)GetActiveView();
pView->OnExStop();
}
}
break;
case SIMSTATE_WAIT:
// if delayed start is active then check to see if ready to start
osTime = time.GetGmtTm( NULL );
if( (osTime->tm_hour == pDoc->m_DelayStartHour)
&& (osTime->tm_min == pDoc->m_DelayStartMin) )
{
pView = (CPathSimView*)GetActiveView();
pView->OnExStart();
}
sBuf = _T(" Waiting for Delayed Start ");
break;
}
szExtent = dc.GetTextExtent(sBuf, sBuf.GetLength() );
nIndex = m_wndStatusBar.CommandToIndex(IDS_STATUSBARX1);
m_wndStatusBar.GetPaneInfo(nIndex, nID, nStyle, nWidth);
m_wndStatusBar.SetPaneInfo(nIndex, nID, nStyle, szExtent.cx);
m_wndStatusBar.SetPaneText(nIndex, sBuf);
dc.SelectObject(pOldFont); //restore font
}
void CMainFrame::OnInputLevelAdj()
{
::WinExec(_T("SndVol32.exe /r"), SW_SHOW);
}
void CMainFrame::OnOutputLevelAdj()
{
::WinExec(_T("SndVol32.exe /p"), SW_SHOW);
}
void CMainFrame::OnSetup()
{
CPathSimDoc* pDoc = (CPathSimDoc*)CMainFrame::GetActiveDocument();
ASSERT_VALID(pDoc);
CSetupDlg dlg;
dlg.m_SaveInputs = pDoc->m_SaveInputs;
dlg.m_SaveOutputs = pDoc->m_SaveOutputs;
dlg.m_AppendTitle = pDoc->m_AppendTitle;
dlg.m_SaveRunTime = pDoc->m_SaveRunTime;
dlg.m_SaveAWGN = pDoc->m_SaveAWGN;
if (dlg.DoModal() == IDOK)
{
pDoc->m_SaveInputs = dlg.m_SaveInputs;
pDoc->m_SaveOutputs = dlg.m_SaveOutputs;
pDoc->m_AppendTitle = dlg.m_AppendTitle;
pDoc->m_SaveRunTime = dlg.m_SaveRunTime;
pDoc->m_SaveAWGN = dlg.m_SaveAWGN;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -