⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 PSK31方式通信C++编写的原代码,可以通过声音传递数据.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
//
#include "stdafx.h"
#include "WinPSK.h"
#include "WinPSKDoc.h"
#include "RcvView.h"
#include "XmitView.h"
#include "SetDlg.h"
#include "WaveDlg.h"
#include "WinPSKView.h"
#include "MainFrm.h"
#include "Htmlhelp.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


#define FILE_TEXT_LIMIT 10000

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	ON_WM_INITMENUPOPUP()
	ON_WM_MENUSELECT()
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_STATUS, OnUpdateStatus)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(IDM_RCVBACKCOLOR, OnRcvbackcolor)
	ON_COMMAND(IDM_XMITBACKCOLOR, OnXmitbackcolor)
	ON_COMMAND(IDM_RCVFONT, OnRcvfont)
	ON_COMMAND(IDM_XMITFONT, OnXmitfont)
	ON_COMMAND(IDM_XMITSENTFONT, OnXmitsentfont)
	ON_WM_CLOSE()
	ON_COMMAND(IDM_CLEARRCV, OnClearrcv)
	ON_COMMAND(IDM_CLEARXMIT, OnClearxmit)
	ON_COMMAND(ID_SETUP, OnSetup)
	ON_COMMAND(ID_RXLVLSETUP, OnRxlvlsetup)
	ON_COMMAND(ID_TXLVLSETUP, OnTxlvlsetup)
	ON_COMMAND(IDM_TXTUNE, OnTxtune)
	ON_COMMAND(IDM_SENDFILE, OnSendfile)
	ON_UPDATE_COMMAND_UI(ID_VIEW_STAYONTOP, OnUpdateViewStayontop)
	ON_COMMAND(ID_VIEW_STAYONTOP, OnViewStayontop)
	ON_COMMAND(IDM_SELWAVEFILES, OnSelwavefiles)
	//}}AFX_MSG_MAP
	// Global help commands
	ON_COMMAND(ID_HELP_FINDER, CFrameWnd::OnHelpFinder)
	ON_COMMAND(ID_HELP, CFrameWnd::OnHelp)
	ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp)
	ON_COMMAND(ID_DEFAULT_HELP, CFrameWnd::OnHelpFinder)
END_MESSAGE_MAP()

static UINT indicators[] =
{
	IDS_STATUSBAR1,
	IDS_STATUSBAR2,
	IDS_STATUSBAR3,
	ID_SEPARATOR,
	ID_INDICATOR_STATUS
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	m_wp.length = 0;
	m_StayOnTop = FALSE;
}

CMainFrame::~CMainFrame()
{
}

///////////////////////////////////////////////////////////////
// create splitter views
///////////////////////////////////////////////////////////////
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
	VERIFY(m_WndSplitter.CreateStatic( this,3,1));		//3 rows, 1 column
	VERIFY(m_WndSplitter.CreateView(0,0,
			RUNTIME_CLASS(CRcvView),CSize(0,0), pContext));
	
	VERIFY(m_WndSplitter.CreateView(1,0,
			RUNTIME_CLASS(CXmitView),CSize(0,0), pContext));
	
	VERIFY(m_WndSplitter.CreateView(2,0,
			RUNTIME_CLASS(CWinPSKView),CSize(0,0), pContext));
	return TRUE;
}

///////////////////////////////////////////////////////////////
// create the outer frame stuff
///////////////////////////////////////////////////////////////
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
//create status and toolbar	
	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
	}
	//  Delete these three lines if you don't want the toolbar to
	//  be dockable
//	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
//	EnableDocking(CBRS_ALIGN_ANY);
//	DockControlBar(&m_wndToolBar);

	CWinPSKView* pWnd = (CWinPSKView*)m_WndSplitter.GetPane(2,0);
	ASSERT_VALID( pWnd );
	CSize size = pWnd->GetTotalSize();	//get size of FormView window
	m_wp.length = sizeof(WINDOWPLACEMENT);
// get screen size settings if they are saved in registry
	CRect rc;
	GetClientRect( rc );
	LoadBarState("ControlBars\\State");	//restore status/toolbar states
	m_WndSplitter.SetColumnInfo(0,size.cx,10);
	if( LoadWindowPlacement(&m_wp, &m_Pane0Height, &m_Pane1Height, &m_Pane2Height))
	{
		m_WndSplitter.SetRowInfo(0,m_Pane0Height,0);
		m_WndSplitter.SetRowInfo(1,m_Pane1Height,0);
		m_WndSplitter.SetRowInfo(2,m_Pane2Height,0);
	}
	else
	{
		// set default splitter sizes if none are loaded from the registry
		m_WndSplitter.SetRowInfo(2,size.cy,10);
		m_WndSplitter.SetRowInfo(0,(rc.bottom-size.cy)/2,10);
		m_WndSplitter.SetRowInfo(1,(rc.bottom-size.cy)/3,10);
		m_wp.length = 0;
		m_StayOnTop = FALSE;
	}
	SetActiveView( pWnd, TRUE);
	return 0;
}

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);
}

///////////////////////////////////////////////////////////////
// get registry screen size settings
///////////////////////////////////////////////////////////////
BOOL CMainFrame::LoadWindowPlacement(LPWINDOWPLACEMENT pwp, INT* P0Height, INT* P1Height, INT* P2Height)
{
	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:%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,
			P0Height, P1Height, P2Height);

	if(pwp->flags & 0x8000)
		m_StayOnTop = TRUE;
	else
		m_StayOnTop = FALSE;
	pwp->flags &= ~0x8000;

	if (cRead != 13)
		return FALSE;
	return TRUE;
}

///////////////////////////////////////////////////////////////
// save screen size settings to registry
///////////////////////////////////////////////////////////////
void CMainFrame::SaveWindowPlacement(LPWINDOWPLACEMENT pwp, INT P0Height, INT P1Height, INT P2Height)
{
	// 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:%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,
		P0Height, P1Height, P2Height);

	AfxGetApp()->WriteProfileString("WindowPos", "WindowPos", strBuffer);
}

///////////////////////////////////////////////////////////////
// save stuff if closing program
///////////////////////////////////////////////////////////////
void CMainFrame::OnClose() 
{
INT x;
	CRect rc;
	m_wndStatusBar.GetItemRect( 1, rc);
	WINDOWPLACEMENT wp;
	wp.length = sizeof(WINDOWPLACEMENT);
	if (GetWindowPlacement(&wp) )
	{
		m_WndSplitter.GetRowInfo( 0, m_Pane0Height, x );
		m_WndSplitter.GetRowInfo( 1, m_Pane1Height, x );
		m_WndSplitter.GetRowInfo( 2, m_Pane2Height, x );
		if( IsZoomed() )
			wp.flags |= WPF_RESTORETOMAXIMIZED;
		SaveWindowPlacement( &wp, m_Pane0Height, m_Pane1Height, m_Pane2Height );
	}

	SaveBarState("ControlBars\\State");
	CFrameWnd::OnClose();
}

void CMainFrame::OnUpdateViewStayontop(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_StayOnTop);
}

void CMainFrame::OnViewStayontop() 
{
	if(	m_StayOnTop )
		m_StayOnTop = FALSE;
	else
		m_StayOnTop = TRUE;
	StayOnTop();
}

void CMainFrame::StayOnTop()
{
CWnd* pWnd = AfxGetMainWnd();
	ASSERT_VALID(pWnd);
	pWnd->SetWindowPos( (m_StayOnTop) ? &wndTopMost : &wndNoTopMost,
						0,0,0,0, SWP_NOMOVE|SWP_NOSIZE);
}

///////////////////////////////////////////////////////////////
// keep default title off the top system bar
///////////////////////////////////////////////////////////////
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	cs.style &= ~FWS_ADDTOTITLE;
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers for menu commands/actions

void CMainFrame::OnClearrcv() 
{
	CWinPSKDoc* pDoc = (CWinPSKDoc*)CMainFrame::GetActiveDocument();
	ASSERT_VALID(pDoc);
	pDoc->m_pRcvEdit->ClearAll();
}

///////////////////////////////////////////////////////////////
void CMainFrame::OnClearxmit() 
{
	CWinPSKDoc* pDoc = (CWinPSKDoc*)CMainFrame::GetActiveDocument();
	ASSERT_VALID(pDoc);
	fnAbortTX();
	pDoc->m_pXmitEdit->ClearAll();
}

///////////////////////////////////////////////////////////////
void CMainFrame::OnTxtune() 
{
CWinPSKView* pView = (CWinPSKView*)GetActiveView();
	ASSERT_VALID(pView);
	pView->OnTxtune();	
}
///////////////////////////////////////////////////////////////
void CMainFrame::OnRcvbackcolor() 
{
CWinPSKDoc* pDoc = (CWinPSKDoc*)CMainFrame::GetActiveDocument();
	ASSERT_VALID(pDoc);
	CColorDialog dlgColor(pDoc->m_pSettings->m_crRcvBackColor, CC_RGBINIT);
	if (dlgColor.DoModal() == IDOK)
	{
		pDoc->m_pSettings->m_crRcvBackColor = dlgColor.GetColor();
		pDoc->m_pRcvEdit->SetBackgroundColor( FALSE, pDoc->m_pSettings->m_crRcvBackColor );
	}
}
///////////////////////////////////////////////////////////////
void CMainFrame::OnRcvfont() 
{
CWinPSKDoc* pDoc = (CWinPSKDoc*)CMainFrame::GetActiveDocument();
	ASSERT_VALID(pDoc);
	CClientDC dc(NULL);
	LOGFONT lf = pDoc->m_pSettings->m_lfRcvFont;
	lf.lfHeight = -::MulDiv(-lf.lfHeight, dc.GetDeviceCaps(LOGPIXELSY), 72);
	CFontDialog dlg(&lf);
	dlg.m_cf.rgbColors = pDoc->m_pSettings->m_crRcvTextColor;
	if (dlg.DoModal() == IDOK)
	{
		pDoc->m_pSettings->m_crRcvTextColor = dlg.GetColor();
		lf.lfHeight = -::MulDiv(-lf.lfHeight, 72, dc.GetDeviceCaps(LOGPIXELSY));
		pDoc->m_pSettings->m_lfRcvFont = lf;
		pDoc->m_pRcvEdit->SetCharFormat(pDoc->m_pSettings->m_lfRcvFont,
			pDoc->m_pSettings->m_lfXmitFont,
			pDoc->m_pSettings->m_crRcvTextColor,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -