?? stdafx.cpp
字號:
// stdafx.cpp : 只包括標準包含文件的源文件
// GPRSDemo.pch 將作為預編譯頭
// stdafx.obj 將包含預編譯類型信息
#include "stdafx.h"
//
// 將字符串 lpszOrg 轉換為多字節的字符串,如果還要使用多字符串的長度,可以用以下方式來使用這個類:
// CMultiByteString MultiByteString(_T("UNICODE字符串"));
// printf ( "ANSI 字符串為: %s, 長度為: %d 字節\n", MultiByteString.GetBuffer(), MultiByteString.GetLength() );
//
CMultiByteString::CMultiByteString( LPCTSTR lpszOrg, int nOrgStringEncodeType/*=STRING_IS_SOFTCODE*/, OUT char *buf/*=NULL*/, int size/*=0*/, OUT int *pnCount/*=NULL*/ )
{
m_bNewBuffer = FALSE;
m_pszData = "";
if ( !lpszOrg ) return;
int nCount = 0;
BOOL bOrgIsUncode = FALSE;
if ( nOrgStringEncodeType == STRING_IS_MULTICHARS ) bOrgIsUncode = FALSE;
else if ( nOrgStringEncodeType == STRING_IS_UNICODE ) bOrgIsUncode = TRUE;
else
{
#ifdef UNICODE
bOrgIsUncode = TRUE;
#else
bOrgIsUncode = FALSE;
#endif
}
if ( buf && size > 0 )
{
m_pszData = buf;
}
else
{
int nLen = 0;
if ( bOrgIsUncode ) nLen = (int)wcslen((WCHAR*)lpszOrg) * 2 + sizeof(WCHAR);
else nLen = (int)strlen((const char*)lpszOrg) + sizeof(char);
m_pszData = new char[nLen];
if ( !m_pszData )
{
::AfxThrowMemoryException ();
return;
}
size = nLen;
m_bNewBuffer = TRUE;
}
memset ( m_pszData, 0, size );
if ( bOrgIsUncode )
{
nCount = WideCharToMultiByte ( CP_ACP, 0, lpszOrg, (int)lstrlen(lpszOrg), (LPSTR)m_pszData, size, NULL, NULL );
}
else
{
nCount = (int)strlen((const char*)lpszOrg);
nCount = __min(nCount,size);
memcpy ( m_pszData, lpszOrg, nCount );
}
if ( pnCount ) *pnCount = nCount;
}
CMultiByteString::~CMultiByteString ()
{
if ( m_bNewBuffer && m_pszData )
{
delete[] m_pszData;
}
}
//
// 將 lpszOrg 轉換為該程序使用的編碼字符串,如果該程序是 UNICODE 就轉為 UNICODE,如果是 ANSI 就轉為 ANSI 的
//
CString GetCompatibleString ( LPVOID lpszOrg, BOOL bOrgIsUncode )
{
if ( !lpszOrg ) return _T("");
#ifdef UNICODE
if ( bOrgIsUncode ) return (LPCTSTR)lpszOrg;
int nOrgLen = (int)strlen((const char*)lpszOrg);
int nWideCount = nOrgLen + 1;
WCHAR *wchar = new WCHAR[nWideCount];
if ( !wchar ) return _T("");
memset ( wchar, 0, nWideCount*sizeof(WCHAR) );
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)lpszOrg, nOrgLen, wchar, nWideCount);
CString csRet = wchar;
delete[] wchar;
return csRet;
#else
if ( !bOrgIsUncode ) return (LPCTSTR)lpszOrg;
int nOrgLen = (int)strlen((LPCTSTR)lpszOrg);
int nMultiByteSize = nOrgLen / sizeof(WCHAR) + 2;
CString csRet;
CMultiByteString ( (LPCTSTR)lpszOrg, csRet.GetBuffer(nMultiByteSize), nMultiByteSize, 1 );
csRet.ReleaseBuffer();
return csRet;
#endif
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -