在线时间212 小时
UID3524997
ST金币0
蝴蝶豆68
注册时间2018-12-3
金牌会员
- 最后登录
- 2020-7-29
|
楼主 |
发表于 2020-2-6 11:34:31
|
显示全部楼层
a0a.1 32b0c
// PDUuniCodeDlg.cpp : implementation file
#include "stdafx.h"
#include "DUuniCode.h"
#include "DUuniCodeDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
CPDUuniCodeDlg::CPDUuniCodeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPDUuniCodeDlg::IDD, pParent){
//{{AFX_DATA_INIT(CPDUuniCodeDlg)
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPDUuniCodeDlg:oDataExchange(CDataExchange* pDX){
CDialog:oDataExchange(pDX);
//{{AFX_DATA_MAP(CPDUuniCodeDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPDUuniCodeDlg, CDialog)
//{{AFX_MSG_MAP(CPDUuniCodeDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_CHK_PDU, OnChkPdu)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
BOOL CPDUuniCodeDlg::OnInitDialog(){
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
SetDlgItemText(IDE_UNICODE,"514D8D3951714EAB");
SetDlgItemText(IDE_MSG_CENTER, "+8613800553500");
SetDlgItemText(IDE_MSG_RECIEVER,"+8613866362895");
return TRUE; // return TRUE unless you set the focus to a control
}
void CPDUuniCodeDlg::OnPaint() {
if (IsIconic()) {
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
} else { CDialog::OnPaint(); }
}
HCURSOR CPDUuniCodeDlg::OnQueryDragIcon(){ return (HCURSOR) m_hIcon; }
// ﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
#define ZGYD_MSGCODE "+8613800553500" //短信中心号码:上海移动:+8613800210500;上海联通:+8613010314500;
#define CARD_SIMCODE "+8615212252203" // 北京移动:+8613800100500;北京联通:+8613010112500;
#define Recieve_CODE "+8613866362895"
#define InterNationT "91" //国际化
#define TxMsgUniCode "77ED4FE15E7353F00050004400556A215F0F4F7F75280055006E00690063006F006400657F167801"
//无论中文2国际还是国际2中文,对应的函数都需要调用2次,如:第一次得到大小;第二次真正转换(末尾参数变化)
//
// int iSize= WideCharToMultiByte(CP_ACP,0,TxUniCode,-1,NULL,0,NULL,NULL);↓AfxMessageBox(MultiByte);
// WideCharToMultiByte(CP_ACP,0,TxUniCode,-1,MultiByte,iSize+1,NULL,NULL); MultiByte[iSize+1]='\0';
char MultiByte[256]={0}; //您好(60A8,597D)再见!(518D89C1,0021) //"短信平台PDU模式使用Unicode编码";
WCHAR TxUniCode[]={0x77ed,0x4fe1,0x5e73,0x53f0};
char str[256], strPDU[256]; //11000D91,683168362698F5,000800,0A5DE54F5C987A5229FF01;工作顺利
//--------------------------- 中文转UNICODE -----------------------------------
//调用方法: char multiByte[32]={0};
// ::GetDlgItemText(m_hWnd,IDE_MULTIBYTE,multiByte,sizeof(multiByte));
// strChinese2UniCode(multiByte);
// SetDlgItemText(IDE_UNICODE,str); // 两个EDIT控件和1个按钮实现这4行
//.............................................................................
char* CPDUuniCodeDlg::strChinese2UniCode(char strZW[128]){ // 输入中文字符串
char stm[4]; DWORD i; //char strTmp[128]=_T(""); //CP_ACP,CP_UTF8,
DWORD iSize = MultiByteToWideChar(CP_ACP,0,strZW,-1,NULL,0);//-1:整个串长
WCHAR* GJuniCode=new wchar_t[iSize+1];
memset(GJuniCode,0,iSize*2+2);
int nRet = MultiByteToWideChar(CP_ACP,0,strZW,-1,GJuniCode,iSize+1);
if (nRet<0) return "BadFace"; else{ GJuniCode[iSize]='\0'; strcpy(str,"");
for (i=0;i<(iSize-1);i++){ sprintf(stm,"%X",*(WCHAR*)(GJuniCode+i));
strcat(str,stm); }}//strcat(strTmp,stm); //827E,548C,8363<=>艾和荣
delete [] GJuniCode; return str; //return strTmp; ←为何出错????
}//----------------------------------------------------------20190827----------
//2019-08-28 去年父亲
//--------------------------- UNICODE转中文 -----------------------------------
//调用方法:
//char strU[]={"5171515A501F520067404EBA4E4B9634973E85CF4E8E72364EB288AB6BB4"};
// //::GetDlgItemText(m_hWnd,IDE_UNICODE,strU,sizeof(strU));
// strUniCode2Chinese(strU); SetDlgItemText(IDE_MULTIBYTE,str);
//.............................................................................
char* CPDUuniCodeDlg::strUniCode2Chinese(char strGJ[128]){ // 输入16进制国际码
WCHAR* uniGJ=new wchar_t[128]; memset(uniGJ,0,256); char ich;
char strANSI[64]=_T(""); unsigned short iTmp; int len,i,Siz;
Siz=strlen(strGJ);
for(len=0;len<Siz;len+=4){ iTmp=0;
for(i=0;i<4;i++){ ich=strGJ[len+i];
if(ich >0x40 ) ich-=0x37; else ich-=0x30;
switch(i){ case 3: iTmp+=ich ; break;
case 2: iTmp+=ich* 16; break;
case 1: iTmp+=ich* 256; break;
case 0: iTmp+=ich*4096; break;
}//if (((ich>0x40)&&(ich<0x47))||((ich>0x2F)&&(ich<0x3A)))
} wcscat(uniGJ,(const unsigned short *)&iTmp);
} *(WCHAR*)(uniGJ+len-1)='\0'; //语法:wcscat(uniCode,LPCWSTR(str));
int need=WideCharToMultiByte(CP_ACP,0,uniGJ,-1, NULL , 0 ,NULL,NULL);
if (need<0) return "BadFace"; else {
len= WideCharToMultiByte(CP_ACP,0,uniGJ,-1,strANSI,need+1,NULL,NULL);
strANSI[need]='\0';}
strcpy(str,strANSI); return str;
}//----------------------------------------------------------20190827----------
//=============================================================================
//工程->设置->C/C++->预处理程序定义:将"_MBCS"改成"-UNICODE" 20190826
char* CPDUuniCodeDlg::codeFMTtoPDU(char *TelNum, int ZGYD){
int i,len; char j; char code[32]="+8613800100500", ps[8]=InterNationT;
strcpy(code,TelNum);
if (strstr(code,"+")){ len = strlen(code); for (i=0;i<len;i++){ j=code[i+1];code[i]=j;}; len--;}
if (len%2) { strcat(code,"F"); }
for (i=0;i<(len+1);i+=2){ j=code[i+1];code[i+1]=code[i];code[i]=j; }
sprintf(str,"%s%s",ps,code); strcpy(code,str);
if (ZGYD==1){ len = strlen(str)/2; sprintf(str,"%02X%s", len,code); }
else { strcpy(ps,"1100"); strcpy(code,str); sprintf(str,"%s%02X%s",ps,len,code); }
return str;
}
char* CPDUuniCodeDlg::msgTXcvPDU(char *contxt){ //to finished !
int len; char text[128]="Hello World!"; strcpy(text,contxt);
len = strlen(text); sprintf(str,"%02X%s",len/2,text);
return str;
}
int CPDUuniCodeDlg::numTXmsgPDU(){
char tmp[256]="", eXchange[256]=""; int lenMix=0; char *ss1,*ss2;
::GetDlgItemText(m_hWnd,IDE_MSG_RECIEVER, tmp,sizeof(tmp)); //strcpy(tmp,Recieve_CODE);
ss1 = codeFMTtoPDU(tmp,0); strcpy(strPDU,ss1); strcat(strPDU,"000800");
::GetDlgItemText(m_hWnd,IDE_UNICODE, tmp,sizeof(tmp)); //strcpy(tmp,TxMsgUniCode);
if (strlen(tmp)<4) { AfxMessageBox("Input Chinese Message First!"); return 0;}
ss2 = msgTXcvPDU(tmp); strcat(strPDU,ss2); lenMix=strlen(strPDU)/2;
::GetDlgItemText(m_hWnd,IDE_MSG_CENTER,tmp,sizeof(tmp)); //strcpy(tmp,ZGYD_MSGCODE);
strcpy(eXchange,strPDU);
strcpy(strPDU, codeFMTtoPDU(tmp,1)); strcat(strPDU,eXchange); strcat(strPDU,"Z");
*(int*)(strPDU+strlen(strPDU)-1)=0x1A;
// if(((char) *(int*)(strPDU+strlen(strPDU)-1) )==0x1A) AfxMessageBox(_T("Tail is ^Z !"));
return lenMix;
}
//-----------------------------------------------------------------------------------------------------
void CPDUuniCodeDlg::OnChkPdu() {
if (IsDlgButtonChecked(IDC_CHK_PDU) != 0) SetDlgItemText(IDC_BUTTON2,"生成完整编码");
}
void CPDUuniCodeDlg::OnButton1() { //To China
char strU[]={"5171515A501F520067404EBA4E4B9634973E85CF4E8E72364EB288AB6BB4"};
::GetDlgItemText(m_hWnd,IDE_UNICODE,strU,sizeof(strU));
strUniCode2Chinese(strU); SetDlgItemText(IDE_MULTIBYTE,str);
}
void CPDUuniCodeDlg::OnButton2() { //To International
char multiByte[64]={0}; int nc;
::SetDlgItemText(m_hWnd,IDE_UNICODE,_T("")); //清空
::GetDlgItemText(m_hWnd,IDE_MULTIBYTE,multiByte,sizeof(multiByte)); //读输入的汉字
strChinese2UniCode(multiByte);
::SetDlgItemText(m_hWnd,IDE_UNICODE,str);
if (IsDlgButtonChecked(IDC_CHK_PDU) != 0) { nc = numTXmsgPDU();
sprintf(multiByte,"%d",nc); SetDlgItemText(IDE_LEN_PDU,multiByte);
::SetDlgItemText(m_hWnd,IDE_UNICODE,strPDU);
}
} |
|