📄 writeview.cpp
字号:
// WriteView.cpp : implementation of the CWriteView class
//
#include "stdafx.h"
#include "Write.h"
#include "WriteDoc.h"
#include "WriteView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define PIPE_CLOSED 232
/////////////////////////////////////////////////////////////////////////////
// CWriteView
extern HANDLE g_hPipe;
bool g_bConnected;
IMPLEMENT_DYNCREATE(CWriteView, CEditView)
BEGIN_MESSAGE_MAP(CWriteView, CEditView)
//{{AFX_MSG_MAP(CWriteView)
ON_WM_KEYDOWN()
ON_WM_KEYUP()
ON_WM_CHAR()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CWriteView construction/destruction
CWriteView::CWriteView()
{
g_bConnected = false;
AfxBeginThread (WaitForConnect, this);
}
CWriteView::~CWriteView()
{
}
BOOL CWriteView::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;
}
/////////////////////////////////////////////////////////////////////////////
// CWriteView drawing
void CWriteView::OnDraw(CDC* pDC)
{
CWriteDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CWriteView printing
BOOL CWriteView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default CEditView preparation
return CEditView::OnPreparePrinting(pInfo);
}
void CWriteView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CEditView begin printing.
CEditView::OnBeginPrinting(pDC, pInfo);
}
void CWriteView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CEditView end printing
CEditView::OnEndPrinting(pDC, pInfo);
}
/////////////////////////////////////////////////////////////////////////////
// CWriteView diagnostics
#ifdef _DEBUG
void CWriteView::AssertValid() const
{
CEditView::AssertValid();
}
void CWriteView::Dump(CDumpContext& dc) const
{
CEditView::Dump(dc);
}
CWriteDoc* CWriteView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWriteDoc)));
return (CWriteDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CWriteView message handlers
void CWriteView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
WriteToPipe (WM_KEYDOWN, nChar, nRepCnt, nFlags);
CEditView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CWriteView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
WriteToPipe (WM_KEYUP, nChar, nRepCnt, nFlags);
CEditView::OnKeyUp(nChar, nRepCnt, nFlags);
}
void CWriteView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
WriteToPipe (WM_CHAR, nChar, nRepCnt, nFlags);
CEditView::OnChar(nChar, nRepCnt, nFlags);
}
void CWriteView::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
WriteToPipe (WM_SYSKEYDOWN, nChar, nRepCnt, nFlags);
CEditView::OnSysKeyDown(nChar, nRepCnt, nFlags);
}
void CWriteView::OnSysKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
WriteToPipe (WM_SYSKEYUP, nChar, nRepCnt, nFlags);
CEditView::OnSysKeyUp(nChar, nRepCnt, nFlags);
}
void CWriteView::OnSysChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
WriteToPipe (WM_SYSCHAR, nChar, nRepCnt, nFlags);
CEditView::OnSysChar(nChar, nRepCnt, nFlags);
}
void CWriteView::WriteToPipe(UINT message, UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (!g_bConnected)
return;
DWORD dwWritten;
MSG msg;
msg.message = message;
msg.lParam = MAKELONG (nRepCnt, nFlags);
msg.wParam = nChar;
msg.time = time (0);
msg.hwnd = NULL;
if (!WriteFile (g_hPipe, (char *) &msg, sizeof (MSG), &dwWritten, NULL))
{
DWORD dwError = GetLastError ();
if (dwError == PIPE_CLOSED)
{
g_bConnected = false;
DisconnectNamedPipe (g_hPipe);
AfxBeginThread (WaitForConnect, this);
}
}
}
UINT CWriteView::WaitForConnect(void *lParam)
{
OVERLAPPED o;
memset (&o, '\0', sizeof (OVERLAPPED));
o.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
ConnectNamedPipe (g_hPipe, &o);
WaitForSingleObject (o.hEvent, INFINITE);
g_bConnected = true;
CloseHandle (o.hEvent);
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -