📄 public.cpp
字号:
/*========================================================================
文件: public.cpp
说明:公用函数
时间:2004-06
编写:oshj || oshj@21cn.com
环境:VC6.0/Win2000 Pro/SP4/1024*768
特别说明:随时更新
版权累死人,想用就用吧:-)
=========================================================================*/
#include "public.h"
//-----------------------------------------------------------------
//提示MessageBox
void MsgInf(char* str)
{
MessageBox(0,TEXT(str),TEXT("信息"),MB_OK);
}
//-----------------------------------------------------------------
//错误MessageBox
void MsgErr(char* str)
{
MessageBox(0,TEXT(str),TEXT("错误"),MB_OK);
}
//-----------------------------------------------------------------
//询问MessageBox
BOOL MsgYN(char* str)
{
if( (MessageBox(0,TEXT(str),TEXT("提示信息"),MB_YESNO |
MB_ICONINFORMATION | MB_DEFBUTTON2) == IDNO ) )
{
return FALSE;
}
return TRUE;
}
//-----------------------------------------------------------------
//Ansi Unicode转换
LPCWSTR AnsiToUnicode(LPCSTR strAnsi)
{
WCHAR* strReturn;//[255] = {'\0'};
int iLen;
//strReturn = SysAllocString();
//计算从Ansi转换到Unicode后需要的字节数
iLen = MultiByteToWideChar(CP_ACP,
MB_COMPOSITE,
strAnsi, //要转换的Ansi字符串
-1, //自动计算长度
NULL,
0 );
strReturn = new WCHAR[iLen +1];
//从Ansi转换到Unicode字符
MultiByteToWideChar( CP_ACP,
MB_COMPOSITE,
strAnsi,
-1,
strReturn, //转换到strReturn
iLen); //最多转换widecharlen个Unicode字符
return (LPCWSTR)strReturn;
}
//-----------------------------------------------------------------
//Unicode Ansi转换
LPCSTR UnicodeToAnsi(LPCWSTR strUnicode)
{
char *strReturn; //[255] = {'\0'};
int iLen;
//计算从Unicode转换到Ansi后需要的字节数
iLen = WideCharToMultiByte(
CP_ACP, //根据ANSI code page转换
WC_COMPOSITECHECK | WC_DEFAULTCHAR, //转换出错用缺省字符代替
strUnicode, //要转换的字符串地址
-1, //要转换的个数,-1为自动计算
NULL, //转换后字符串放置的地址
0, //最多转换字符的个数,为0表示返回转换Unicode后需要多少个字节
NULL, //缺省的字符:"\0"
NULL //缺省的设置
);
strReturn = new char[iLen + 1];
//转换Unicode到Ansi
WideCharToMultiByte(CP_ACP,
WC_COMPOSITECHECK | WC_DEFAULTCHAR,
strUnicode,
-1,
strReturn, //转换到缓冲区中
iLen, //要转换的长度
NULL,
NULL );
//don't free!
//delete strReturn;
return (LPCSTR)strReturn;
}
//-----------------------------------------------------------------
//判断是否字符
BOOL IsAlpha(const char* source)
{
int iLen,i;
if(strlen(source) <= 0)
return FALSE;
iLen = strlen(source);
for(i = 0; i < iLen; i++)
{
if( ((source[i] < 'A') || (source[i] > 'Z')) && //大写
((source[i] < 'a') || (source[i] > 'z')) ) //小写
{
;
}
else
{
return FALSE;
}
}
return TRUE;
}
//-----------------------------------------------------------------
//判断是否数字
BOOL IsDigital(const char* source)
{
/*
int iLen,i;
if(strlen(source) <= 0)
return FALSE;
iLen = strlen(source);
for(i = 0; i < iLen; i++)
{
if((source[i] >= '0') && (source[i] <= '9'))
{
;
}
else
{
return FALSE;
}
}
return TRUE;
*/
int iLen,i;
if(strlen(source) <= 0)
return FALSE;
iLen = strlen(source);
for(i = 0; i < iLen; i++)
{
if( isdigit(source[i]) == 0 )
{
return FALSE;
}
}
return TRUE;
}
//-----------------------------------------------------------------
//判断是否浮点型
BOOL IsFloat(const char* source)
{
int iLen,i;
if(strlen(source) <= 0)
return FALSE;
iLen = strlen(source);
for(i = 0; i < iLen; i++)
{
if((source[i] >= '0') && (source[i] <= '9') || (source[i] == '.'))
{
;
}
else
{
return FALSE;
}
}
return TRUE;
}
//-----------------------------------------------------------------
//判断是否宽字节数字型
BOOL IsWDigital(const wchar_t* source)
{
int iLen,i;
if(wcslen(source) <= 0)
return FALSE;
iLen = wcslen(source);
for(i = 0; i < iLen; i++)
{
if( iswdigit(source[i]) == 0 )
{
return FALSE;
}
}
return TRUE;
}
//-----------------------------------------------------------------
//判断是否宽字节浮点型
BOOL IsWFloat(const wchar_t* source)
{
int iLen,i;
if(wcslen(source) <= 0)
return FALSE;
iLen = wcslen(source);
for(i = 0; i < iLen; i++)
{
if( iswdigit(source[i]) != 0 || (source[i] == '.') )
{
;
}
else
return FALSE;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -