1 串转换 CString && TCHAR*
CString 转换 TCHAR*
int iLen = strRet.GetLength();
TCHAR* szRs = new TCHAR[iLen];
lstrcpy(szRs, strRet.GetBuffer(iLen));
2 TCHAR[]转换CString
TCHAR szTemp[MaxLen]={0};
CString strTemp;
strTemp = CString(szTemp);
3 CString转换 char[]
strcpy_s(noteSign.szNoticeSender,20,_bstr_t(m_strSender));
4 CString 转换 int
int nIndex = _wtoi(strTemp);
5 CString 转char *
void CLServiceDlg::MyWideCharToMultiByte(WCHAR*wchars,CHAR*schars,int scharsLen)
{
memset(schars,0,scharsLen);
CString m_snd = wchars;
int len = m_snd.GetLength();
CString tmpstr(m_snd); //复制要发送的字符串
int multibytelen=WideCharToMultiByte(//计算从Unicode转换到Ansi后需要的字节数
CP_ACP,//根据ANSI code page转换
WC_COMPOSITECHECK| WC_DEFAULTCHAR, //转换出错用缺省字符代替
(LPCWSTR)tmpstr.GetBuffer(len), //要转换的字符串地址
len, //要转换的个数
0, //转换后字符串放置的地址
0, //最多转换字符的个数,为表示返回转换Unicode后需要多少个字节
0, //缺省的字符:"/0"
0 //缺省的设置
);
WideCharToMultiByte(//转换Unicode到Ansi
CP_ACP,
WC_COMPOSITECHECK| WC_DEFAULTCHAR,
(LPCWSTR)tmpstr.GetBuffer(len),
len,
(char *)schars, //转换到缓冲区中
scharsLen,//最多个字节
0,
0
);
};
调用
char *m_szIp = new char[MAX_PATH];
if (!smsg.szIPAddr.IsEmpty())
{
MyWideCharToMultiByte((LPWSTR)smsg.szIPAddr.GetBuffer(0),m_szIp,MAX_PATH);
}
结束
6 BYTE sendbuf.Head[0] = 0x55;
7 宽字符和多字符
(CStringA)strRequestBody
Char* 转 char数组
char szBuf[2048];
strcpy_s(szBuf,strlen(pChar),pChar);
///nunicode转换 UTF-8
//wchar_t* pWChar =NULL;
//DWORD nLen1;
将新浪网页UTF-8格式编码转换成Unicode
//nLen1 =MultiByteToWideChar(CP_UTF8,0,(LPCSTR)(CStringA)strRequestBody,strRequestBody.GetLength(),pWChar,0);
//pWChar = new wchar_t[nLen1 + 1];
//memset(pWChar,0,(nLen1+ 1 ) * sizeof(wchar_t));
//MultiByteToWideChar(CP_UTF8,0,(LPCSTR)(CStringA)strRequestBody,strRequestBody.GetLength(),pWChar,nLen1);
//char* pChar = NULL;
//DWORD nLen2;
//nLen2 =WideCharToMultiByte(CP_ACP,0,pWChar,nLen1,pChar,0,NULL,NULL);
//pChar =new char[nLen2 + 1];
//memset(pChar,0,nLen2 + 1);
//WideCharToMultiByte(CP_UTF8,0,pWChar,nLen1,pChar,nLen2,NULL,NULL);
// 查找登录时服务器时返回的信息
/*char szBuf[2048];
strcpy_s(szBuf,strlen(pChar),pChar);*/
///
//pFile->SendRequest(NULL,0, pBuf, strlen(pChar));
8 PostMessage(,,)相当于一个线程,可以运行多个
9 Time转CString
CString strDate;
strDate = input.tmSendTime.Format(_T("%Y/%m/%d%H:%M:%S"));
_variant_t szSignTime
COleDateTime time;
SYSTEMTIMEsystime;
time=(COleDateTime)szSignTime;
VariantTimeToSystemTime(time, &systime);
CTimetm(systime);
nSign.tmSignTime = tm;
菜单功能添加快捷键方法 在资源中 Accelerator下添加。
10 弹出框选择是或者否
int nRes = AfxMessageBox("你下岗了吗?",MB_YESNO|MB_ICONQUESTION);
if(nRes == IDYES)
{
AfxMessageBox("我下岗了。");
}
else
{
AfxMessageBox("我上班了。");
}
11 获取CMainFrame指针
CMainFrame* pMain = (CMainFrame*)AfxGetApp()->m_pMainWnd;
12 postmessage 发送tchar
发送:TCHAR *szSendIp= new TCHAR[20];
memset(szSendIp,0,20);
_tcscpy_s(szSendIp,20,strCfgIp.GetBuffer());
pMain->PostMessage(WM_POSTSENTNEWIP,0,(LPARAM)szSendIp);
接收:TCHAR *szSendIp= (TCHAR* )lParam;
TCHAR sztempIP[20]={0};
_tcscpy_s(sztempIP,20,szSendIp);
m_szNewIp= sztempIP ;
delete[] szSendIp;
13 开源视频技术
ffmpeg live555 vlc等
14 UTF8转换
char *str1[1];
URLEncode(m_szContent1, str1);
void URLEncode( char* szIn, char** pOut )
{
intnInLenth = ( int ) strlen( szIn );
intnFlag = 0;
BYTEbyte;
*pOut= new char[nInLenth*3];
char*szOut = *pOut;
for( int i = 0; i < nInLenth; i++ )
{
byte= szIn[i];
if( isalnum( byte ) )
{
szOut[nFlag++]= byte;
}
else
{
if( isspace( byte ) )
{
szOut[nFlag++]= '+';
}
else
{
szOut[nFlag++]= '%';
szOut[nFlag++]= TOHEX( byte >> 4 );
szOut[nFlag++]= TOHEX( byte % 16 );
}
}
}
szOut[nFlag]= '\0';
}