【VC开源代码栏目提醒】:以下是网学会员为您推荐的VC开源代码-CCLientView.cpp,希望本篇文章对您学习有所帮助。
// CCLientView.cpp : implementation of the CCCLientView class
//
#include "stdafx.h"
#include "CCLient.h"
#include "CCLientDoc.h"
#include "CCLientView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCCLientView
IMPLEMENT_DYNCREATE(CCCLientView, CView)
BEGIN_MESSAGE_MAP(CCCLientView, CView)
//{{AFX_MSG_MAP(CCCLientView)
ON_COMMAND(IDM_CONNECT, OnConnect)
ON_COMMAND(IDM_READ, OnRead)
ON_COMMAND(IDM_WRITE, OnWrite)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCCLientView construction/destruction
CCCLientView::CCCLientView()
{
// TODO: add construction code here
pipe=NULL;
}
CCCLientView::~CCCLientView()
{
if(pipe)
CloseHandle(pipe);
}
BOOL CCCLientView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCCLientView drawing
void CCCLientView::OnDraw(CDC* pDC)
{
CCCLientDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCCLientView printing
BOOL CCCLientView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCCLientView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCCLientView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCCLientView diagnostics
#ifdef _DEBUG
void CCCLientView::AssertValid() const
{
CView::AssertValid();
}
void CCCLientView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCCLientDoc* CCCLientView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCCLientDoc)));
return (CCCLientDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCCLientView message handlers
void CCCLientView::OnConnect() //客户端连接命名管道
{
// TODO: Add your command handler code here
WaitNamedPipe("\\\\.\\pipe\\mypipe",NMPWAIT_WAIT_FOREVER);
pipe=CreateFile("\\\\.\\pipe\\mypipe",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
}
void CCCLientView::OnRead() //客户端读程序
{
// TODO: Add your command handler code here
char readbuf[100];
DWORD dwread;
ReadFile(pipe,readbuf,100,&dwread,NULL);
MessageBox(readbuf);
}
void CCCLientView::OnWrite() //客户端写程序
{
// TODO: Add your command handler code here
char buf[]="Hello,MFC";
DWORD dwwrite;
WriteFile(pipe,buf,strlen(buf)+1,&dwwrite,NULL);
}
上一篇:
CCLientDoc.cpp
下一篇:
扛起年轻化大旗,哈弗F系玩转行业新风潮