?? public.cpp
字號:
/*========================================================================
文件: public.cpp
說明:公用函數(shù)
時間:2004-06
編寫:oshj || oshj@21cn.com
環(huán)境:VC6.0/Win2000 Pro/SP4/1024*768
特別說明:隨時更新
版權(quán)累死人,想用就用吧:-)
=========================================================================*/
#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轉(zhuǎn)換
LPCWSTR AnsiToUnicode(LPCSTR strAnsi)
{
WCHAR* strReturn;//[255] = {'\0'};
int iLen;
//strReturn = SysAllocString();
//計算從Ansi轉(zhuǎn)換到Unicode后需要的字節(jié)數(shù)
iLen = MultiByteToWideChar(CP_ACP,
MB_COMPOSITE,
strAnsi, //要轉(zhuǎn)換的Ansi字符串
-1, //自動計算長度
NULL,
0 );
strReturn = new WCHAR[iLen +1];
//從Ansi轉(zhuǎn)換到Unicode字符
MultiByteToWideChar( CP_ACP,
MB_COMPOSITE,
strAnsi,
-1,
strReturn, //轉(zhuǎn)換到strReturn
iLen); //最多轉(zhuǎn)換widecharlen個Unicode字符
return (LPCWSTR)strReturn;
}
//-----------------------------------------------------------------
//Unicode Ansi轉(zhuǎn)換
LPCSTR UnicodeToAnsi(LPCWSTR strUnicode)
{
char *strReturn; //[255] = {'\0'};
int iLen;
//計算從Unicode轉(zhuǎn)換到Ansi后需要的字節(jié)數(shù)
iLen = WideCharToMultiByte(
CP_ACP, //根據(jù)ANSI code page轉(zhuǎn)換
WC_COMPOSITECHECK | WC_DEFAULTCHAR, //轉(zhuǎn)換出錯用缺省字符代替
strUnicode, //要轉(zhuǎn)換的字符串地址
-1, //要轉(zhuǎn)換的個數(shù),-1為自動計算
NULL, //轉(zhuǎn)換后字符串放置的地址
0, //最多轉(zhuǎn)換字符的個數(shù),為0表示返回轉(zhuǎn)換Unicode后需要多少個字節(jié)
NULL, //缺省的字符:"\0"
NULL //缺省的設置
);
strReturn = new char[iLen + 1];
//轉(zhuǎn)換Unicode到Ansi
WideCharToMultiByte(CP_ACP,
WC_COMPOSITECHECK | WC_DEFAULTCHAR,
strUnicode,
-1,
strReturn, //轉(zhuǎn)換到緩沖區(qū)中
iLen, //要轉(zhuǎn)換的長度
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;
}
//-----------------------------------------------------------------
//判斷是否數(shù)字
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;
}
//-----------------------------------------------------------------
//判斷是否寬字節(jié)數(shù)字型
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;
}
//-----------------------------------------------------------------
//判斷是否寬字節(jié)浮點型
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 + -