Sie sind auf Seite 1von 3

VC++ by BSS

KEYBOARD HANDLING

NEWSView.h : interface of the CNEWSView class


//

class CNEWSView : public CView


{
protected: // create from serialization only
CNEWSView();
DECLARE_DYNCREATE(CNEWSView)

// Attributes
public:
CNEWSDoc* GetDocument();

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CNEWSView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual void OnInitialUpdate();

/* OnInitialUpdate() Called by the framework after the view is first attached to the document, but
before the view is initially displayed. */

protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL

// Implementation
public:
CRect rect;
CPoint position;
virtual ~CNEWSView();

protected:

// Generated message map functions


protected:
//{{AFX_MSG(CNEWSView)
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

1
VC++ by BSS

NEWSView.cpp : implementation of the CNEWSView class

#include "stdafx.h"
#include "NEWS.h"

#include "NEWSDoc.h"
#include "NEWSView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CNEWSView

IMPLEMENT_DYNCREATE(CNEWSView, CView)

BEGIN_MESSAGE_MAP(CNEWSView, CView)
//{{AFX_MSG_MAP(CNEWSView)
ON_WM_CHAR()
//}}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()

///////////////////////////////////////CNEWSView drawing//////////////////////////////////////////////////////////

void CNEWSView::OnDraw(CDC* pDC)


{
CNEWSDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CClientDC dc(this);
dc.Rectangle(rect);
pDC->Ellipse(CRect(position.x-50,position.y-50,position.x+50,position.y+50));

///////////////////////////////CNEWSView message handlers////////////////////////////////////////////////////

void CNEWSView::OnInitialUpdate()
{
CView::OnInitialUpdate();

// TODO: Add your specialized code here and/or call the base class
GetClientRect(&rect);
position.x=(rect.right-rect.left)/2;
position.y=(rect.bottom-rect.top)/2;
}

2
VC++ by BSS

void CNEWSView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)


{
// TODO: Add your message handler code here and/or call default
switch(nChar)
{
case 'n':
case 'N':
position.y-=20;
break;
case 's':
case 'S':
position.y+=20;
break;
case 'W':
case 'w':
position.x-=20;
break;
case 'e':
case 'E':
position.x+=20;
break;
case 'q':
case 'Q':
PostQuitMessage(0);
break;
}
Invalidate();
if(position.x<rect.left)
position.x=rect.right;
else if(position.x>rect.right)
position.x=rect.left;
else if(position.y<rect.top)
position.y=rect.bottom;
else if(position.y>rect.bottom)
position.y=rect.top;
CView::OnChar(nChar, nRepCnt, nFlags);
}

Das könnte Ihnen auch gefallen