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

📄 dvp.cpp

📁 郎顿51开发板上位机代码 帮助你快速开发工控程序
💻 CPP
字号:
// dvp.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "dvp.h"


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

/////////////////////////////////////////////////////////////////////////////
// CDvpApp

BEGIN_MESSAGE_MAP(CDvpApp, CWinApp)
	//{{AFX_MSG_MAP(CDvpApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDvpApp construction

CDvpApp::CDvpApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
	m_Serial = new CSerial;
	OpenComPort(6);
}





/////////////////////////////////////////////////////////////////////////////
// The one and only CDvpApp object

CDvpApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CDvpApp initialization

BOOL CDvpApp::InitInstance()
{
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CDvpDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CDvpView));
	AddDocTemplate(pDocTemplate);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);
	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();
    m_pMainWnd->SetWindowText("朗顿科技-51Pro开发板上位机程序");
	return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
		// No message handlers
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CDvpApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CDvpApp message handlers



BOOL CDvpApp::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	return CWinApp::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

//事件过滤函数,这里只是针对按键事件过滤
BOOL CDvpApp::PreTranslateMessage(MSG* pMsg) 
{
	//如果主窗体存在,且为按键事件 
	if(this->GetMainWnd() && (pMsg->message == WM_CHAR )) 
	{
		//如果按键事件是发送给当前View的接收Edit则调用相应处理函数
		if(pMsg->hwnd == ((CMainFrame *)this->GetMainWnd())->GetActiveView()->GetDlgItem(IDC_DATA_RX)->m_hWnd)
		((CDvpView *)((CMainFrame *)this->GetMainWnd())->GetActiveView())->DealRxKeyDown((unsigned char*)&pMsg->wParam);
		//如果按键事件是发送给当前View的发送Edit则调用相应处理函数
		if(pMsg->hwnd == ((CMainFrame *)this->GetMainWnd())->GetActiveView()->GetDlgItem(IDC_DATA_TX)->m_hWnd)
		((CDvpView *)((CMainFrame *)this->GetMainWnd())->GetActiveView())->DealTxKeyDown((unsigned char *)&pMsg->wParam);
	} 

	return CWinApp::PreTranslateMessage(pMsg);
}

BOOL CDvpApp::ProcessMessageFilter(int code, LPMSG lpMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CWinApp::ProcessMessageFilter(code, lpMsg);
}
bool CDvpApp::OpenComPort(int nPort, int nBaud,CString nExt)
{
	return (bool)m_Serial->Open(nPort,nBaud,nExt);
}
bool CDvpApp::CloseComPort()
{
	return (bool)m_Serial->Close();
}

bool CDvpApp::IsComOpened()
{
	return (bool)m_Serial->IsOpened();
}

int CDvpApp::ReadData( void * data, int count)
{
	return m_Serial->ReadData(data , count);
}

int CDvpApp::SendData( const unsigned char * data , int count)
{
	return m_Serial->SendData(data , count);
}

⌨️ 快捷键说明

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