?? senderview.cpp
字號:
// SenderView.cpp : implementation of the CSenderView class
//
#include "stdafx.h"
#include "Sender.h"
#include "SenderDoc.h"
#include "SenderView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSenderView
IMPLEMENT_DYNCREATE(CSenderView, CFormView)
BEGIN_MESSAGE_MAP(CSenderView, CFormView)
//{{AFX_MSG_MAP(CSenderView)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_SEND, OnSend)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSenderView construction/destruction
CSenderView::CSenderView()
: CFormView(CSenderView::IDD)
{
//{{AFX_DATA_INIT(CSenderView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CSenderView::~CSenderView()
{
}
void CSenderView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSenderView)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BOOL CSenderView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CSenderView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
}
/////////////////////////////////////////////////////////////////////////////
// CSenderView diagnostics
#ifdef _DEBUG
void CSenderView::AssertValid() const
{
CFormView::AssertValid();
}
void CSenderView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CSenderDoc* CSenderView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSenderDoc)));
return (CSenderDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSenderView message handlers
void CSenderView::OnDestroy()
{
CFormView::OnDestroy();
}
void CSenderView::OnSend()
{
// 自定義消息
#define WM_MAP_OPEN WM_USER + 101
#define WM_DATA_READY WM_USER + 102
#define WM_MAP_CLOSE WM_USER + 103
// 在系統頁文件創建文件映射內核對象
HANDLE hRecvMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
PAGE_READWRITE | SEC_COMMIT,
0, 1000000, "DataMap");
if (hRecvMap == NULL)
return;
// 映射到進程的地址空間
LPBYTE lpData = (LPBYTE)MapViewOfFile(hRecvMap, FILE_MAP_WRITE, 0, 0, 0);
if (lpData == NULL)
return;
// 通知接收程序共享內存已建立
CWnd* pWnd = FindWindow(NULL, "接收程序");
if (pWnd != NULL)
pWnd->PostMessage(WM_MAP_OPEN, 0, 0);
// 要發送的數據
CString Message = "本數據從發送方發出!";
// 將數據寫入到共享內存
memcpy(lpData, Message, Message.GetLength());
// 通知接收方數據準備好
pWnd->PostMessage(WM_DATA_READY, (WPARAM)0, (LPARAM)Message.GetLength());
// 延遲1毫秒
Sleep(1);
// 通知接收方關閉共享內存
pWnd->PostMessage(WM_MAP_CLOSE, 0, 0);
// 撤消映像
UnmapViewOfFile(lpData);
// 關閉映像對象
CloseHandle(hRecvMap);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -