📄 test.cpp
字号:
// Test.cpp : 定义应用程序的类行为。
//
#include "stdafx.h"
#include "Test.h"
#include "TestDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CTestApp
BEGIN_MESSAGE_MAP(CTestApp, CWinApp)
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
// CTestApp 构造
CTestApp::CTestApp()
{
// TODO: 在此处添加构造代码,
// 将所有重要的初始化放置在 InitInstance 中
}
// 唯一的一个 CTestApp 对象
CTestApp theApp;
// CTestApp 初始化
BOOL CTestApp::InitInstance()
{
// 如果一个运行在 Windows XP 上的应用程序清单指定要
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
//则需要 InitCommonControls()。否则,将无法创建窗口。
InitCommonControls();
CWinApp::InitInstance();
AfxEnableControlContainer();
// 标准初始化
// 如果未使用这些功能并希望减小
// 最终可执行文件的大小,则应移除下列
// 不需要的特定初始化例程
// 更改用于存储设置的注册表项
// TODO: 应适当修改该字符串,
// 例如修改为公司或组织名
//SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
IniAPISocket();
int nLen = MAX_PATH;
BYTE * pucIP = new BYTE[nLen];
if( pucIP != NULL )
{
EnumLocalIP( pucIP, nLen );
for( int nCount = 0; nCount < nLen / 4; nCount++ )
{
TRACE( "\nLocal IP:%d.%d.%d.%d",
pucIP[nCount * 4], pucIP[nCount * 4 + 1], pucIP[nCount * 4 + 2],
pucIP[nCount * 4 + 3] );
}
}
CTestDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: 在此放置处理何时用“确定”来关闭
//对话框的代码
}
else if (nResponse == IDCANCEL)
{
// TODO: 在此放置处理何时用“取消”来关闭
//对话框的代码
}
void CloseAPISocket();
if( pucIP != NULL )
{
delete [] pucIP;
}
// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
// 而不是启动应用程序的消息泵。
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
//
// 将字符串转换为BYTE字符串
// 参数: pucText 需要转换回的字符串
// nLen pucText长度
// 返回值: 转换结果
//
/////////////////////////////////////////////////////////////////////////////
CString GetByteString( const BYTE *pucText, int nLen )
{
int nCount;
CString strByte;
CString strText;
if( nLen <= 0 )
{
return "";
}
for( nCount = 0; nCount < nLen; nCount++ )
{
strByte.Format( "%.2X", pucText[nCount] );
strText += ( strByte + " " );
}
strText = strText.Left(strText.GetLength() - 1 );
return strText;
}
/////////////////////////////////////////////////////////////////////////////
//
// 将BYTE字符串转换为BYTE数组
// 参数: strText 需要转换回的字符串
// pucBuf 转换结果
// 返回值: -1 失败
// 正数 转换后pucBuf的数据大小
//
/////////////////////////////////////////////////////////////////////////////
int GetBytesFromString( CString strText, BYTE *pucBuf )
{
int nCount;
int nDataNum;
CString strByte;
BYTE *pucCharBuf;
if( strText.GetLength() > 1 )
{
pucCharBuf = new BYTE[strText.GetLength()];
memcpy( pucCharBuf, strText.GetBuffer(strText.GetLength()), strText.GetLength() );
}
else
{
return -1;
}
nDataNum = 0;
for( nCount = 0; nCount < strText.GetLength(); nCount += 3 )
{
if( nCount + 1 < strText.GetLength() )
{
pucBuf[nDataNum] = GetHexValue( pucCharBuf[nCount] ) * 16 +
GetHexValue( pucCharBuf[nCount + 1] );
nDataNum++;
}
}
delete [] pucCharBuf;
return nDataNum;
}
/////////////////////////////////////////////////////////////////////////////
//
// 将BYTE字符转换为BYTE数据
// 参数: ucChar 0-9、A-F、a-f的十六进制字符
// 返回值: 转换结果
//
/////////////////////////////////////////////////////////////////////////////
BYTE GetHexValue( BYTE ucChar )
{
if( ucChar >= 48 && ucChar <= 57 )
{
return ucChar - 48;
}
else if( ucChar >= 65 && ucChar <= 70 )
{
return ucChar - 55;
}
else if( ucChar >= 97 && ucChar <= 102 )
{
return ucChar - 87;
}
else
{
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -