📄 msgdetailview.cpp
字号:
// MsgDetailView.cpp : implementation of the CMsgDetailView class
//
#include "stdafx.h"
#include "MsgDetail.h"
#include "MsgDetailDoc.h"
#include "MsgDetailView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMsgDetailView
void SwipBytes(unsigned char* msg,int off,int count)
{
byte b;
for(int i=0;i<count;i+=2)
{
b=msg[off+i];
msg[off+i]=msg[off+i+1];
msg[off+i+1]=b;
}
}
bool GetCharsFromUnicode(char* msg,unsigned char *buffer,int count)
{
SwipBytes(buffer,0,count);
int len=WideCharToMultiByte(CP_ACP,0,(unsigned short *)buffer,count/2,msg,299,NULL,NULL);
if(len==0)
{
DWORD code=GetLastError();
CString str;
if(code==ERROR_INSUFFICIENT_BUFFER)
{
str="ERROR_INSUFFICIENT_BUFFER";
}
else if(code==ERROR_INVALID_FLAGS)
{
str="ERROR_INVALID_FLAGS";
}
else if(code==ERROR_INVALID_PARAMETER)
{
str="ERROR_INVALID_PARAMETER";
}
return false;
}
msg[len]=0;
return true;
}
IMPLEMENT_DYNCREATE(CMsgDetailView, CFormView)
BEGIN_MESSAGE_MAP(CMsgDetailView, CFormView)
//{{AFX_MSG_MAP(CMsgDetailView)
ON_NOTIFY(NM_DBLCLK, IDC_MSG_LIST, OnDblclkMsgList)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_REMOVEALL, OnRemoveall)
ON_BN_CLICKED(IDC_SMS, OnSms)
ON_BN_CLICKED(IDC_BUTTON_PAGEUP, OnButtonPageup)
ON_BN_CLICKED(IDC_BUTTON_PAGEDOWN, OnButtonPagedown)
ON_BN_CLICKED(IDC_BUTTON_PAGE_START, OnButtonPageStart)
ON_BN_CLICKED(IDC_BUTTON_PAGE_END, OnButtonPageEnd)
ON_BN_CLICKED(IDC_BUTTON_JUMP, OnButtonJump)
ON_BN_CLICKED(IDC_BUTTON1, OnOK)
ON_NOTIFY(NM_DBLCLK, IDC_LIST_CDR, OnDblclkListCdr)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMsgDetailView construction/destruction
CMsgDetailView::CMsgDetailView()
: CFormView(CMsgDetailView::IDD)
{
//{{AFX_DATA_INIT(CMsgDetailView)
nPageJump = 0;
strPageInfo = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
haveMsgHead=false;
firstRun=true;
MsgCountPerPage=100;
npage=0;
}
CMsgDetailView::~CMsgDetailView()
{
}
void CMsgDetailView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMsgDetailView)
DDX_Control(pDX, IDC_LIST_CDR, cdrListc);
DDX_Control(pDX, IDC_BINARY, binaryc);
DDX_Control(pDX, IDC_MSG_LIST, listc);
DDX_Control(pDX, IDC_MSG_DETAIL, msgdetailc);
DDX_Control(pDX, IDC_MSG, msgc);
DDX_Text(pDX, IDC_EDIT_JUMP, nPageJump);
DDX_Text(pDX, IDC_EDIT_PAGE_INFO, strPageInfo);
//}}AFX_DATA_MAP
}
BOOL CMsgDetailView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CMsgDetailView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
if(firstRun)
{
firstRun=false;
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
DWORD j=listc.GetExtendedStyle()| LVS_EX_HEADERDRAGDROP |LVS_EX_TWOCLICKACTIVATE|LVS_EX_FULLROWSELECT;
listc.SetExtendedStyle(j);
cdrListc.SetExtendedStyle(j);
#define COLCOUNT 11
int nWidth[COLCOUNT]={50,40,10,50,50,60,60,45,100,340,150};
CString strColumn[COLCOUNT]={"索引","链路","时间","后向","前向","DPC","OPC","CIC","消息类型","号码","原因"};
BuildColumns(COLCOUNT,nWidth,strColumn);
CButton *pbuttion=(CButton *)this->GetDlgItem(IDC_RADIO2);
pbuttion->SetCheck(1);
GetDocument()->BusySysMsgList.BuildColumns(cdrListc);
}
npage=0;
UpdateCDRList();
orderby=1;
UpdateList();
}
/////////////////////////////////////////////////////////////////////////////
// CMsgDetailView printing
BOOL CMsgDetailView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMsgDetailView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMsgDetailView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CMsgDetailView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CMsgDetailView diagnostics
#ifdef _DEBUG
void CMsgDetailView::AssertValid() const
{
CFormView::AssertValid();
}
void CMsgDetailView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CMsgDetailDoc* CMsgDetailView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMsgDetailDoc)));
return (CMsgDetailDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMsgDetailView message handle
#include "show.h"
void CMsgDetailView::OnOK()
{
CMsgText msgtext;
unsigned char buffer[]={
00,00,0x5f,0x00,0x01,0x00,0x01,0x00,0x01,0x01,
0xec,0x89,0x3f,0x85,0x73,0xff,0x0d,0x74,0xff,0x0d,0x08,
0x58,0x00,0x01,0x00,0x20,0x01,0x0a,0x00,0x02,0x08,
0x06,0x03,0x90,0x99,0x09,0x00,0x10,0x0a,0x08,0x03,
0x13,0x31,0x77,0x47,0x19,0x29,0xf4,0x28,0x08,0x83,
0x14,0x31,0x06,0x85,0x01,0x71,0x04,0x3f,0x05,0x83,
0x97,0x68,0x75,0x01,0x13,0x02,0x06,0x31,0x0b,0x08,
0x83,0x14,0x31,0x06,0x85,0x01,0x71,0x04,0x3d,0x01,
0x1f,0x03,0x04,0x7d,0x02,0x91,0x81,0x1d,0x03,0x80,
0x90,0xa3,0x39,0x05,0x3f,0x40,0x80,0x3d,0xc0,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
if(haveMsgHead)
{
}
else
{
}
int off=(haveMsgHead)?2:10;
CString str;
CString mgsstr;
msgc.GetWindowText(mgsstr);
int msglen=0;
while(SplitMsgStr(mgsstr,str))
{
if(!ChangeStringToBinary(&buffer[off],sizeof(buffer)-off,str,msglen))
{
AfxMessageBox("格式有错!");
return;
}
msglen+=6;
buffer[2]=msglen%256;
buffer[3]=msglen/256;
if(!GetDocument()->msgList.Add(&buffer[2]))
{
AfxMessageBox("格式有错!");
return;
}
int index=GetDocument()->msgList.GetCount()-1;
CString strs[11];
GetDocument()->msgList.GetMsgStr(strs,index);
listc.InsertItem(index,strs[0],0);
for(int j=1;j<11;j++)
{
listc.SetItemText(index, j, strs[j]);
}
}
listc.UpdateWindow();
msgtext.DetailText(&buffer[2]);
str=msgtext.GetLengthText();
msgdetailc.SetWindowText(str);
}
int GetCharValue(char c)
{
int v=-1;
if(c>='0'&&c<='9')
{
v=c-'0';
}
else if(c>='a'&&c<='f')
{
v=c-'a'+10;
}
else if(c>='A'&&c<='F')
{
v=c-'A'+10;
}
return v;
}
bool IsBinaryString(CString str)
{
int n=str.GetLength();
for(int i=0;i<n;i++)
{
if(GetCharValue(str[i])<0&&!(str[i]==','||str[i]=='x'||str[i]==' '))
{
return false;
}
}
return true;
}
bool CMsgDetailView::SplitMsgStr(CString &msgstr,CString &str)
{
str="";
if(msgstr.GetLength()<10)return false;
CString ts;
bool bErrorLine=false;
while(msgstr.GetLength()>0)
{
int n=msgstr.Find("\r");
if(n<0)
{
n=msgstr.Find("\r");
}
if(n<0)
{
if(IsBinaryString(msgstr))str+=msgstr;
msgstr="";
break;
}
ts=msgstr.Left(n);
if(IsBinaryString(ts))
{
if(bErrorLine)
{
break;
}
str+=ts;
}
else
{
if(str!="")bErrorLine=true;
}
msgstr=msgstr.Right(msgstr.GetLength()-n-2);
}
return (str.GetLength()>10);
}
bool CMsgDetailView::ChangeStringToBinary(unsigned char *buf,int buflen,CString str,int& msglen)
{
str.Replace(" ","");
str.Replace(",","");
str.Replace("0x","");
int pos=0,i=0,errorcount=0,len=str.GetLength();
int vh=0,vl=0;
while(i<len-1&&pos<buflen)
{
if(str[i]=='\r'&&str[i+1]=='\n')
{
i+=2;
continue;
}
vh=GetCharValue(str[i]);
vl=GetCharValue(str[i+1]);
if(vh<0||vl<0)
{
return false;
}
buf[pos++]=vh*16+vl;
i+=2;
}
buf[pos++]=0x0a;//消息结束标志
msglen=pos;
return true;
}
void CMsgDetailView::OnDblclkMsgList(NMHDR* pNMHDRi, LRESULT* pResult)
{
int item=listc.GetHotItem();
if(item>=0)
{
CString str=listc.GetItemText(item, 0);
item=atoi(str);
UpdateDetailMsg(item);
}
*pResult = 0;
}
void CMsgDetailView::UpdateDetailMsg(int index)
{
CMsgText msgItem;
BYTE* pBuf;
pBuf=GetDocument()->msgList.GetMsgBufFromIndex(index);
WORD len=*((WORD*)pBuf)-2-1;
msgItem.DetailText(pBuf);
//if(msgItem.strList.GetCount()<=0)return ;
CString str,strText;
for(int i=8;i<len;i++)
{
if((i-8)%16==0)
{
str.Format("\r\n %06x ",i-8);
strText+=str;
}
str.Format("%02X ",pBuf[i]);
strText+=str;
if((i-8)%8==7)
{
strText+=" ";
}
}
binaryc.SetWindowText(strText);
msgc.SetWindowText(GetDocument()->msgList.GetMsgStr(index));
msgdetailc.SetWindowText(msgItem.GetLengthText());
}
void CMsgDetailView::BuildColumns(int nCols, int * nWidth, CString * strCol)
{
//insert columns
int i;
LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
CString strTemp;
for(i = 0; i < nCols; i++)
{
lvc.iSubItem = i;
strTemp=strCol[i];
lvc.pszText = (char*)(LPCTSTR)strTemp;
lvc.cx = nWidth[i];
lvc.fmt = LVCFMT_LEFT;
listc.InsertColumn(i,&lvc);
}
}
void CMsgDetailView::OnRadio1()
{
haveMsgHead=true;
}
void CMsgDetailView::OnRadio2()
{
haveMsgHead=false;
}
void CMsgDetailView::OnDelete()
{
msgc.SetWindowText("");
msgdetailc.SetWindowText("");
binaryc.SetWindowText("");
POSITION pos=listc.GetFirstSelectedItemPosition();
if(pos)
{
int item=listc.GetNextSelectedItem(pos);
if(item>=0)
{
CString str=listc.GetItemText(item, 0);
item=atoi(str);
GetDocument()->msgList.DeleteItemFromIndex(item);
UpdateList();
listc.SetHotItem(item);
listc.SetSelectionMark(item);
}
}
}
void CMsgDetailView::OnRemoveall()
{
GetDocument()->msgList.DeleteAllItem();
listc.DeleteAllItems();
msgc.SetWindowText("");
msgdetailc.SetWindowText("");
binaryc.SetWindowText("");
}
void CMsgDetailView::UpdateList()
{
int ncount=GetDocument()->msgList.GetCount();
CString strs[11];
listc.DeleteAllItems();
int start=npage*MsgCountPerPage;
int end=start+MsgCountPerPage;
if(end>ncount)end=ncount;
int line=0;
int nafter=(orderby==0)?0:100000;
for(int i=start;i<end;i++)
{
GetDocument()->msgList.GetMsgStr(strs,i);
line=listc.InsertItem(nafter,strs[0],0);
for(int j=1;j<11;j++)
{
listc.SetItemText(line, j, strs[j]);
}
line++;
}
strPageInfo.Format("%d/%d",npage,ncount/MsgCountPerPage);
UpdateData(FALSE);
}
void CMsgDetailView::OnSms()
{
unsigned char buffer[1000];
int off=0;
CString str;
CString mgsstr;
msgc.GetWindowText(mgsstr);
int msglen=0;
char msg[300];
if(SplitMsgStr(mgsstr,str))
{
if(!ChangeStringToBinary(&buffer[off],sizeof(buffer)-off,str,msglen))
{
AfxMessageBox("格式有错!");
return;
}
GetCharsFromUnicode(msg,buffer,msglen);
msgdetailc.SetWindowText(msg);
}
}
void CMsgDetailView::OnButtonPageup()
{
npage--;
if(npage<0)npage=0;
UpdateList();
}
void CMsgDetailView::OnButtonPagedown()
{
int ncount=GetDocument()->msgList.GetCount();
npage++;
if(npage>ncount/MsgCountPerPage)npage=ncount/MsgCountPerPage;
UpdateList();
}
void CMsgDetailView::OnButtonPageStart()
{
npage=0;
UpdateList();
}
void CMsgDetailView::OnButtonPageEnd()
{
int ncount=GetDocument()->msgList.GetCount();
npage=ncount/MsgCountPerPage;
UpdateList();
}
void CMsgDetailView::OnButtonJump()
{
UpdateData();
int ncount=GetDocument()->msgList.GetCount();
npage=nPageJump;
if(npage>ncount/MsgCountPerPage)npage=ncount/MsgCountPerPage;
if(npage<0)npage=0;
nPageJump=npage;
UpdateList();
return;
}
void CMsgDetailView::UpdateCDRList()
{
GetDocument()->BusySysMsgList.UpdateList(cdrListc);
}
void CMsgDetailView::OnDblclkListCdr(NMHDR* pNMHDR, LRESULT* pResult)
{
int item=cdrListc.GetHotItem();
if(item>=0)
{
CString str=cdrListc.GetItemText(item, 0);
if(str.Find('*')>=0)return;
int filepos1=atoi(str);
str=cdrListc.GetItemText(item, 3);
str=str.Left(8);
CString filePath;
filePath.Format("d:\\msg\\%s.dat",str.GetBuffer(0));
int item2=(item%3==0)?item+1:item-1;
str=cdrListc.GetItemText(item2, 0);
if(str.Find('*')>=0)return;
int filepos2=atoi(str);
if(item2>item)
{
UpdateCDRMsg(filepos2,filepos1,filePath);
}
else
{
UpdateCDRMsg(filepos1,filepos2,filePath);
}
}
*pResult = 0;
}
void CMsgDetailView::UpdateCDRMsg(UINT filepos1,UINT filepos2,CString filePath)
{
orderby=0;
npage=0;
GetDocument()->msgList.DeleteAllItem();
GetDocument()->BusySysMsgList.UpdateCDRMsg(filepos1,filePath,GetDocument()->msgList);
GetDocument()->BusySysMsgList.UpdateCDRMsg(filepos2,filePath,GetDocument()->msgList);
UpdateList();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -