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

📄 controlsetdialog.cpp

📁 自己写的俄罗斯方块
💻 CPP
字号:
// ControlsetDialog.cpp : implementation file
//

#include "stdafx.h"
#include "Tetris.h"
#include "ControlsetDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CControlsetDialog dialog
/*********定义键盘上每个键的名称**********/
char KeyDefString[KEYBOARD_NUMBER][KEYBOARD_STRINGLENGTH]={"",
/*#define DIK_ESCAPE          0x01*/	"Escape",
/*#define DIK_1               0x02*/	"1",
/*#define DIK_2               0x03*/	"2",
/*#define DIK_3               0x04*/	"3",
/*#define DIK_4               0x05*/	"4",
/*#define DIK_5               0x06*/	"5",
/*#define DIK_6               0x07*/	"6",
/*#define DIK_7               0x08*/	"7",
/*#define DIK_8               0x09*/	"8",
/*#define DIK_9               0x0A*/	"9",
/*#define DIK_0               0x0B*/	"0",
/*#define DIK_MINUS           0x0C*/	"-",
/*#define DIK_EQUALS          0x0D*/	"=",
/*#define DIK_BACK            0x0E*/	"backspace",
/*#define DIK_TAB             0x0F*/	"Table",
/*#define DIK_Q               0x10*/	"Q",
/*#define DIK_W               0x11*/	"W",
/*#define DIK_E               0x12*/	"E",
/*#define DIK_R               0x13*/	"R",
/*#define DIK_T               0x14*/	"T",
/*#define DIK_Y               0x15*/	"Y",
/*#define DIK_U               0x16*/	"U",
/*#define DIK_I               0x17*/	"I",
/*#define DIK_O               0x18*/	"O",
/*#define DIK_P               0x19*/	"P",
/*#define DIK_LBRACKET        0x1A*/	"[",
/*#define DIK_RBRACKET        0x1B*/	"]",
/*#define DIK_RETURN          0x1C*/	"Enter",
/*#define DIK_LCONTROL        0x1D*/	"Left Control",
/*#define DIK_A               0x1E*/	"A",
/*#define DIK_S               0x1F*/	"S",
/*#define DIK_D               0x20*/	"D",
/*#define DIK_F               0x21*/	"F",
/*#define DIK_G               0x22*/	"G",
/*#define DIK_H               0x23*/	"H",
/*#define DIK_J               0x24*/	"J",
/*#define DIK_K               0x25*/	"K",
/*#define DIK_L               0x26*/	"L",
/*#define DIK_SEMICOLON       0x27*/	"Semicolon",
/*#define DIK_APOSTROPHE      0x28*/	"Apostrophe",
/*#define DIK_GRAVE           0x29*/	"accent grave",
/*#define DIK_LSHIFT          0x2A*/	"Left Shift",
/*#define DIK_BACKSLASH       0x2B*/	"Back Slash",
/*#define DIK_Z               0x2C*/	"Z",
/*#define DIK_X               0x2D*/	"X",
/*#define DIK_C               0x2E*/	"C",
/*#define DIK_V               0x2F*/	"V",
/*#define DIK_B               0x30*/	"B",
/*#define DIK_N               0x31*/	"N",
/*#define DIK_M               0x32*/	"M",
/*#define DIK_COMMA           0x33*/	",",
/*#define DIK_PERIOD          0x34*/	".",
/*#define DIK_SLASH           0x35*/	"/",
/*#define DIK_RSHIFT          0x36*/	"Right Shift",
/*#define DIK_MULTIPLY        0x37*/	"*",
/*#define DIK_LMENU           0x38*/	"left Alt",
/*#define DIK_SPACE           0x39*/	"Space Bar",
/*#define DIK_CAPITAL         0x3A*/	"Capital",
/*#define DIK_F1              0x3B*/	"F1",
/*#define DIK_F2              0x3C*/	"F2",
/*#define DIK_F3              0x3D*/	"F3",
/*#define DIK_F4              0x3E*/	"F4",
/*#define DIK_F5              0x3F*/	"F5",
/*#define DIK_F6              0x40*/	"F6",
/*#define DIK_F7              0x41*/	"F7",
/*#define DIK_F8              0x42*/	"F8",
/*#define DIK_F9              0x43*/	"F9",
/*#define DIK_F10             0x44*/	"F10",
/*#define DIK_NUMLOCK         0x45*/	"Number Lock",
/*#define DIK_SCROLL          0x46*/	"Scroll Lock",
/*#define DIK_NUMPAD7         0x47*/	"NumPad 7",
/*#define DIK_NUMPAD8         0x48*/	"NumPad 8",
/*#define DIK_NUMPAD9         0x49*/	"NumPad 9",
/*#define DIK_SUBTRACT        0x4A*/	"Substract",
/*#define DIK_NUMPAD4         0x4B*/	"NumPad 4",
/*#define DIK_NUMPAD5         0x4C*/	"NumPad 5",
/*#define DIK_NUMPAD6         0x4D*/	"NumPad 6",
/*#define DIK_ADD             0x4E*/	"Add",
/*#define DIK_NUMPAD1         0x4F*/	"NumPad 1",
/*#define DIK_NUMPAD2         0x50*/	"NumPad 2",
/*#define DIK_NUMPAD3         0x51*/	"NumPad 3",
/*#define DIK_NUMPAD0         0x52*/	"NumPad 0",
/*#define DIK_DECIMAL         0x53*/	"NumPad .", "", "",
/*#define DIK_OEM_102         0x56*/	"",
/*#define DIK_F11             0x57*/	"F11",
/*#define DIK_F12             0x58*/	"F12", "", "", "", "", "", "", "", "", "", "", "",
/*#define DIK_F13             0x64*/	"",
/*#define DIK_F14             0x65*/	"",
/*#define DIK_F15             0x66*/	"", "", "", "", "", "", "", "", "", "",
/*#define DIK_KANA            0x70*/	"", "", "",
/*#define DIK_ABNT_C1         0x73*/	"", "", "", "", "", "",
/*#define DIK_CONVERT         0x79*/	"", "",
/*#define DIK_NOCONVERT       0x7B*/	"", "",
/*#define DIK_YEN             0x7D*/	"",
/*#define DIK_ABNT_C2         0x7E*/	"Numpad . on Brazilian keyboard", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
/*#define DIK_NUMPADEQUALS    0x8D*/	"", "", "",
/*#define DIK_PREVTRACK       0x90*/	"",
/*#define DIK_AT              0x91*/	"",
/*#define DIK_COLON           0x92*/	"",
/*#define DIK_UNDERLINE       0x93*/	"",
/*#define DIK_KANJI           0x94*/	"",
/*#define DIK_STOP            0x95*/	"",
/*#define DIK_AX              0x96*/	"",
/*#define DIK_UNLABELED       0x97*/	"", "",
/*#define DIK_NEXTTRACK       0x99*/	"Next Track", "", "",
/*#define DIK_NUMPADENTER     0x9C*/	"Enter on numeric keypad",
/*#define DIK_RCONTROL        0x9D*/	"Right Control", "", "",
/*#define DIK_MUTE            0xA0*/	"Mute",
/*#define DIK_CALCULATOR      0xA1*/	"Calculator",
/*#define DIK_PLAYPAUSE       0xA2*/	"Play / Pause", "",
/*#define DIK_MEDIASTOP       0xA4*/	"Media Stop", "", "", "", "", "", "", "", "", "",
/*#define DIK_VOLUMEDOWN      0xAE*/	"Volume -", "",
/*#define DIK_VOLUMEUP        0xB0*/	"Volume +", "",
/*#define DIK_WEBHOME         0xB2*/	"Web home",
/*#define DIK_NUMPADCOMMA     0xB3*/	"", "",
/*#define DIK_DIVIDE          0xB5*/	"NumPad /", "",
/*#define DIK_SYSRQ           0xB7*/	"SysRQ",
/*#define DIK_RMENU           0xB8*/	"right Alt", "", "", "", "", "", "", "", "", "", "", "", "",
/*#define DIK_PAUSE           0xC5*/	"Pause", "",
/*#define DIK_HOME            0xC7*/	"Home",
/*#define DIK_UP              0xC8*/	"UpArrow",
/*#define DIK_PRIOR           0xC9*/	"PgUp", "",
/*#define DIK_LEFT            0xCB*/	"LeftArrow", "",
/*#define DIK_RIGHT           0xCD*/	"RightArrow", "",
/*#define DIK_END             0xCF*/	"End",
/*#define DIK_DOWN            0xD0*/	"DownArrow",
/*#define DIK_NEXT            0xD1*/	"PgDn",
/*#define DIK_INSERT          0xD2*/	"Insert",
/*#define DIK_DELETE          0xD3*/	"Delete", "", "", "", "", "", "", "",
/*#define DIK_LWIN            0xDB*/	"Left Winkey",
/*#define DIK_RWIN            0xDC*/	"Right Winkey",
/*#define DIK_APPS            0xDD*/	"AppMenu key",
/*#define DIK_POWER           0xDE*/	"System Power",
/*#define DIK_SLEEP           0xDF*/	"System Sleep", "", "", "",
/*#define DIK_WAKE            0xE3*/	"System Wake", "",
/*#define DIK_WEBSEARCH       0xE5*/	"Web Search",
/*#define DIK_WEBFAVORITES    0xE6*/	"Web Favorites",
/*#define DIK_WEBREFRESH      0xE7*/	"Web Refresh",
/*#define DIK_WEBSTOP         0xE8*/	"Web Stop",
/*#define DIK_WEBFORWARD      0xE9*/	"Web Forward",
/*#define DIK_WEBBACK         0xEA*/	"Web Back",
/*#define DIK_MYCOMPUTER      0xEB*/	"My Computer",
/*#define DIK_MAIL            0xEC*/	"Mail",
/*#define DIK_MEDIASELECT     0xED*/	"Media Select",
};

