myedit.cpp

来自「背单词程序」· C++ 代码 · 共 78 行

CPP
78
字号
// MyEdit.cpp : implementation file
//

#include "stdafx.h"
#include "EngRecite.h"
#include "MyEdit.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyEdit

CMyEdit::CMyEdit()
{
}

CMyEdit::~CMyEdit()
{
}


BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
	//{{AFX_MSG_MAP(CMyEdit)
	ON_WM_CHAR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyEdit message handlers

void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	CEdit::OnChar(nChar, nRepCnt, nFlags);
	
	static BOOL bRepType = FALSE;

	UINT nInsertChar = 0;
	switch(nChar)
	{
	case '[':
		nInsertChar = ']';
		break;
	case '{':
		nInsertChar = '}';
		break;
	case '(':
		nInsertChar = ')';
		break;
	case '<':
		nInsertChar = '>';
		break;
	case '"':
		bRepType = ~bRepType;
		nInsertChar = bRepType ? '"' : 0;
		break;
	case '\'':
		bRepType = ~bRepType;
		nInsertChar = bRepType ? '\'' : 0;
		break;
	default:
		break;
	}

	if (nInsertChar != 0)
	{
		SendMessage(WM_CHAR, (WPARAM)nInsertChar, (LPARAM)((nRepCnt & 0x00FF) | ((nFlags << 16) & 0xFF00)));
		
		SendMessage(WM_KEYDOWN, (WPARAM)37, (LPARAM)((1  & 0x00FF) | ((331 << 16)   & 0xFF00)));
		SendMessage(WM_KEYUP,   (WPARAM)37, (LPARAM)((1  & 0x00FF) | ((49483 << 16) & 0xFF00)));

		SetSel(-1, 0);
	}
}

⌨️ 快捷键说明

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