📄 unispen_demoview.cpp
字号:
// unispen_demoView.cpp : implementation of the CUnispen_demoView class
//
#include "stdafx.h"
#include "unispen_demo.h"
#include "unispen_demoDoc.h"
#include "unispen_demoView.h"
//for unispen use
#include "wintab.h"
#define PACKETDATA PK_X| PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE
#define PACKETMODE PK_X | PK_Y |PK_BUTTONS
#include "pktdef.h"
//end for unispen use
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CUnispen_demoView
IMPLEMENT_DYNCREATE(CUnispen_demoView, CView)
BEGIN_MESSAGE_MAP(CUnispen_demoView, CView)
ON_MESSAGE(WT_PACKET, OnWTPacket)
//{{AFX_MSG_MAP(CUnispen_demoView)
ON_WM_CREATE()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CUnispen_demoView construction/destruction
CUnispen_demoView::CUnispen_demoView()
{
// TODO: add construction code here
hCtx = 0;
}
CUnispen_demoView::~CUnispen_demoView()
{
if( hCtx )
WTClose( hCtx );
}
BOOL CUnispen_demoView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CUnispen_demoView drawing
void CUnispen_demoView::OnDraw(CDC* pDC)
{
CUnispen_demoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CUnispen_demoView printing
BOOL CUnispen_demoView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CUnispen_demoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CUnispen_demoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CUnispen_demoView diagnostics
#ifdef _DEBUG
void CUnispen_demoView::AssertValid() const
{
CView::AssertValid();
}
void CUnispen_demoView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CUnispen_demoDoc* CUnispen_demoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CUnispen_demoDoc)));
return (CUnispen_demoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CUnispen_demoView message handlers
int CUnispen_demoView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
WTInfo( WTI_DEFCONTEXT, 0, &lc );
// Open the context
lc.lcPktData = PACKETDATA;
lc.lcPktMode = PACKETMODE;
lc.lcOptions = CXO_SYSTEM;// | CXO_MESSAGES;
lc.lcSysMode = 1;
hCtx = WTOpen( m_hWnd, &lc, TRUE );
if (hCtx == NULL)
AfxMessageBox("Error Open wintab");
return 0;
}
//wintab message handler
LRESULT CUnispen_demoView::OnWTPacket(WPARAM wSerial, LPARAM hCtx)
{
// Read the packet
PACKET pkt;
// WTPacket( (HCTX)hCtx, wSerial, &pkt );
CDC *pDC = GetDC();
//display the pressure
CString str;
char buf[20];
wsprintf(buf, "%ld", pkt.pkNormalPressure);
pDC->TextOut(0,0, " ", 7);
str = buf;
pDC->TextOut(0,0, str);
ReleaseDC(pDC);
return 0;
}
CPoint ptOld;
void CUnispen_demoView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
PACKET pkt[5];
int i;
CDC *pDC = GetDC();
CPen newpen, *poldpen;
i = WTPacketsGet(hCtx, 5, pkt);
if ( i > 0)
{
CString str;
char buf[20];
int pressure = pkt[i-1].pkNormalPressure;
wsprintf(buf, "x:%03ld y:%03ld pressure:%03ld", point.x, point.y, pressure);
pDC->TextOut(0, 0, " ", 30);
str = buf;
pDC->TextOut(0, 0, str);
if (nFlags & MK_LBUTTON)
{
newpen.CreatePen(PS_SOLID, pressure /8 , 0x008040ff);
poldpen = pDC->SelectObject(&newpen);
pDC->MoveTo(ptOld);
pDC->LineTo(point);
pDC->SelectObject(poldpen);
newpen.DeleteObject();
}
ptOld = point;
}
ReleaseDC( pDC );
CView::OnMouseMove(nFlags, point);
}
void CUnispen_demoView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
ptOld = point;
CView::OnLButtonDown(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -