📄 keyboarddlg.cpp
字号:
// keyboardDlg.cpp : implementation file
//
#include "stdafx.h"
#include "keyboard.h"
#include "keyboardDlg.h"
#include "pytable.h"
#include "mmsystem.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define KB_KEYDELAY 2
#define KB_OK 0
#define KB_ERROR 1
#define INPUT_NUMBER 0
#define INPUT_LETTER 1
#define INPUT_CAPLETTER 2
#define INPUT_CHINESE 3
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKeyboardDlg dialog
CKeyboardDlg::CKeyboardDlg(CWnd* pParent /*=NULL*/)
: CDialog(CKeyboardDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CKeyboardDlg)
m_edit1 = _T("");
m_edit2 = _T("");
m_edit3 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CKeyboardDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKeyboardDlg)
DDX_Text(pDX, IDC_EDIT1, m_edit1);
DDX_Text(pDX, IDC_EDIT2, m_edit2);
DDX_Text(pDX, IDC_EDIT3, m_edit3);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CKeyboardDlg, CDialog)
//{{AFX_MSG_MAP(CKeyboardDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_KEY1, OnKey1)
ON_BN_CLICKED(IDC_KEY2, OnKey2)
ON_BN_CLICKED(IDC_KEY3, OnKey3)
ON_BN_CLICKED(IDC_KEY4, OnKey4)
ON_BN_CLICKED(IDC_KEY5, OnKey5)
ON_BN_CLICKED(IDC_KEY6, OnKey6)
ON_BN_CLICKED(IDC_KEY7, OnKey7)
ON_BN_CLICKED(IDC_KEY8, OnKey8)
ON_BN_CLICKED(IDC_KEY9, OnKey9)
ON_BN_CLICKED(IDC_KEY12, OnKey12)
ON_BN_CLICKED(IDC_KEY13, OnKey13)
ON_BN_CLICKED(IDC_KEY14, OnKey14)
ON_BN_CLICKED(IDC_KEY15, OnKey15)
ON_BN_CLICKED(IDC_KEY16, OnKey16)
ON_BN_CLICKED(IDC_KEY0, OnKey0)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKeyboardDlg message handlers
BOOL CKeyboardDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
kb_input_mode=0;
kb_selecting=0;
kb_select_roll=0;
kb_key_next=0;
kb_key_repeat=0;
kb_last_key=0;
kb_last_keytime=0;
kb_hz_inputed[0]='\0';
kb_key_input[0]='\0';
kb_hz_field=NULL;
init_pytable();
kb_font_English.CreateFont(
32, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"Times New Roman"); // lpszFacename
SetKeyBoard();
return TRUE; // return TRUE unless you set the focus to a control
}
void CKeyboardDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CKeyboardDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
WinRefresh(IDC_EDIT1,m_edit1);
WinRefresh(IDC_EDIT2,m_edit2);
WinRefresh(IDC_EDIT3,m_edit3);
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CKeyboardDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
CKeyboardDlg::~CKeyboardDlg()
{
if (kb_hz_field) free(kb_hz_field);
remv_pytable();
}
void CKeyboardDlg::OnKey0()
// "0" 键
{
if(kb_input_mode==INPUT_NUMBER){
NumberKey('0');
}else if(kb_input_mode==INPUT_LETTER||kb_input_mode==INPUT_CAPLETTER){
NumberKey(' ');
}else if(kb_input_mode==INPUT_CHINESE){
if (kb_selecting==1) SelectKey(0);
else{
kb_key_next=strlen(kb_key_input)+1;
kb_key_repeat=0;
}
}
}
void CKeyboardDlg::OnKey1()
// "1" "ABC"键
{
if(kb_input_mode==INPUT_NUMBER){
NumberKey('1');
}else if(kb_input_mode==INPUT_LETTER){
EnglishKey('a',3);
}else if(kb_input_mode==INPUT_CAPLETTER){
EnglishKey('A',3);
}else if(kb_input_mode==INPUT_CHINESE){
if (kb_selecting==1) SelectKey(1);
else LetterKey('a',3);
}
}
void CKeyboardDlg::OnKey2()
// "2" "DEF"键
{
if(kb_input_mode==INPUT_NUMBER){
NumberKey('2');
}else if(kb_input_mode==INPUT_LETTER){
EnglishKey('d',3);
}else if(kb_input_mode==INPUT_CAPLETTER){
EnglishKey('D',3);
}else if(kb_input_mode==INPUT_CHINESE){
if (kb_selecting==1) SelectKey(2);
else LetterKey('d',3);
}
}
void CKeyboardDlg::OnKey3()
// "3" "GHI"键
{
if(kb_input_mode==INPUT_NUMBER){
NumberKey('3');
}else if(kb_input_mode==INPUT_LETTER){
EnglishKey('g',3);
}else if(kb_input_mode==INPUT_CAPLETTER){
EnglishKey('G',3);
}else if(kb_input_mode==INPUT_CHINESE){
if (kb_selecting==1) SelectKey(3);
else LetterKey('g',3);
}
}
void CKeyboardDlg::OnKey4()
// "4" "JKL"键
{
if(kb_input_mode==INPUT_NUMBER){
NumberKey('4');
}else if(kb_input_mode==INPUT_LETTER){
EnglishKey('j',3);
}else if(kb_input_mode==INPUT_CAPLETTER){
EnglishKey('J',3);
}else if(kb_input_mode==INPUT_CHINESE){
if (kb_selecting==1) SelectKey(4);
else LetterKey('j',3);
}
}
void CKeyboardDlg::OnKey5()
// "5" "MN"键
{
if(kb_input_mode==INPUT_NUMBER){
NumberKey('5');
}else if(kb_input_mode==INPUT_LETTER){
EnglishKey('m',2);
}else if(kb_input_mode==INPUT_CAPLETTER){
EnglishKey('M',2);
}else if(kb_input_mode==INPUT_CHINESE){
if (kb_selecting==1) SelectKey(5);
else LetterKey('m',2);
}
}
void CKeyboardDlg::OnKey6()
// "6" "OPQ"键
{
if(kb_input_mode==INPUT_NUMBER){
NumberKey('6');
}else if(kb_input_mode==INPUT_LETTER){
EnglishKey('o',3);
}else if(kb_input_mode==INPUT_CAPLETTER){
EnglishKey('O',3);
}else if(kb_input_mode==INPUT_CHINESE){
if (kb_selecting==1) SelectKey(6);
else LetterKey('o',3);
}
}
void CKeyboardDlg::OnKey7()
// "7" "RST"键
{
if(kb_input_mode==INPUT_NUMBER){
NumberKey('7');
}else if(kb_input_mode==INPUT_LETTER){
EnglishKey('r',3);
}else if(kb_input_mode==INPUT_CAPLETTER){
EnglishKey('R',3);
}else if(kb_input_mode==INPUT_CHINESE){
if (kb_selecting==1) SelectKey(7);
else LetterKey('r',3);
}
}
void CKeyboardDlg::OnKey8()
// "8" "UVW"键
{
if(kb_input_mode==INPUT_NUMBER){
NumberKey('8');
}else if(kb_input_mode==INPUT_LETTER){
EnglishKey('u',3);
}else if(kb_input_mode==INPUT_CAPLETTER){
EnglishKey('U',3);
}else if(kb_input_mode==INPUT_CHINESE){
if (kb_selecting==1) SelectKey(8);
else LetterKey('u',3);
}
}
void CKeyboardDlg::OnKey9()
// "9" "XYZ"键
{
if(kb_input_mode==INPUT_NUMBER){
NumberKey('9');
}else if(kb_input_mode==INPUT_LETTER){
EnglishKey('x',3);
}else if(kb_input_mode==INPUT_CAPLETTER){
EnglishKey('X',3);
}else if(kb_input_mode==INPUT_CHINESE){
if (kb_selecting==1) SelectKey(9);
else LetterKey('x',3);
}
}
void CKeyboardDlg::OnKey12()
// "左移键"
{
int i,count=10;
char *temp2;
if(kb_input_mode==INPUT_NUMBER){
NumberKey('-');
}else if(kb_input_mode==INPUT_LETTER||kb_input_mode==INPUT_CAPLETTER){
NumberKey('.');
}else if(kb_input_mode==INPUT_CHINESE){
if (kb_selecting==1){
kb_select_roll=kb_select_roll-1;
if(kb_select_roll==0)
GetDlgItem(IDC_KEY12)->EnableWindow(false);
temp2=(char*)malloc(count*3+1);
for (i=0;i<count;i++){
temp2[3*i]='0'+i%10;
temp2[3*i+1]=kb_hz_field[2*(i+kb_select_roll*10)];
temp2[3*i+2]=kb_hz_field[2*(i+kb_select_roll*10)+1];
}
temp2[3*count]='\0';
m_edit2.Format("%s",temp2);
free(temp2);
GetDlgItem(IDC_KEY13)->EnableWindow(true);
WinRefresh(IDC_EDIT2,m_edit2);
}
}
}
void CKeyboardDlg::OnKey13()
// "右移"键
{
int i,count=10;
char *temp2;
if(kb_input_mode==INPUT_NUMBER){
NumberKey('+');
}else if(kb_input_mode==INPUT_LETTER||kb_input_mode==INPUT_CAPLETTER){
NumberKey('_');
}else if(kb_input_mode==INPUT_CHINESE){
if (kb_selecting==1){
kb_select_roll=kb_select_roll+1;
if(strlen(kb_hz_field)-kb_select_roll*20<=20){
count=(strlen(kb_hz_field)-kb_select_roll*20)/2;
GetDlgItem(IDC_KEY13)->EnableWindow(false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -