广州大学学生实验报告
开课学院及实验室:机械与电气工程学院、计机楼601B 年 月 日
学 院 实验课程名称 实验项目名称 机电学院 年级、专业、班 高级C语言及其应用 实验四:外设的应用 姓名 学号 成绩 指导教师 一、实验目的 1. 掌握键盘的基本编程方法 2. 掌握鼠标的基本编程方法 二、实验原理 三、实验设备 计算机、VC++6.0 四、实验内容与结果 1、接收键盘的按键值, 并打印出来; 若按下的是“Esc”键则退出。 #include
2、用鼠标画一条线。
// DrawView.cpp : implementation of the CDrawView class //
#include \#include \
#include \#include \
#ifdef _DEBUG
#define new DEBUG_NEW #undef THIS_FILE
static char THIS_FILE[] = __FILE__; #endif
///////////////////////////////////////////////////////////////////////////// // CDrawView
IMPLEMENT_DYNCREATE(CDrawView, CView)
BEGIN_MESSAGE_MAP(CDrawView, CView) //{{AFX_MSG_MAP(CDrawView) ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() ON_WM_MOUSEMOVE() //}}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()
///////////////////////////////////////////////////////////////////////////// // CDrawView construction/destruction
CDrawView::CDrawView() {
// TODO: add construction code here m_bDraw = FALSE; }
CDrawView::~CDrawView() { }
BOOL CDrawView::PreCreateWindow(CREATESTRUCT& cs) {
// TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs
return CView::PreCreateWindow(cs); }
///////////////////////////////////////////////////////////////////////////// // CDrawView drawing
void CDrawView::OnDraw(CDC* pDC) {
CDrawDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc);
// TODO: add draw code for native data here }
///////////////////////////////////////////////////////////////////////////// // CDrawView printing
BOOL CDrawView::OnPreparePrinting(CPrintInfo* pInfo) {
// default preparation
return DoPreparePrinting(pInfo); }
void CDrawView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) {
// TODO: add extra initialization before printing }
void CDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) {
// TODO: add cleanup after printing }
///////////////////////////////////////////////////////////////////////////// // CDrawView diagnostics
#ifdef _DEBUG
void CDrawView::AssertValid() const {
CView::AssertValid(); }
void CDrawView::Dump(CDumpContext& dc) const {
CView::Dump(dc); }
CDrawDoc* CDrawView::GetDocument() // non-debug version is inline {
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDrawDoc))); return (CDrawDoc*)m_pDocument; }
#endif //_DEBUG
///////////////////////////////////////////////////////////////////////////// // CDrawView message handlers
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point) {
// TODO: Add your message handler code here and/or call default m_ptOrigin = point; m_ptOld = point; m_bDraw = TRUE;
CView::OnLButtonDown(nFlags, point); }
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) {
/* // 首先获得窗口的设备描述表 HDC hdc;
hdc = ::GetDC(m_hWnd); //移动到线条的起点
MoveToEx(hdc, m_ptOrigin.x, m_ptOrigin.y, NULL); //画线
LineTo(hdc, point.x, point.y); //释放设备描述表
::ReleaseDC(m_hWnd,hdc); */
/* CDC* pDC = GetDC();
pDC->MoveTo(m_ptOrigin); pDC->LineTo(point); ReleaseDC(pDC);