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

📄 readview.cpp

📁 这些源代码
💻 CPP
字号:
// ReadView.cpp : implementation of the CReadView class
//

#include "stdafx.h"
#include "Read.h"

#include "ReadDoc.h"
#include "ReadView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CReadView

HANDLE g_hPipe;

#define		PIPE_CLOSED		232
#define		PIPE_ENDED		109

IMPLEMENT_DYNCREATE(CReadView, CEditView)

BEGIN_MESSAGE_MAP(CReadView, CEditView)
	//{{AFX_MSG_MAP(CReadView)
		// 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 printing commands
	ON_COMMAND(ID_FILE_PRINT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CReadView construction/destruction

CReadView::CReadView()
{
	g_hPipe = INVALID_HANDLE_VALUE;
	AfxBeginThread (ReadFromPipe, this);
}

CReadView::~CReadView()
{
}

BOOL CReadView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	BOOL bPreCreated = CEditView::PreCreateWindow(cs);
	cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL);	// Enable word-wrapping

	return bPreCreated;
}

/////////////////////////////////////////////////////////////////////////////
// CReadView drawing

void CReadView::OnDraw(CDC* pDC)
{
	CReadDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CReadView printing

BOOL CReadView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default CEditView preparation
	return CEditView::OnPreparePrinting(pInfo);
}

void CReadView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView begin printing.
	CEditView::OnBeginPrinting(pDC, pInfo);
}

void CReadView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView end printing
	CEditView::OnEndPrinting(pDC, pInfo);
}

/////////////////////////////////////////////////////////////////////////////
// CReadView diagnostics

#ifdef _DEBUG
void CReadView::AssertValid() const
{
	CEditView::AssertValid();
}

void CReadView::Dump(CDumpContext& dc) const
{
	CEditView::Dump(dc);
}

CReadDoc* CReadView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CReadDoc)));
	return (CReadDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CReadView message handlers


UINT CReadView::ReadFromPipe(void *lParam)
{
	CReadView *pThis = (CReadView *) lParam;
	while (1)
	{
		while (g_hPipe == INVALID_HANDLE_VALUE)
		{
			g_hPipe = CreateFile("\\\\.\\pipe\\pipename",
						GENERIC_READ | GENERIC_WRITE,
						FILE_SHARE_READ | FILE_SHARE_WRITE,
						NULL,
						OPEN_EXISTING,
						FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
						NULL);
			if (g_hPipe == INVALID_HANDLE_VALUE)
			{
				if (GetLastError () == 50)
				{
					AfxMessageBox ("The network does not support this operation");
					return (0);
				}
				Sleep (1000);
			}
		}
		while (1)
		{
			DWORD dwRead, dwAvailable, dwLeft;
			MSG msg;
			BOOL bResult;
			bResult = PeekNamedPipe (g_hPipe, &msg, sizeof (MSG), &dwRead, &dwAvailable, &dwLeft);
			if (!bResult)
			{
				DWORD dwError = GetLastError ();
				CloseHandle (g_hPipe);
				if (dwError == PIPE_ENDED)
				{
					AfxMessageBox ("The pipe has been closed");
					g_hPipe = INVALID_HANDLE_VALUE;
				}
				break;
			}
			bResult = ReadFile (g_hPipe, &msg, sizeof (MSG), &dwRead, NULL);
			if (dwRead < sizeof (MSG))
				continue;
			pThis->SendMessage (msg.message, msg.wParam, msg.lParam);
		}
		if (g_hPipe != INVALID_HANDLE_VALUE)
			break;
	}
	return (0);
}

⌨️ 快捷键说明

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