CControlsetDialog::CControlsetDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CControlsetDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CControlsetDialog)
	//}}AFX_DATA_INIT
}


void CControlsetDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CControlsetDialog)
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CControlsetDialog, CDialog)
	//{{AFX_MSG_MAP(CControlsetDialog)
	ON_EN_SETFOCUS(IDC_EDIT_LEFT1, OnSetfocusEditLeft1)
	ON_EN_SETFOCUS(IDC_EDIT_RIGHT1, OnSetfocusEditRight1)
	ON_EN_SETFOCUS(IDC_EDIT_ROTATE1, OnSetfocusEditRotate1)
	ON_EN_SETFOCUS(IDC_EDIT_BOTTOM1, OnSetfocusEditBottom1)
	ON_EN_SETFOCUS(IDC_EDIT_DOWN1, OnSetfocusEditDown1)
	ON_EN_SETFOCUS(IDC_EDIT_LEFT2, OnSetfocusEditLeft2)
	ON_EN_SETFOCUS(IDC_EDIT_RIGHT2, OnSetfocusEditRight2)
	ON_EN_SETFOCUS(IDC_EDIT_ROTATE2, OnSetfocusEditRotate2)
	ON_EN_SETFOCUS(IDC_EDIT_BOTTOM2, OnSetfocusEditBottom2)
	ON_EN_SETFOCUS(IDC_EDIT_DOWN2, OnSetfocusEditDown2)
	ON_WM_TIMER()
	ON_EN_KILLFOCUS(IDC_EDIT_BOTTOM1, OnKillfocusEditBottom1)
	ON_EN_KILLFOCUS(IDC_EDIT_BOTTOM2, OnKillfocusEditBottom2)
	ON_EN_KILLFOCUS(IDC_EDIT_DOWN1, OnKillfocusEditDown1)
	ON_EN_KILLFOCUS(IDC_EDIT_DOWN2, OnKillfocusEditDown2)
	ON_EN_KILLFOCUS(IDC_EDIT_LEFT1, OnKillfocusEditLeft1)
	ON_EN_KILLFOCUS(IDC_EDIT_LEFT2, OnKillfocusEditLeft2)
	ON_EN_KILLFOCUS(IDC_EDIT_RIGHT1, OnKillfocusEditRight1)
	ON_EN_KILLFOCUS(IDC_EDIT_RIGHT2, OnKillfocusEditRight2)
	ON_EN_KILLFOCUS(IDC_EDIT_ROTATE1, OnKillfocusEditRotate1)
	ON_EN_KILLFOCUS(IDC_EDIT_ROTATE2, OnKillfocusEditRotate2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CControlsetDialog message handlers

BOOL CControlsetDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	playercontrol=-1;

	GetDlgItem(IDC_EDIT_LEFT1)->SetWindowText(	KeyDefString[Keydef[0][KeyDef_Left]]);
	GetDlgItem(IDC_EDIT_LEFT2)->SetWindowText(	KeyDefString[Keydef[1][KeyDef_Left]]);
	GetDlgItem(IDC_EDIT_RIGHT1)->SetWindowText(	KeyDefString[Keydef[0][KeyDef_Right]]);
	GetDlgItem(IDC_EDIT_RIGHT2)->SetWindowText(	KeyDefString[Keydef[1][KeyDef_Right]]);
	GetDlgItem(IDC_EDIT_ROTATE1)->SetWindowText(KeyDefString[Keydef[0][KeyDef_Rotate]]);
	GetDlgItem(IDC_EDIT_ROTATE2)->SetWindowText(KeyDefString[Keydef[1][KeyDef_Rotate]]);
	GetDlgItem(IDC_EDIT_BOTTOM1)->SetWindowText(KeyDefString[Keydef[0][KeyDef_Bottom]]);
	GetDlgItem(IDC_EDIT_BOTTOM2)->SetWindowText(KeyDefString[Keydef[1][KeyDef_Bottom]]);
	GetDlgItem(IDC_EDIT_DOWN1)->SetWindowText(	KeyDefString[Keydef[0][KeyDef_Down]]);
	GetDlgItem(IDC_EDIT_DOWN2)->SetWindowText(	KeyDefString[Keydef[1][KeyDef_Down]]);

	InitDirectInput(m_hWnd);
	SetTimer(1000, 50, NULL);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CControlsetDialog::OnCancel()
{
	KillTimer(1000);
	FreeDirectInput();
	CDialog::OnCancel();
}

void CControlsetDialog::OnOK() 
{
	KillTimer(1000);
	FreeDirectInput();
	UpdateData();	
	CDialog::OnOK();
}

void CControlsetDialog::OnTimer(UINT nIDEvent)
{	//每间隔一定时间读取键盘缓冲,如果有输入则保存到keydef数组
	if(playercontrol!=-1)
	{
		DWORD dwElements;
		DIDEVICEOBJECTDATA didod[ DINPUT_BUFFER_SIZE ];
		ReadBufferedData(didod, dwElements);
		if(dwElements<DINPUT_BUFFER_SIZE)
			for(DWORD i=0;i<dwElements;i++)
				if((didod[i].dwData & 0x80) && didod[i].dwOfs!=0x0f)
				{
					Keydef[playercontrol][nkeydef]=didod[i].dwOfs;
					GetDlgItem(ControlID)->SetWindowText(KeyDefString[didod[i].dwOfs]);
					NextDlgCtrl();
					if(playercontrol==-1)
						break;
				}
	}
	CDialog::OnTimer(nIDEvent);
}
//当不同的edit control得到焦点的时候改变playercontrol和nkeydef、controlid的值
void CControlsetDialog::OnSetfocusEditLeft1() 
{	playercontrol=0;	nkeydef=0;	ControlID=IDC_EDIT_LEFT1;	}
void CControlsetDialog::OnSetfocusEditRight1() 
{	playercontrol=0;	nkeydef=1;	ControlID=IDC_EDIT_RIGHT1;	}
void CControlsetDialog::OnSetfocusEditRotate1() 
{	playercontrol=0;	nkeydef=2;	ControlID=IDC_EDIT_ROTATE1;	}
void CControlsetDialog::OnSetfocusEditBottom1() 
{	playercontrol=0;	nkeydef=3;	ControlID=IDC_EDIT_BOTTOM1;	}
void CControlsetDialog::OnSetfocusEditDown1() 
{	playercontrol=0;	nkeydef=4;	ControlID=IDC_EDIT_DOWN1;	}
void CControlsetDialog::OnSetfocusEditLeft2() 
{	playercontrol=1;	nkeydef=0;	ControlID=IDC_EDIT_LEFT2;	}
void CControlsetDialog::OnSetfocusEditRight2() 
{	playercontrol=1;	nkeydef=1;	ControlID=IDC_EDIT_RIGHT2;	}
void CControlsetDialog::OnSetfocusEditRotate2() 
{	playercontrol=1;	nkeydef=2;	ControlID=IDC_EDIT_ROTATE2;	}
void CControlsetDialog::OnSetfocusEditBottom2() 
{	playercontrol=1;	nkeydef=3;	ControlID=IDC_EDIT_BOTTOM2;	}
void CControlsetDialog::OnSetfocusEditDown2() 
{	playercontrol=1;	nkeydef=4;	ControlID=IDC_EDIT_DOWN2;	}

void CControlsetDialog::OnKillfocusEditBottom1() {	playercontrol=-1;}
void CControlsetDialog::OnKillfocusEditBottom2() {	playercontrol=-1;}
void CControlsetDialog::OnKillfocusEditDown1() {	playercontrol=-1;}
void CControlsetDialog::OnKillfocusEditDown2() {	playercontrol=-1;}
void CControlsetDialog::OnKillfocusEditLeft1() {	playercontrol=-1;}
void CControlsetDialog::OnKillfocusEditLeft2() {	playercontrol=-1;}
void CControlsetDialog::OnKillfocusEditRight1() {	playercontrol=-1;}
void CControlsetDialog::OnKillfocusEditRight2() {	playercontrol=-1;}
void CControlsetDialog::OnKillfocusEditRotate1() {	playercontrol=-1;}
void CControlsetDialog::OnKillfocusEditRotate2() {	playercontrol=-1;}

⌨️ 快捷键说明

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