📄 edithex.cpp
字号:
// EditHex.cpp : implementation file
//
#include "stdafx.h"
#include "AESDemo.h"
#include "EditHex.h"
// CEditHex
IMPLEMENT_DYNAMIC(CEditHex, CEdit)
CEditHex::CEditHex() :
m_State(EMHEX)
{
}
CEditHex::~CEditHex()
{
}
BEGIN_MESSAGE_MAP(CEditHex, CEdit)
ON_WM_CHAR()
// ON_CONTROL_REFLECT(EN_MAXTEXT, OnEnMaxtext)
ON_WM_CREATE()
END_MESSAGE_MAP()
// CEditHex message handlers
void CEditHex::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
// If in Hex Mode, only pass Hex characters
if(EMHEX==m_State)
{
// Block out any editable non-hex characters
if ((nChar >= 'G' && nChar <= 'Z') ||
(nChar >= 'g' && nChar <= 'z'))
{
// Invalid Hex character, let the user know
MessageBeep(-1);
}
else
{
// Valid Hex character, pass it along
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}
else
{
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}
// Get the data - copies the data to the passed byte pointer and returns the count
int CEditHex::GetData(int *piData)
{
int nLength;
if (piData)
nLength = StrToHex(piData);
return nLength;
}
// Converts the Display string hexidecimal data
int CEditHex::StrToHex(int *piData)
{
UINT nLength;
CString strData;
// Get the text data
GetWindowText(strData);
nLength = strData.GetLength();
// Make sure the text data is hex
for(int i = 0; i < strData.GetLength(); i++)
{
if (-1 == CharToHexInt(strData[i]))
// Text is not a hex string, return an error
return -1;
}
// Convert data
for(i = 0; (i < (int)nLength/2) && (i < MAX_BLOCKSIZE); i++)
{
piData[i] = 0;
piData[i] = (CharToHexInt(strData[i<<1])<<4) | (CharToHexInt(strData[(i<<1)+1]));
}
return nLength/2;
}
int CEditHex::CharToHexInt(const char str)
{
if (str >= '0' && str <= '9')
return (int)((str - '0')&0xff);
else if (str >= 'A' && str <= 'F')
return (int)(((str-'A')+0xA)&0xff);
else
return -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -