?? mainfrm.cpp
字號:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Receiver.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// 自定義消息
#define WM_MAP_OPEN WM_USER + 101
#define WM_DATA_READY WM_USER + 102
#define WM_MAP_CLOSE WM_USER + 103
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
// 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
ON_MESSAGE(WM_MAP_OPEN, OnMapOpen)
ON_MESSAGE(WM_MAP_CLOSE, OnMapClose)
ON_MESSAGE(WM_DATA_READY, OnDataReady)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.cx =300;
cs.cy =200;
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
void CMainFrame::OnMapOpen()
{
// 打開文件映射內核對象
m_hReceiveMap = OpenFileMapping(FILE_MAP_READ, FALSE, "DataMap");
if (m_hReceiveMap == NULL)
return;
// 映射到進程的地址空間
m_lpbReceiveBuf = (LPBYTE)MapViewOfFile(m_hReceiveMap, FILE_MAP_READ, 0, 0, 0);
if (m_lpbReceiveBuf == NULL)
return;
}
void CMainFrame::OnMapClose()
{
// 撤消映像
UnmapViewOfFile(m_lpbReceiveBuf);
m_lpbReceiveBuf = NULL;
// 關閉對象
CloseHandle(m_hReceiveMap);
m_hReceiveMap = NULL;
}
void CMainFrame::OnDataReady(WPARAM wParam, LPARAM lParam)
{
// 接受緩存
char RecvBuf[100];
// 共享內存中的數據長度
int length = (int)lParam;
// 將數據復制到內存
memcpy(RecvBuf, (char*)(m_lpbReceiveBuf), length);
RecvBuf[length] = '\0';
// 跟蹤輸出
AfxMessageBox((CString)RecvBuf);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -