📄 demodlg.cpp
字号:
return FALSE;
}
memset ((char*)szTemp, 0, 20);
iTempSize = 20;
SendData[iDataIndex++] = (BYTE)dwData;
dwData = 0;
if (iDataIndex >= iSize)
{
iRet = 0;
break;
};
};
if (iRet == 1)
{
CString str;
str = "Data error.";
AfxMessageBox(str);
return FALSE;
};
CString str, s;
for (int i = 0 ; i < iDataIndex; i++)
{
s.Format("%x ", SendData[i]);
str += s;
};
AfxMessageBox(str);
iSize = iDataIndex;
return TRUE;
}
int GetValidString(LPCTSTR pOrgStr, int& iNextPos, char * ResultBuf, int& iBufSize)
{
int i = iNextPos;
while ((pOrgStr[i]) && ((pOrgStr[i]==' ') || (pOrgStr[i]==0x0a)
|| (pOrgStr[i]==0x0d) || (pOrgStr[i]=='\t')))
i++;
if (!pOrgStr[i])
{
iBufSize = 0;
return 2; //结束
};
int j=0;
while ((pOrgStr[i]) && (iBufSize-1 > j) && (pOrgStr[i]!=' ')
&& (pOrgStr[i]!=0x0a) && (pOrgStr[i]!=0x0d) && (pOrgStr[i]!='\t'))
{
ResultBuf[j] = pOrgStr[i];
j++;
i++;
};
ResultBuf[j] = 0;
iNextPos = i;
iBufSize = j+1;
if ((pOrgStr[i] == 0) || (pOrgStr[i]==' ') || (pOrgStr[i]==0x0a)
||(pOrgStr[i]==0x0d) || (pOrgStr[i]=='\t'))
return 0; //成功
else
return 1; //非法值
}
void CDemoDlg::OnQueryDetailEx()
{
UpdateData(TRUE);
unsigned char OrgTON=0, OrgNPI=0;
char OrgAddr[MAX_ADDR_LEN];
unsigned char DestTON=0, DestNPI=0;
char DestAddr[MAX_ADDR_LEN];
unsigned char PRI, DCS, UDHI, PID;
char Schedule[MAX_TIMESTAMP_LEN];
char Expire[MAX_TIMESTAMP_LEN];
char Final[MAX_TIMESTAMP_LEN];
unsigned char SM_Status;
unsigned char Error_Code;
char* UserData = NULL;
if (m_len > 0) UserData = new char[m_len];
if (UserData == NULL) return;
int iRet;
CString str;
iRet = QuerySMDetailEx(m_sm_id, &OrgTON, &OrgNPI, OrgAddr, &DestTON, &DestNPI, DestAddr,
&PRI, NULL, NULL, &UDHI, NULL, NULL, &PID, &DCS, Schedule, Expire, Final, &SM_Status, &Error_Code, (unsigned long*)(&m_len), UserData);
if (iRet != E_SUCCESS)
{
char errstr[200];
if (GetErrorString(iRet, 200, errstr) > 0)
AfxMessageBox(errstr);
if (UserData != NULL) delete UserData;
return;
};
m_destaddr.Format("%s",DestAddr);
m_orgaddr.Format("%s",OrgAddr);
m_destaddr.Format("%s",DestAddr);
m_PRI=PRI;
m_DCS.Format("%d", DCS);
m_pid = PID;
m_UDHI = UDHI;
if (m_UDHI == 1)
{
char* pUDstr = new char[(m_len+1)*3];
if (!pUDstr)
{
if (UserData != NULL) delete UserData;
return;
}
ConvertBinaryToString((unsigned char*)UserData, m_len, pUDstr, (m_len+1)*3);
m_userdata.Format("%s", pUDstr);
delete pUDstr;
m_Binary = TRUE;
}
else
m_userdata.Format("%s", UserData);
/*switch(DCS)
{
case SM_DCS_ASC:
m_DCS=0;
break;
case SM_DCS_CHINA:
m_DCS=1;
break;
case 0:
m_DCS=2;
break;
default:
ASSERT(false);
if (UserData != NULL) delete UserData;
return;
};*/
m_schedule.Format("%s", Schedule);
m_expire.Format("%s",Expire);
m_final.Format("%s", Final);
char sStatusStr[255];
GetSMStatusString(SM_Status, 255, sStatusStr);
m_status.Format("%d %s", SM_Status, sStatusStr);
/*
switch(SM_Status)
{
case WAITING_FOR_DELIVER:
m_status.Format("%s", "WAITING_FOR_DELIVER");
break;
case DELIVER_SUCCESS:
m_status.Format("%s", "DELIVER_SUCCESS");
break;
case DELIVER_FAIL:
m_status.Format("%s", "DELIVER_FAIL");
break;
case SM_RES_WAIT_DELIVER_FOR_ERROR:
m_status.Format("%s", "因提交失败而等待");
break;
case SM_RES_WAIT_DELIVER_FOR_NORMAL:
m_status.Format("%s", "因定时短讯而等待");
break;
case SM_RES_WORK:
m_status.Format("%s", "工作态");
break;
case SM_RES_WAIT_ALERT:
m_status.Format("%s", "等待ALERT");
break;
default:
m_status.Format("未知状态:%d", SM_Status);
case 0:
m_status.Format("0 %s", "WAITING_FOR_DELIVER");
break;
case 1:
m_status.Format("1 %s", "DELIVER_SUCCESS");
break;
case 2:
m_status.Format("2 %s", "DELIVER_FAIL");
break;
default:
m_status.Format("%d", SM_Status);
};
switch(Error_Code)
{
case 0:
m_error_code.Format("0 %s","SM_STATUS_NO_ERR");
break;
case 1:
m_error_code.Format("1 %s","SM_STATUS_ERR_OTHER");
break;
default:
m_error_code.Format("%d", Error_Code);
};
*/
m_error_code.Format("%d", Error_Code);
UpdateData(FALSE);
AfxMessageBox("Query SM Details SUCCESS!");
if (UserData != NULL) delete UserData;
}
BOOL ConvertBinaryToString(BYTE* pData, unsigned long ulDataLen,
char* pString, unsigned long ulStrLen)
{
ASSERT(pData);
ASSERT(pString);
if (!pData)
return FALSE;
if (!pString)
return FALSE;
if (ulDataLen > 0x4ffff)
return FALSE;
int iLineNum = 0, iDataCount = 0;
int iStringCount = 0;
char tmpStr[20];
while ((iDataCount < (int)ulDataLen) && (iStringCount < (int)ulStrLen-3))
{
sprintf(tmpStr, "%02x ", (BYTE)pData[iDataCount]);
strncpy(pString + iStringCount, tmpStr, 3);
iLineNum++;
iDataCount++;
iStringCount += 3;
if (iLineNum == 8)
{
iLineNum = 0;
if (iStringCount < (int)ulStrLen - 2 )
{
pString[iStringCount] = 0x0d;
pString[iStringCount+1] = 0x0a;
iStringCount+=2;
}
}
}
pString[iStringCount-1] = 0;
return TRUE;
}
void CDemoDlg::OnReplaceSMEx()
{
UpdateData(TRUE);
unsigned char DCS = (unsigned char)atol(m_DCS);
int size = m_userdata.GetLength();
char * ud = NULL;
ud = new char[size+1];
memset(ud, 0, size+1);
if (ud == NULL)
return;
DWORD UDLen = size;
if ((m_UDHI == 1) && m_Binary)
{
AnalysisString(m_userdata, (unsigned char*)ud, size);
UDLen = size;
}
else
strcpy(ud, m_userdata);
int iRet = ReplaceSMEx(
m_sm_id,
1,
1,
m_orgaddr,
m_schedule,
m_expire,
0,
DCS,
m_UDHI,
m_default_id,
UDLen,
ud
);
char errstr[200];
if (GetErrorString(iRet, 200, errstr) > 0)
AfxMessageBox(errstr);
delete ud;
}
//by ycl 2001.2.15
void CDemoDlg::OnExitInterface()
{
// TODO: Add your control notification handler code here
if (!IFExitInterface())
::MessageBox(NULL, "exit failed.", "",MB_OK|MB_ICONINFORMATION);
else
{
::MessageBox(NULL, "exit success.", "",MB_OK|MB_ICONINFORMATION);
};
}
void CDemoDlg::OnLoadCmppConfig()
{
// TODO: Add your control notification handler code here
CCmppDlg CmppDlg;
int nResponse = CmppDlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
}
void CDemoDlg::OnCmppSubmitSM()
{
// TODO: Add your control notification handler code here
}
void CDemoDlg::OnCmppQuery()
{
// TODO: Add your control notification handler code here
char sBeginTime[8+1];
char sServiceID[10+1];
UpdateData(true);
memset(sBeginTime, 0, 8+1);
memset(sServiceID, 0, 10+1);
memcpy(sBeginTime, m_begintime, 8);
memcpy(sServiceID, m_sServiceType, 10);
UpdateData(false);
//init
m_nMTTLMsg = 0;
m_nMTTLusr = 0;
m_nMTScs = 0;
m_nMTWT = 0;
m_nMTFL = 0;
m_nMOScs = 0;
m_nMOWT = 0;
m_nMOFL = 0;
int iRet = 0;
if(sServiceID[0] == NULL)
iRet = QueryCmppStatus(sBeginTime, sServiceID, 0, \
m_nMTTLMsg,m_nMTTLusr,m_nMTScs,\
m_nMTWT,m_nMTFL,\
m_nMOScs,m_nMOWT,m_nMOFL);
else
iRet = QueryCmppStatus(sBeginTime, sServiceID, 1, \
m_nMTTLMsg,m_nMTTLusr,m_nMTScs,\
m_nMTWT,m_nMTFL,\
m_nMOScs,m_nMOWT,m_nMOFL);
if(iRet != 0)
{
AfxMessageBox("查询超时!");
return;
}
// 2002.01.05 hyt delete
/*
CCmppStatusDlg dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
*/
}
void CDemoDlg::OnCmppCancel()
{
// TODO: Add your control notification handler code here
unsigned char byMsgID[8];
memset(byMsgID, 0, 8);
UpdateData(true);
BYTE sTmp[16];
for(int i = 0; i < 16; i++)
{
switch(m_sMsgID[i])
{
case 'a':
case 'A':
sTmp[i] = 10;
break;
case 'b':
case 'B':
sTmp[i] = 11;
break;
case 'c':
case 'C':
sTmp[i] = 12;
break;
case 'd':
case 'D':
sTmp[i] = 13;
break;
case 'e':
case 'E':
sTmp[i] = 14;
break;
case 'f':
case 'F':
sTmp[i] = 15;
break;
default:
sTmp[i] = m_sMsgID[i] - '0';
break;
}
}
byMsgID[0] = sTmp[0]* 0x10 + sTmp[1];
byMsgID[1] = sTmp[2]* 0x10 + sTmp[3];
byMsgID[2] = sTmp[4]* 0x10 + sTmp[5];
byMsgID[3] = sTmp[6]* 0x10 + sTmp[7];
byMsgID[4] = sTmp[8]* 0x10 + sTmp[9];
byMsgID[5] = sTmp[10]* 0x10 + sTmp[11];
byMsgID[6] = sTmp[12]* 0x10 + sTmp[13];
byMsgID[7] = sTmp[14]* 0x10 + sTmp[15];
UpdateData(false);
BYTE byRet = 1;
CancelCmppSM((char*)byMsgID, &byRet);
if(byRet == 0)
AfxMessageBox("删除成功!");
else
AfxMessageBox("删除失败!");
}
void CDemoDlg::OnContextMenu(CWnd*, CPoint point)
{
// CG: This block was added by the Pop-up Menu component
{
if (point.x == -1 && point.y == -1){
//keystroke invocation
CRect rect;
GetClientRect(rect);
ClientToScreen(rect);
point = rect.TopLeft();
point.Offset(5, 5);
}
CMenu menu;
VERIFY(menu.LoadMenu(CG_IDR_POPUP_DEMO_DLG));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this;
while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
pWndPopupOwner);
}
}
void CDemoDlg::OnClear()
{
m_DlvSMNum = "0";
m_ulSmNum = 0;
UpdateData(FALSE);
}
void CDemoDlg::OnChecksmnum()
{
UpdateData(TRUE);
if (m_bSmNumFlag)
{
m_DlvSMNum.Format("%d", m_ulSmNum);
UpdateData(FALSE);
}
}
void CDemoDlg::OnMENUITEMAbout()
{
CAboutDlg AboutDlg;
AboutDlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -