c++ MFC模拟笔记本键盘测试



// KeyBoardDlg.h : 头文件
//


#pragma once
#include "afxwin.h"
#include "MyButton.h"




// CKeyBoardDlg 对话框
class CKeyBoardDlg : public CDialogEx
{
// 构造
public:
CKeyBoardDlg(CWnd* pParent = NULL); // 标准构造函数


// 对话框数据
enum { IDD = IDD_KEYBOARD_DIALOG };


protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持




// 实现
protected:
HICON m_hIcon;

// 生成的消息映射函数
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg void SetFontColorBKcolor(CMyButton &str);
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void RunKeySet(CString str,BOOL &KeyIs);
afx_msg BOOL IsTrue();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
BOOL PreTranslateMessage(MSG* pMsg);
CMyButton m_A;
CMyButton m_Esc;
CMyButton m_F1;
CMyButton m_F2;
CMyButton m_F3;
CMyButton m_F4;
CMyButton m_F5;
CMyButton m_F6;
CMyButton m_F7;
CMyButton m_F8;
CMyButton m_F9;
CMyButton m_F10;
CMyButton m_F11;
CMyButton m_F12;
virtual void OnOK();
CMyButton m_Char;
CMyButton m_1;
CMyButton m_2;
CMyButton m_3;
CMyButton m_4;
CMyButton m_5;
CMyButton m_6;
CMyButton m_7;
CMyButton m_8;
CMyButton m_9;
CMyButton m_10;
CMyButton m_Add;
CMyButton m_plus;
CMyButton m_Back;
CMyButton m_Tab;
CMyButton m_Q;
CMyButton m_W;
CMyButton m_E;
CMyButton m_R;
CMyButton m_T;
CMyButton m_Y;
CMyButton m_U;
CMyButton m_I;
CMyButton m_O;
CMyButton m_p;
CMyButton m_bracketr;
CMyButton m_bracketl;
CMyButton m_char1;
CMyButton m_Caps;
CMyButton m_S;
CMyButton m_D;
CMyButton m_F;
CMyButton m_G;
CMyButton m_H;
CMyButton m_J;
CMyButton m_K;
CMyButton m_L;
CMyButton m_Char2;
CMyButton m_Char3;
CMyButton m_Shift_L;
CMyButton m_Z;
CMyButton m_X;
CMyButton m_C;
CMyButton m_V;
CMyButton m_B;
CMyButton m_N;
CMyButton m_M;
CMyButton m_char4;
CMyButton m_char5;
CMyButton m_char7;
CMyButton m_UP;
CMyButton m_Enter;
CMyButton m_Ctrl_L;
CMyButton m_Win;
CMyButton m_Alt_L;
CMyButton m_Space;
CMyButton m_Down;
CMyButton m_Right;
CMyButton m_Left;
BOOL Key1 = FALSE, Key2 = FALSE, Key3 = FALSE, Key4 = FALSE, Key5 = FALSE, Key6 = FALSE, Key7 = FALSE, Key8 = FALSE, Key9 = TRUE, Key10 = FALSE,
Key11 = TRUE, Key12 = FALSE, Key13 = FALSE, Key14 = FALSE, Key15 = FALSE, Key16 = FALSE, Key17 = FALSE, Key18 = FALSE, Key19 = FALSE,
Key20 = FALSE, Key21 = FALSE, Key22 = FALSE, Key23 = FALSE, Key24 = FALSE, Key25 = FALSE, Key26 = FALSE, Key27 = FALSE, Key28 = FALSE,
Key29 = FALSE, Key30 = FALSE, Key31 = FALSE, Key32 = FALSE, Key33 = FALSE, Key34 = FALSE, Key35 = FALSE, Key36 = FALSE,Key37 = FALSE, 
Key38 = FALSE, Key39 = FALSE, Key40 = FALSE, Key41 = FALSE, Key42 = FALSE, Key43 = FALSE, Key44 = FALSE, Key45 = FALSE,Key46 = FALSE, 
Key47 = FALSE, Key48 = FALSE, Key49 = FALSE, Key50 = FALSE, Key51 = FALSE, Key52 = FALSE, Key53 = FALSE, Key54 = FALSE,Key55 = FALSE, 
Key56 = TRUE, Key57 = FALSE, Key58 = FALSE, Key59 = FALSE, Key60 = FALSE, Key61 = FALSE, Key62 = FALSE, Key63 = FALSE,Key64 = FALSE, 
Key65 = FALSE, Key66 = FALSE, Key67 = FALSE, Key68 = FALSE, Key69 = FALSE, Key70 = FALSE, Key71 = FALSE, Key72 = FALSE,Key73 = FALSE;
CStringArray KeyNum;
};

// KeyBoardDlg.cpp : 实现文件
//


#include "stdafx.h"
#include "KeyBoard.h"
#include "KeyBoardDlg.h"
#include "afxdialogex.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif




// 用于应用程序“关于”菜单项的 CAboutDlg 对话框


class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();


// 对话框数据
enum { IDD = IDD_ABOUTBOX };


protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持


// 实现
protected:
DECLARE_MESSAGE_MAP()
};


CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}


void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()




// CKeyBoardDlg 对话框






CKeyBoardDlg::CKeyBoardDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CKeyBoardDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}


void CKeyBoardDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_BUTTON34, m_A);
DDX_Control(pDX, IDC_BUTTON1, m_Esc);
DDX_Control(pDX, IDC_BUTTON2, m_F1);
DDX_Control(pDX, IDC_BUTTON3, m_F2);
DDX_Control(pDX, IDC_BUTTON4, m_F3);
DDX_Control(pDX, IDC_BUTTON5, m_F4);
DDX_Control(pDX, IDC_BUTTON6, m_F5);
DDX_Control(pDX, IDC_BUTTON7, m_F6);
DDX_Control(pDX, IDC_BUTTON8, m_F7);
DDX_Control(pDX, IDC_BUTTON9, m_F8);
DDX_Control(pDX, IDC_BUTTON10, m_F9);
DDX_Control(pDX, IDC_BUTTON11, m_F10);
DDX_Control(pDX, IDC_BUTTON12, m_F11);
DDX_Control(pDX, IDC_BUTTON13, m_F12);
DDX_Control(pDX, IDC_BUTTON15, m_Char);
DDX_Control(pDX, IDC_BUTTON16, m_1);
DDX_Control(pDX, IDC_BUTTON17, m_2);
DDX_Control(pDX, IDC_BUTTON18, m_3);
DDX_Control(pDX, IDC_BUTTON19, m_4);
DDX_Control(pDX, IDC_BUTTON20, m_5);
DDX_Control(pDX, IDC_BUTTON21, m_6);
DDX_Control(pDX, IDC_BUTTON22, m_7);
DDX_Control(pDX, IDC_BUTTON23, m_8);
DDX_Control(pDX, IDC_BUTTON24, m_9);
DDX_Control(pDX, IDC_BUTTON25, m_10);
DDX_Control(pDX, IDC_BUTTON26, m_Add);
DDX_Control(pDX, IDC_BUTTON27, m_plus);
DDX_Control(pDX, IDC_BUTTON28, m_Back);
DDX_Control(pDX, IDC_BUTTON29, m_Tab);
DDX_Control(pDX, IDC_BUTTON33, m_Q);
DDX_Control(pDX, IDC_BUTTON37, m_W);
DDX_Control(pDX, IDC_BUTTON38, m_E);
DDX_Control(pDX, IDC_BUTTON39, m_R);
DDX_Control(pDX, IDC_BUTTON40, m_T);
DDX_Control(pDX, IDC_BUTTON41, m_Y);
DDX_Control(pDX, IDC_BUTTON42, m_U);
DDX_Control(pDX, IDC_BUTTON43, m_I);
DDX_Control(pDX, IDC_BUTTON44, m_O);
DDX_Control(pDX, IDC_BUTTON45, m_p);
DDX_Control(pDX, IDC_BUTTON46, m_bracketr);
DDX_Control(pDX, IDC_BUTTON47, m_bracketl);
DDX_Control(pDX, IDC_BUTTON48, m_char1);
DDX_Control(pDX, IDC_BUTTON30, m_Caps);
DDX_Control(pDX, IDC_BUTTON49, m_S);
DDX_Control(pDX, IDC_BUTTON50, m_D);
DDX_Control(pDX, IDC_BUTTON51, m_F);
DDX_Control(pDX, IDC_BUTTON52, m_G);
DDX_Control(pDX, IDC_BUTTON53, m_H);
DDX_Control(pDX, IDC_BUTTON54, m_J);
DDX_Control(pDX, IDC_BUTTON55, m_K);
DDX_Control(pDX, IDC_BUTTON56, m_L);
DDX_Control(pDX, IDC_BUTTON57, m_Char2);
DDX_Control(pDX, IDC_BUTTON58, m_Char3);
DDX_Control(pDX, IDC_BUTTON31, m_Shift_L);
DDX_Control(pDX, IDC_BUTTON35, m_Z);
DDX_Control(pDX, IDC_BUTTON61, m_X);
DDX_Control(pDX, IDC_BUTTON62, m_C);
DDX_Control(pDX, IDC_BUTTON63, m_V);
DDX_Control(pDX, IDC_BUTTON64, m_B);
DDX_Control(pDX, IDC_BUTTON65, m_N);
DDX_Control(pDX, IDC_BUTTON66, m_M);
DDX_Control(pDX, IDC_BUTTON67, m_char4);
DDX_Control(pDX, IDC_BUTTON68, m_char5);
DDX_Control(pDX, IDC_BUTTON69, m_char7);
DDX_Control(pDX, IDC_BUTTON70, m_UP);
DDX_Control(pDX, IDC_BUTTON60, m_Enter);
DDX_Control(pDX, IDC_BUTTON32, m_Ctrl_L);
DDX_Control(pDX, IDC_BUTTON36, m_Win);
DDX_Control(pDX, IDC_BUTTON73, m_Alt_L);
DDX_Control(pDX, IDC_BUTTON59, m_Space);
DDX_Control(pDX, IDC_BUTTON80, m_Down);
DDX_Control(pDX, IDC_BUTTON81, m_Right);
DDX_Control(pDX, IDC_BUTTON82, m_Left);
}


BEGIN_MESSAGE_MAP(CKeyBoardDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_KEYDOWN()
END_MESSAGE_MAP()




// CKeyBoardDlg 消息处理程序


BOOL CKeyBoardDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();


// 将“关于...”菜单项添加到系统菜单中。


// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);


CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetFontColorBKcolor(m_F8);
SetFontColorBKcolor(m_Alt_L);
SetFontColorBKcolor(m_F10);
// 设置此对话框的图标。  当应用程序主窗口不是对话框时,框架将自动
//  执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标


// TODO:  在此添加额外的初始化代码


return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}


void CKeyBoardDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}


// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。  对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。


void CKeyBoardDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文


SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);


// 使图标在工作区矩形中居中
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;


// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}


//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CKeyBoardDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}






void CKeyBoardDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO:  在此添加消息处理程序代码和/或调用默认值
CDialogEx::OnKeyDown(nChar, nRepCnt, nFlags);
}


void CKeyBoardDlg::SetFontColorBKcolor(CMyButton &str)
{
str.SetBKColor(120);
str.SetForeColor(234);
}


BOOL CKeyBoardDlg::IsTrue()
{
if (Key1 == TRUE&&Key2 == TRUE&& Key3 == TRUE&& Key4 == TRUE&& Key5 == TRUE&& Key6 == TRUE&& Key7 == TRUE&& Key8 == TRUE&& Key9 == TRUE&& Key10 == TRUE&&
Key11 == TRUE&& Key12 == TRUE&& Key13 == TRUE&& Key14 == TRUE&& Key15 == TRUE&& Key16 == TRUE&& Key17 == TRUE&& Key18 == TRUE&& Key19 == TRUE&&
Key20 == TRUE&& Key21 == TRUE&& Key22 == TRUE&& Key23 == TRUE&& Key24 == TRUE&& Key25 == TRUE&& Key26 == TRUE&& Key27 == TRUE&& Key28 == TRUE&&
Key29 == TRUE&& Key30 == TRUE&& Key31 == TRUE&& Key32 == TRUE&& Key33 == TRUE&& Key34 == TRUE&& Key35 == TRUE&& Key36 == TRUE&& Key37 == TRUE&&
Key38 == TRUE&& Key39 == TRUE&& Key40 == TRUE&& Key41 == TRUE&& Key42 == TRUE&& Key43 == TRUE&& Key44 == TRUE&& Key45 == TRUE&& Key46 == TRUE&&
Key47 == TRUE&& Key48 == TRUE&& Key49 == TRUE&& Key50 == TRUE&& Key51 == TRUE&& Key52 == TRUE&& Key53 == TRUE&& Key54 == TRUE&& Key55 == TRUE&&
Key56 == TRUE&& Key57 == TRUE&& Key58 == TRUE&& Key59 == TRUE&& Key60 == TRUE&& Key61 == TRUE&& Key62 == TRUE&& Key63 == TRUE&& Key64 == TRUE&&
Key65 == TRUE&& Key66 == TRUE&& Key67 == TRUE&& Key68 == TRUE&& Key69 == TRUE&& Key70 == TRUE&& Key71 == TRUE&& Key72 == TRUE&& Key73 == TRUE)
return TRUE;
return FALSE;
}


BOOL CKeyBoardDlg::PreTranslateMessage(MSG* pMsg)
{

if (pMsg->message == WM_KEYDOWN)
{
switch (pMsg->wParam)
{
case 0x1B:
{
SetFontColorBKcolor(m_Esc);
if (Key1 == FALSE)
RunKeySet("Key1",Key1);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 0x70:
{
SetFontColorBKcolor(m_F1);
if (Key2 == FALSE)
RunKeySet("Key2",Key2);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 0x71:
{
SetFontColorBKcolor(m_F2);
if (Key3==FALSE)
RunKeySet("Key3", Key3);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 0x72:
{
SetFontColorBKcolor(m_F3);
if (Key4 == FALSE)
RunKeySet("Key4", Key4);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 0x73:
{
SetFontColorBKcolor(m_F4);
if (Key5 == FALSE)
RunKeySet("Key5", Key5);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 0x74:
{
SetFontColorBKcolor(m_F5);
if (Key6 == FALSE)
RunKeySet("Key6", Key6);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 0x75:
{
SetFontColorBKcolor(m_F6);
if (Key7 == FALSE)
RunKeySet("Key7", Key7);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 0x76:
{
SetFontColorBKcolor(m_F7);
if (Key8 == FALSE)
RunKeySet("Key8", Key8);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 119:
{
SetFontColorBKcolor(m_F8);
if (Key9 == FALSE)
RunKeySet("Key9", Key9);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 0x78:
{
SetFontColorBKcolor(m_F9);
if (Key10 == FALSE)
RunKeySet("Key10", Key10);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case VK_F10:
{
SetFontColorBKcolor(m_F10);
if (Key11 == FALSE)
RunKeySet("Key11", Key11);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case VK_F11:
{
SetFontColorBKcolor(m_F11);
if (Key12 == FALSE)
RunKeySet("Key12", Key12);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case VK_F12:
{
SetFontColorBKcolor(m_F12);
if (Key13 == FALSE)
RunKeySet("Key13", Key13);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 49:
{
SetFontColorBKcolor(m_1);
if (Key14 == FALSE)
RunKeySet("Key14", Key14);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 50:
{
SetFontColorBKcolor(m_2);
if (Key15 == FALSE)
RunKeySet("Key15", Key15);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 51:
{
SetFontColorBKcolor(m_3);
if (Key16 == FALSE)
RunKeySet("Key16", Key16);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 52:
{
SetFontColorBKcolor(m_4);
if (Key17 == FALSE)
RunKeySet("Key17", Key17);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 53:
{
SetFontColorBKcolor(m_5);
if (Key18 == FALSE)
RunKeySet("Key18", Key18);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 54:
{
SetFontColorBKcolor(m_6);
if (Key19 == FALSE)
RunKeySet("Key19", Key19);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 55:
{
SetFontColorBKcolor(m_7);
if (Key20 == FALSE)
RunKeySet("Key20", Key20);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 56:
{
SetFontColorBKcolor(m_8);
if (Key21 == FALSE)
RunKeySet("Key21", Key21);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 57:
{
SetFontColorBKcolor(m_9);
if (Key22 == FALSE)
RunKeySet("Key22", Key22);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 48:
{
SetFontColorBKcolor(m_10);
if (Key23 == FALSE)
RunKeySet("Key23", Key23);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 65:
{
SetFontColorBKcolor(m_A);
if (Key24 == FALSE)
RunKeySet("Key24", Key24);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 66:
{
SetFontColorBKcolor(m_B);
if (Key25 == FALSE)
RunKeySet("Key25", Key25);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 67:
{
SetFontColorBKcolor(m_C);
if (Key26 == FALSE)
RunKeySet("Key26", Key26);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 68:
{
SetFontColorBKcolor(m_D);
if (Key27 == FALSE)
RunKeySet("Key27", Key27);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 69:
{
SetFontColorBKcolor(m_E);
if (Key28 == FALSE)
RunKeySet("Key28", Key28);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 70:
{
SetFontColorBKcolor(m_F);
if (Key29 == FALSE)
RunKeySet("Key29", Key29);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 71:
{
SetFontColorBKcolor(m_G);
if (Key30 == FALSE)
RunKeySet("Key30", Key30);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 72:
{
SetFontColorBKcolor(m_H);
if (Key31 == FALSE)
RunKeySet("Key31", Key31);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 73:
{
SetFontColorBKcolor(m_I);
if (Key32 == FALSE)
RunKeySet("Key32", Key32);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 74:
{
SetFontColorBKcolor(m_J);
if (Key33 == FALSE)
RunKeySet("Key33", Key33);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 75:
{
SetFontColorBKcolor(m_K);
if (Key34 == FALSE)
RunKeySet("Key34", Key34);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 76:
{
SetFontColorBKcolor(m_L);
if (Key35 == FALSE)
RunKeySet("Key35", Key35);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 77:
{
SetFontColorBKcolor(m_M);
if (Key36 == FALSE)
RunKeySet("Key36", Key36);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 78:
{
SetFontColorBKcolor(m_N);
if (Key37 == FALSE)
RunKeySet("Key37", Key37);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 79:
{
SetFontColorBKcolor(m_O);
if (Key38 == FALSE)
RunKeySet("Key38", Key38);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 80:
{
SetFontColorBKcolor(m_p);
if (Key39 == FALSE)
RunKeySet("Key39", Key39);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 81:
{
SetFontColorBKcolor(m_Q);
if (Key40 == FALSE)
RunKeySet("Key40", Key40);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 82:
{
SetFontColorBKcolor(m_R);
if (Key41 == FALSE)
RunKeySet("Key41", Key41);
if (KeyNum.GetSize ()== 73)
{
exit(0);
}
break;
}
case 83:
{
SetFontColorBKcolor(m_S);
if (Key42 == FALSE)
RunKeySet("Key42", Key42);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 84:
{
SetFontColorBKcolor(m_T);
if (Key43 == FALSE)
RunKeySet("Key43", Key43);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 85:
{
SetFontColorBKcolor(m_U);
if (Key44 == FALSE)
RunKeySet("Key44", Key44);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 86:
{
SetFontColorBKcolor(m_V);
if (Key45 == FALSE)
RunKeySet("Key45", Key45);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 87:
{
SetFontColorBKcolor(m_W);
if (Key46 == FALSE)
RunKeySet("Key46", Key46);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 88:
{
SetFontColorBKcolor(m_X);
if (Key47 == FALSE)
RunKeySet("Key47", Key47);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 89:
{
SetFontColorBKcolor(m_Y);
if (Key48 == FALSE)
RunKeySet("Key48", Key48);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 90:
{
SetFontColorBKcolor(m_Z);
if (Key49 == FALSE)
RunKeySet("Key49", Key49);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 192:
{
SetFontColorBKcolor(m_Char);
if (Key50 == FALSE)
RunKeySet("Key50", Key50);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 9:
{
SetFontColorBKcolor(m_Tab);
if (Key51 == FALSE)
RunKeySet("Key51", Key51);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 20:
{
SetFontColorBKcolor(m_Caps);
if (Key52 == FALSE)
RunKeySet("Key52", Key52);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 16:
{
SetFontColorBKcolor(m_Shift_L);
if (Key53 == FALSE)
RunKeySet("Key53", Key53);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 17:
{
SetFontColorBKcolor(m_Ctrl_L);
if (Key54 == FALSE)
RunKeySet("Key54", Key54);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 91:
{
SetFontColorBKcolor(m_Win);
if (Key55 == FALSE)
RunKeySet("Key55", Key55);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 18:
{
SetFontColorBKcolor(m_Alt_L);
if (Key56 == FALSE)
RunKeySet("Key56", Key56);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 32:
{
SetFontColorBKcolor(m_Space);
if (Key57 == FALSE)
RunKeySet("Key57", Key57);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 40:
{
SetFontColorBKcolor(m_Down);
if (Key58 == FALSE)
RunKeySet("Key58", Key58);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 39:
{
SetFontColorBKcolor(m_Right);
if (Key59 == FALSE)
RunKeySet("Key59", Key59);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 37:
{
SetFontColorBKcolor(m_Left);
if (Key60 == FALSE)
RunKeySet("Key60", Key60);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 38:
{
SetFontColorBKcolor(m_UP);
if (Key61 == FALSE)
RunKeySet("Key61", Key61);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 188:
{
SetFontColorBKcolor(m_char4);
if (Key62 == FALSE)
RunKeySet("Key62", Key62);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 190:
{
SetFontColorBKcolor(m_char5);
if (Key63 == FALSE)
RunKeySet("Key63", Key63);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 191:
{
SetFontColorBKcolor(m_char7);
if (Key64 == FALSE)
RunKeySet("Key64", Key64);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 186:
{
SetFontColorBKcolor(m_Char2);
if (Key65 == FALSE)
RunKeySet("Key65", Key65);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 222:
{
SetFontColorBKcolor(m_Char3);
if (Key66 == FALSE)
RunKeySet("Key66", Key66);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 13:
{
SetFontColorBKcolor(m_Enter);
if (Key67 == FALSE)
RunKeySet("Key67", Key67);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 219:
{
SetFontColorBKcolor(m_bracketr);
if (Key68 == FALSE)
RunKeySet("Key68", Key68);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 221:
{
SetFontColorBKcolor(m_bracketl);
if (Key69 == FALSE)
RunKeySet("Key69", Key69);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 220:
{
SetFontColorBKcolor(m_char1);
if (Key70 == FALSE)
RunKeySet("Key70", Key70);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 189:
{
SetFontColorBKcolor(m_Add);
if (Key71 == FALSE)
RunKeySet("Key71", Key71);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 187:
{
SetFontColorBKcolor(m_plus);
if (Key72 == FALSE)
RunKeySet("Key72", Key72);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}
case 8:
{
SetFontColorBKcolor(m_Back);
if (Key73 == FALSE)
RunKeySet("Key73", Key73);
if (IsTrue()==TRUE)
{
exit(0);
}
break;
}


default:
{
break;
}
}
}
if ((pMsg->message == WM_KEYDOWN&&
pMsg->wParam==VK_TAB&&
VK_F1 == pMsg->wParam) || (VK_RWIN == pMsg->wParam) || 
(VK_LWIN == pMsg->wParam) || (pMsg->message == 77) || 
(pMsg->wParam == VK_ESCAPE) || (VK_SPACE == pMsg->wParam)
||(pMsg->wParam == VK_MENU)) return TRUE;
//else if((VK_F1 == pMsg->wParam && WM_KEYDOWN == pMsg->message) || (pMsg->message == 77))
//return TRUE;
else
   return CDialog::PreTranslateMessage(pMsg);
}




void CKeyBoardDlg::OnOK()
{
// TODO:  在此添加专用代码和/或调用基类


//CDialogEx::OnOK();
}


void CKeyBoardDlg::RunKeySet(CString str, BOOL &KeyIs)
{
KeyNum.Add(str);
KeyIs = TRUE;

}




#pragma once
#include "afxwin.h"
class CMyButton :
public CButton
{
public:
CMyButton();
~CMyButton();


private:
int m_Style;              //鼠标进入标志
BOOL b_InRect;            //按钮文字
CString m_strText;        //文本颜色
COLORREF m_ForeColor;      //背景色
COLORREF m_BackColor;     //锁定按钮的文字颜色
COLORREF m_LockForColor;
CRect m_ButRect;          //按钮尺寸
CFont* p_Font;            //字体
void DrawButton(CDC *pDC);


public:
void SetText(CString str);
void SetForeColor(COLORREF color);
void SetBKColor(COLORREF color);
void SetTextFont(int FontHight,LPCTSTR FontName);
virtual void PreSubclassWindow();
virtual void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/);
DECLARE_MESSAGE_MAP()
afx_msg void OnMouseHover(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
};

#include "stdafx.h"
#include "MyButton.h"




CMyButton::CMyButton()
{
m_Style = 0;
b_InRect = false;
m_strText=_T("");
m_ForeColor = RGB(0,0,0);
m_BackColor = RGB(243,243,243);
m_LockForColor = GetSysColor(COLOR_GRAYTEXT);
p_Font = NULL;
}




CMyButton::~CMyButton()
{
if (p_Font) delete p_Font;
}




void CMyButton::PreSubclassWindow()
{
// TODO:  在此添加专用代码和/或调用基类
ModifyStyle(0,BS_OWNERDRAW);
CButton::PreSubclassWindow();
}




void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
m_ButRect = lpDrawItemStruct->rcItem;
if (m_strText.IsEmpty())
GetWindowText(m_strText);
int nSavedDC = pDC->SaveDC();
VERIFY(pDC);
DrawButton(pDC);
pDC->RestoreDC(nSavedDC);
// TODO:  添加您的代码以绘制指定项
}
BEGIN_MESSAGE_MAP(CMyButton, CButton)
ON_WM_MOUSEHOVER()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()


void CMyButton::DrawButton(CDC *pDC)
{
if (m_Style == 3)m_Style = 0;
if (GetStyle()&WS_DISABLED)
m_Style = 3;
COLORREF bColor, fColor;
switch (m_Style)
{
    case 0: bColor = RGB(192, 192, 192); fColor = m_ForeColor; break;   //正常按钮
    case 1: bColor = RGB(255, 255, 255); fColor = m_ForeColor; break;   //鼠标进入时按钮
    case 2: bColor = RGB(192, 192, 192); fColor = m_ForeColor; break;   //按下的按钮
case 3: bColor = m_BackColor; fColor = m_LockForColor; break;    //锁定的按钮
}


CBrush Brush;
Brush.CreateSolidBrush(m_BackColor);//背景刷
pDC->SelectObject(&Brush);
CPen Pen;
Pen.CreatePen(PS_SOLID,1,bColor);
pDC->SelectObject(&Pen);
pDC->RoundRect(&m_ButRect,CPoint(5,5));
if (m_Style != 2)
{
CRect Rect;
Rect.SetRect(m_ButRect.left + 2, m_ButRect.top + 1, m_ButRect.right, m_ButRect.bottom);
pDC->DrawEdge(&Rect, BDR_RAISEDINNER, BF_RECT);     //画边框
}
pDC->SetTextColor(fColor);         //画文字
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText(m_strText, &m_ButRect, DT_SINGLELINE | DT_CENTER
| DT_VCENTER | DT_END_ELLIPSIS);
//绘制拥有焦点按钮的虚线框
if (GetFocus() == this)
{
CRect Rect;
Rect.SetRect(m_ButRect.left + 3, m_ButRect.top + 2, m_ButRect.right - 3, m_ButRect.bottom - 2);
pDC->DrawFocusRect(&Rect);     //画拥有焦点的虚线框
}
}


void CMyButton::OnMouseHover(UINT nFlags, CPoint point)
{
// TODO:  在此添加消息处理程序代码和/或调用默认值
if (!b_InRect || GetCapture() != this)     //鼠标进入按钮
{
b_InRect = true;     //设置进入标志
SetCapture();        //捕获鼠标
m_Style = 1;         //设置按钮状态
Invalidate();        //重绘按钮
}
else
{
if (!m_ButRect.PtInRect(point))     //鼠标离开按钮
{
b_InRect = false;    //清除进入标志
ReleaseCapture();    //释放捕获的鼠标
m_Style = 0;         //设置按钮状态
Invalidate();        //重绘按钮
}
}
CButton::OnMouseHover(nFlags, point);
}




void CMyButton::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO:  在此添加消息处理程序代码和/或调用默认值
m_Style = 2;
Invalidate();
CButton::OnLButtonDown(nFlags, point);
}




void CMyButton::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO:  在此添加消息处理程序代码和/或调用默认值
m_Style = 1;
Invalidate();
CButton::OnLButtonUp(nFlags, point);
}


void CMyButton::SetText(CString str)
{
m_strText=_T("");
SetWindowText(str);
}


void CMyButton::SetForeColor(COLORREF color)
{
m_ForeColor = color;
Invalidate();
}


void CMyButton::SetBKColor(COLORREF color)
{
m_BackColor = color;
Invalidate();
}


void CMyButton::SetTextFont(int FontHight, LPCTSTR FontName)
{
if (p_Font) delete p_Font;
p_Font = new CFont;
p_Font->CreatePointFont(FontHight,FontName);
SetFont(p_Font);
}





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值