void CdemoDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
/*
{
char *p="显示栏";
CString x(p);
SetDlgItemText(IDC_EDIT2, x); //显示到IEC_EDIT2控件
}
// TODO: 在此添加控件通知处理程序代码
size_t gbk_len=0;
int iRet=-1;
char *strTmp;
int to_len=0;
CString str;
GetDlgItem(IDC_EDIT3)->GetWindowText(str); //取得IDC_EDIT3控件输入的值放入str
gbk_len=wcslen( str )+1;
const char *from=(LPSTR)(LPCTSTR)str;
iRet=utf8_to_gbk(from, gbk_len, &strTmp, &to_len);
if(iRet > 0)
{
CString str(str_tmp);
SetDlgItemText(IDC_EDIT2, strTmp); //显示到IEC_EDIT2控件
}else
return;
*/
// TODO: 在此添加控件通知处理程序代码
CString str;
unsigned int uiGbk_len=0;
unsigned int uiUtf8_len=0;
int iRet=50;
GetDlgItem(IDC_EDIT3)->GetWindowText(str); //获得内容
MessageBox(str,_T("输入的内容为:"),1);
// const char *c_pcGbk=(const char *)str.GetBuffer(str.GetLength()); //将CString转换成const char*
wchar_t *origString = str.GetBuffer(str.GetLength());
char CharString[100]={0};
setlocale(LC_ALL,""); //设置语言环境
wcstombs(CharString,origString,100); //将宽字符转换成多字符
setlocale(LC_ALL,"C"); //设置语言环境"C"
const char *c_pcGbk=(const char*)CharString;
str_normalize_init(); //字符初始化
uiGbk_len=(unsigned int)strlen(c_pcGbk)*2;
// uiUtf8_len=(unsigned int)(((uiGbk_len-1)/2)+1);
uiUtf8_len=(unsigned int)((uiGbk_len*2)+1);
char *pcStrTmp=(char *)malloc(uiUtf8_len);
iRet=gbk_to_utf8(c_pcGbk,uiGbk_len, &pcStrTmp ,&uiUtf8_len);
/*
char *pcStrTmp=NULL;int iRet=-1;unsigned int a=6;
pcStrTmp=(char *)malloc(50);
iRet=gbk_to_utf8("E591A8",10, &pcStrTmp ,&a);
*/
if(iRet == 0)
{
if(pcStrTmp == "")
{
MessageBox(str,_T("输入有误 重新输入"),0);
return;
}
// str_tmp.Format("%s",strTmp); //将char*转化成CString
/* for(int i=0;pcStrTmp[i]!='\0';i+=3)
{
sprintf(CharString,"%X%X%X",pcStrTmp[0],pcStrTmp[1],pcStrTmp[2]);
}
*/
sprintf(CharString,"%X%X%X",pcStrTmp[0],pcStrTmp[1],pcStrTmp[2]);
char cBuf[1024]="";
char *p=CharString;
int k=0;
for(int i=0;i < strlen(CharString)/4;i++)
{
p =p+6;
for(int j=0; j < 2;j++)
{
cBuf[k++]=p[j];
}
p+=2;
}
CString str(cBuf); 将char*转化成CString
SetDlgItemText(IDC_EDIT2, str); //显示到IEC_EDIT2控件
}else
{
char *pcEr="失败!";
CString fail(pcEr);
MessageBox(fail,_T("转换失败"),MB_OK);
return;
}
str.ReleaseBuffer();
free(pcStrTmp);
}
void CdemoDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
// TODO: 在此添加控件通知处理程序代码
/*
iRet=gbk_to_utf8(const char *from, unsigned int from_len, char **to, unsigned int *to_len);
iRet=utf8_to_gbk(const char *from, unsigned int from_len, char **to, unsigned int *to_len);
*/
int iRet=-1;
unsigned int uiUtf8_len=0;
unsigned int uiGbk_len=0;
unsigned char ucaTemp[1024]= "\0";
char *pcStrTmp=NULL;
CString str;
unsigned char *pucTp=NULL;
// SetDlgItemText(IDC_EDIT1,_T("E591A8")); //设置默认值
GetDlgItem(IDC_EDIT1)->GetWindowText(str); //取得IDC_EDIT1控件输入的值放入str
if (str == "")
{
MessageBox(str,_T("输入有误 重新输入"),0);
return;
}
// utf8_len=wcslen( str )+1;
// MessageBox(str,_T("运行结果。。。你输入的是"),1);
// sprintf(pucTemp ,_T("%s"),str);
// const char *c_pcUtf8=(LPSTR)(LPCTSTR)str; //强制类型转换将CString转换成char*
// pucTp=(unsigned char*)str.GetBuffer(str.GetAllocLength());
/* int tmp_len = str.GetLength();
char *tmp_str;
tmp_str= (tmp_len);
*/
// pucTp= (unsigned char*)(LPCTSTR)str;
// char *tmp_pucTp=(char *) malloc(1024);
// wchar_t *pwhello = str.GetBuffer(str.GetLength());
// MyWideChar_tToMultiByte(str.GetBuffer(0), tmp_pucTp, sizeof(tmp_pucTp));
// wcstombs(tmp_pucTp,pwhello,1024);
wchar_t *origString = str.GetBuffer(str.GetLength());
char CharString[100]={0};
setlocale(LC_ALL,""); //设置语言环境
wcstombs(CharString,origString,100); //将宽字符转换成多字符
setlocale(LC_ALL,"C"); //设置语言环境"C"
pucTp=(unsigned char*)CharString;
// pucTp=(unsigned char*)str.GetBuffer(str.GetLength());
iRet=MyAHex((unsigned char *)pucTp,ucaTemp,strlen( (char*)pucTp)); //转换编码
str_normalize_init(); //字符初始化
const char *c_pcUtf8=(const char*)pucTp;
uiUtf8_len=strlen((const char*)pucTp)/2;
uiGbk_len=uiUtf8_len*2 +1;
char *pcGbk_buffer =(char *)malloc(uiGbk_len);
iRet=utf8_to_gbk((char *)ucaTemp,3, &pcGbk_buffer ,&uiGbk_len);
// iRet=utf8_to_gbk("我",uiUtf8_len, &pcGbk_buffer ,&uiGbk_len);
/*弹出返回值
char *piRet;
sprintf(piRet,"%s",(char)iRet);
CString ret(piRet);
MessageBox(ret,_T("函数返回值"),MB_OK);
*/
if(iRet == 0)
{
// str.Format("%s",pcGbk_buffer); //将char*转化成CString
CString str(pcGbk_buffer); //将char*转化成CString
if(str == "")
{
CString s("警告【表情】");
MessageBox(s,_T("转换输入内容出错"),MB_ICONEXCLAMATION);
// AfxMessageBox("Are you sure?",MB_YESNO|MB_ICONQUESTION);
return;
}
// MessageBox(str,_T("转换结果"),MB_OK);
SetDlgItemText(IDC_EDIT2, str); //显示到IEC_EDIT2控件
}
else
{
char *pcEr="fail";
CString fail(pcEr);
MessageBox(fail,_T("转换失败"),MB_OK);
SetDlgItemText(IDC_EDIT2, fail); //显示到IEC_EDIT2控件
return;
}
str.ReleaseBuffer();
free(pcGbk_buffer);
//return;
}
{
// TODO: 在此添加控件通知处理程序代码
/*
{
char *p="显示栏";
CString x(p);
SetDlgItemText(IDC_EDIT2, x); //显示到IEC_EDIT2控件
}
// TODO: 在此添加控件通知处理程序代码
size_t gbk_len=0;
int iRet=-1;
char *strTmp;
int to_len=0;
CString str;
GetDlgItem(IDC_EDIT3)->GetWindowText(str); //取得IDC_EDIT3控件输入的值放入str
gbk_len=wcslen( str )+1;
const char *from=(LPSTR)(LPCTSTR)str;
iRet=utf8_to_gbk(from, gbk_len, &strTmp, &to_len);
if(iRet > 0)
{
CString str(str_tmp);
SetDlgItemText(IDC_EDIT2, strTmp); //显示到IEC_EDIT2控件
}else
return;
*/
// TODO: 在此添加控件通知处理程序代码
CString str;
unsigned int uiGbk_len=0;
unsigned int uiUtf8_len=0;
int iRet=50;
GetDlgItem(IDC_EDIT3)->GetWindowText(str); //获得内容
MessageBox(str,_T("输入的内容为:"),1);
// const char *c_pcGbk=(const char *)str.GetBuffer(str.GetLength()); //将CString转换成const char*
wchar_t *origString = str.GetBuffer(str.GetLength());
char CharString[100]={0};
setlocale(LC_ALL,""); //设置语言环境
wcstombs(CharString,origString,100); //将宽字符转换成多字符
setlocale(LC_ALL,"C"); //设置语言环境"C"
const char *c_pcGbk=(const char*)CharString;
str_normalize_init(); //字符初始化
uiGbk_len=(unsigned int)strlen(c_pcGbk)*2;
// uiUtf8_len=(unsigned int)(((uiGbk_len-1)/2)+1);
uiUtf8_len=(unsigned int)((uiGbk_len*2)+1);
char *pcStrTmp=(char *)malloc(uiUtf8_len);
iRet=gbk_to_utf8(c_pcGbk,uiGbk_len, &pcStrTmp ,&uiUtf8_len);
/*
char *pcStrTmp=NULL;int iRet=-1;unsigned int a=6;
pcStrTmp=(char *)malloc(50);
iRet=gbk_to_utf8("E591A8",10, &pcStrTmp ,&a);
*/
if(iRet == 0)
{
if(pcStrTmp == "")
{
MessageBox(str,_T("输入有误 重新输入"),0);
return;
}
// str_tmp.Format("%s",strTmp); //将char*转化成CString
/* for(int i=0;pcStrTmp[i]!='\0';i+=3)
{
sprintf(CharString,"%X%X%X",pcStrTmp[0],pcStrTmp[1],pcStrTmp[2]);
}
*/
sprintf(CharString,"%X%X%X",pcStrTmp[0],pcStrTmp[1],pcStrTmp[2]);
char cBuf[1024]="";
char *p=CharString;
int k=0;
for(int i=0;i < strlen(CharString)/4;i++)
{
p =p+6;
for(int j=0; j < 2;j++)
{
cBuf[k++]=p[j];
}
p+=2;
}
CString str(cBuf); 将char*转化成CString
SetDlgItemText(IDC_EDIT2, str); //显示到IEC_EDIT2控件
}else
{
char *pcEr="失败!";
CString fail(pcEr);
MessageBox(fail,_T("转换失败"),MB_OK);
return;
}
str.ReleaseBuffer();
free(pcStrTmp);
}
void CdemoDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
// TODO: 在此添加控件通知处理程序代码
/*
iRet=gbk_to_utf8(const char *from, unsigned int from_len, char **to, unsigned int *to_len);
iRet=utf8_to_gbk(const char *from, unsigned int from_len, char **to, unsigned int *to_len);
*/
int iRet=-1;
unsigned int uiUtf8_len=0;
unsigned int uiGbk_len=0;
unsigned char ucaTemp[1024]= "\0";
char *pcStrTmp=NULL;
CString str;
unsigned char *pucTp=NULL;
// SetDlgItemText(IDC_EDIT1,_T("E591A8")); //设置默认值
GetDlgItem(IDC_EDIT1)->GetWindowText(str); //取得IDC_EDIT1控件输入的值放入str
if (str == "")
{
MessageBox(str,_T("输入有误 重新输入"),0);
return;
}
// utf8_len=wcslen( str )+1;
// MessageBox(str,_T("运行结果。。。你输入的是"),1);
// sprintf(pucTemp ,_T("%s"),str);
// const char *c_pcUtf8=(LPSTR)(LPCTSTR)str; //强制类型转换将CString转换成char*
// pucTp=(unsigned char*)str.GetBuffer(str.GetAllocLength());
/* int tmp_len = str.GetLength();
char *tmp_str;
tmp_str= (tmp_len);
*/
// pucTp= (unsigned char*)(LPCTSTR)str;
// char *tmp_pucTp=(char *) malloc(1024);
// wchar_t *pwhello = str.GetBuffer(str.GetLength());
// MyWideChar_tToMultiByte(str.GetBuffer(0), tmp_pucTp, sizeof(tmp_pucTp));
// wcstombs(tmp_pucTp,pwhello,1024);
wchar_t *origString = str.GetBuffer(str.GetLength());
char CharString[100]={0};
setlocale(LC_ALL,""); //设置语言环境
wcstombs(CharString,origString,100); //将宽字符转换成多字符
setlocale(LC_ALL,"C"); //设置语言环境"C"
pucTp=(unsigned char*)CharString;
// pucTp=(unsigned char*)str.GetBuffer(str.GetLength());
iRet=MyAHex((unsigned char *)pucTp,ucaTemp,strlen( (char*)pucTp)); //转换编码
str_normalize_init(); //字符初始化
const char *c_pcUtf8=(const char*)pucTp;
uiUtf8_len=strlen((const char*)pucTp)/2;
uiGbk_len=uiUtf8_len*2 +1;
char *pcGbk_buffer =(char *)malloc(uiGbk_len);
iRet=utf8_to_gbk((char *)ucaTemp,3, &pcGbk_buffer ,&uiGbk_len);
// iRet=utf8_to_gbk("我",uiUtf8_len, &pcGbk_buffer ,&uiGbk_len);
/*弹出返回值
char *piRet;
sprintf(piRet,"%s",(char)iRet);
CString ret(piRet);
MessageBox(ret,_T("函数返回值"),MB_OK);
*/
if(iRet == 0)
{
// str.Format("%s",pcGbk_buffer); //将char*转化成CString
CString str(pcGbk_buffer); //将char*转化成CString
if(str == "")
{
CString s("警告【表情】");
MessageBox(s,_T("转换输入内容出错"),MB_ICONEXCLAMATION);
// AfxMessageBox("Are you sure?",MB_YESNO|MB_ICONQUESTION);
return;
}
// MessageBox(str,_T("转换结果"),MB_OK);
SetDlgItemText(IDC_EDIT2, str); //显示到IEC_EDIT2控件
}
else
{
char *pcEr="fail";
CString fail(pcEr);
MessageBox(fail,_T("转换失败"),MB_OK);
SetDlgItemText(IDC_EDIT2, fail); //显示到IEC_EDIT2控件
return;
}
str.ReleaseBuffer();
free(pcGbk_buffer);
//return;
}