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

📄 keyboardview.cpp

📁 一个EVC4.0下面的实现捕捉按键的程序
💻 CPP
字号:
// keyboardView.cpp : implementation of the CKeyboardView class
//

#include "stdafx.h"
#include "keyboard.h"
#include <windows.h>
#include "keyboardDoc.h"
#include "keyboardView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CKeyboardView

IMPLEMENT_DYNCREATE(CKeyboardView, CFormView)

BEGIN_MESSAGE_MAP(CKeyboardView, CFormView)
	//{{AFX_MSG_MAP(CKeyboardView)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKeyboardView construction/destruction

CKeyboardView::CKeyboardView()
	: CFormView(CKeyboardView::IDD)
{
	//{{AFX_DATA_INIT(CKeyboardView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here
}

CKeyboardView::~CKeyboardView()
{
}

void CKeyboardView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CKeyboardView)
	DDX_Control(pDX, IDC_EDIT2, m_edit2);
	DDX_Control(pDX, IDC_BUTTON3, m_button3);
	DDX_Control(pDX, IDC_BUTTON2, m_button2);
	DDX_Control(pDX, IDC_BUTTON1, m_button1);
	DDX_Control(pDX, IDC_EDIT1, m_edit1);
	//}}AFX_DATA_MAP
}

BOOL CKeyboardView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
  	return CFormView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CKeyboardView diagnostics

#ifdef _DEBUG
void CKeyboardView::AssertValid() const
{
	CFormView::AssertValid();
}

void CKeyboardView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CKeyboardView message handlers
 

void CKeyboardView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
		m_button1.SetFocus();
//BOOL CKeyboardView::PreTranslateMessage(MSG* pMsg) ;	
}

void CKeyboardView::OnButton1() 
{
	// TODO: Add your control notification handler code here

//LPVOID VirtualAlloc(  LPVOID lpAddress,   DWORD dwSize,   DWORD flAllocationType,   DWORD flProtect );
//BOOL VirtualCopy(   LPVOID lpvDest,   LPVOID lpvSrc,   DWORD cbSize,   DWORD fdwProtect );
BOOL CKeyboardView::PreTranslateMessage(MSG* pMsg) ;
}



BOOL CKeyboardView::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_KEYDOWN)   
{
	switch(pMsg->wParam)
	{
    	case VK_LEFT:
         AfxMessageBox(_T("按下了<-键"));
	     break;
		case VK_UP:
         AfxMessageBox(_T("按下了向上键"));
	     break;
		case 'A':
		AfxMessageBox(_T("按下了a键"));
	     break;
		default:  ;
	}
 
}

	return CFormView::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

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