📄 msgdemoview.cpp
字号:
// MsgDemoView.cpp : implementation of the CMsgDemoView class
//
#include "stdafx.h"
#include "MsgDemo.h"
#include "MsgDemoDoc.h"
#include "MsgDemoView.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMsgDemoView
IMPLEMENT_DYNCREATE(CMsgDemoView, CView)
BEGIN_MESSAGE_MAP(CMsgDemoView, CView)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CMsgDemoView)
ON_WM_SIZE()
ON_COMMAND(ID_REFRESH, OnRefresh)
ON_COMMAND(ID_ADD, OnAdd)
ON_COMMAND(ID_DELETE, OnDelete)
ON_COMMAND(ID_EDIT, OnEdit)
ON_WM_ERASEBKGND()
ON_NOTIFY(NM_DBLCLK, IDC_MSGLIST, OnDblclkMsgList)
ON_COMMAND(ID_SEND_MSG, OnSendMsg)
ON_COMMAND(ID_SEEK, OnSeek)
ON_COMMAND(ID_REMOVE_ALL, OnRemoveAll)
ON_COMMAND(ID_CONFIG_REAL, OnConfigReal)
ON_WM_TIMER()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMsgDemoView construction/destruction
CMsgDemoView::CMsgDemoView()
{
// TODO: add construction code here
bResetLoad=FALSE;
}
CMsgDemoView::~CMsgDemoView()
{
if(bResetLoad)
{
m_pConnection->Close();
m_pConnection.Release();
}
}
BOOL CMsgDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMsgDemoView drawing
void CMsgDemoView::OnDraw(CDC* pDC)
{
CMsgDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMsgDemoView printing
BOOL CMsgDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMsgDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMsgDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMsgDemoView diagnostics
#ifdef _DEBUG
void CMsgDemoView::AssertValid() const
{
CView::AssertValid();
}
void CMsgDemoView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMsgDemoDoc* CMsgDemoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMsgDemoDoc)));
return (CMsgDemoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMsgDemoView message handlers
void CMsgDemoView::OnInitialUpdate()
{
CView::OnInitialUpdate();
CRect rect;
GetClientRect(&rect);
//如果使用OWNERDRAW属性能够是用彩色LIST,但是没有鼠标移动的选中效果.
m_List.Create(WS_CHILD|WS_VISIBLE| LVS_REPORT/* | LVS_OWNERDRAWFIXED*/,rect,this,IDC_MSGLIST);
this->m_List.DeleteAllItems();
//设置list控件的文字和背景颜色
m_List.SetBkColor(RGB(255,255,255));
m_List.SetTextBkColor(RGB(255,255,255));
//清空list控件的数据
for(int delcolumn=100;delcolumn>=0;delcolumn--)
m_List.DeleteColumn(delcolumn);
//设置list对话框的列
DWORD dwStyle;
LV_COLUMN lvc;
dwStyle = m_List.GetStyle();
dwStyle |= LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT |LVS_SHOWSELALWAYS |LVS_EDITLABELS ;
m_List.SetExtendedStyle(dwStyle);
lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH |LVCF_FMT;
lvc.fmt=LVCFMT_LEFT;
lvc.iSubItem = 0;
lvc.pszText = _T("列队编号");
lvc.cx = rect.Width()/10;
m_List.InsertColumn(1,&lvc);
lvc.iSubItem = 1;
lvc.pszText = _T("信息内容");
lvc.cx = rect.Width()*3/10;
m_List.InsertColumn(2,&lvc);
lvc.iSubItem = 2;
lvc.pszText = _T("呼叫号码");
lvc.cx = rect.Width()/5;
m_List.InsertColumn(3,&lvc);
lvc.iSubItem = 3;
lvc.pszText = _T("发送级别");
lvc.cx = rect.Width()/10;
m_List.InsertColumn(4,&lvc);
lvc.iSubItem = 4;
lvc.pszText = _T("备注");
lvc.cx = rect.Width()*3/10;
m_List.InsertColumn(5,&lvc);
//添加LISTCTRL内容,同时读取INI内容
theApp.SetDlgSkin();
if(MessageBox("加载短信报警驱动信息,需要重新配置新的驱动文件吗?","提示信息",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
{
ConnectToDatabase();
bResetLoad=TRUE;
}
ReadIniFileVal();
theApp.SetMainFrmSkin();
m_MsgSend.InitDevice();
SetTimer(1,1000,NULL);
}
void CMsgDemoView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CRect rect;
GetClientRect(&rect);
if(m_List)
{
m_List.MoveWindow(&rect,TRUE);
m_List.SetColumnWidth(0,rect.Width()/10);
m_List.SetColumnWidth(1,rect.Width()*3/10);
m_List.SetColumnWidth(2,rect.Width()/5);
m_List.SetColumnWidth(3,rect.Width()/10);
m_List.SetColumnWidth(4,rect.Width()*3/10);
}
}
void CMsgDemoView::OnContextMenu(CWnd*, CPoint point)
{
CRect rect;
int iOption;
iOption = m_List.GetSelectedCount();
//得到当前选中的行
POSITION pos = m_List.GetFirstSelectedItemPosition();
//如果选中一行
m_List.GetClientRect(&rect);
if(rect.PtInRect(point)&&pos) // 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(IDR_POPMENU)); 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);
TrackSkinPopupMenu( pPopup->m_hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
pWndPopupOwner->m_hWnd ); }
}
void CMsgDemoView::OnRefresh()
{
// TODO: Add your command handler code here
m_List.UpdateWindow();
Invalidate();
}
void CMsgDemoView::OnAdd()
{
// TODO: Add your command handler code here
CAddMsgDlg dlg;
if(dlg.DoModal()==IDOK)
{
BOOL bExist=FALSE;
CString strId;
int nCount=m_List.GetItemCount();
for(int i=0;i<nCount;i++)
{
strId=m_List.GetItemText(i,0);
if(strId==dlg.m_Id)
{
bExist=TRUE;
break;
}
}
if(bExist)
::AfxMessageBox("编号为“"+dlg.m_Id+"”的列队编号已经存在!信息添加失败!");
else
{
m_List.InsertItem(nCount,dlg.m_Id);
m_List.SetItemText(nCount,1,dlg.m_Content);
m_List.SetItemText(nCount,2,dlg.m_Num);
m_List.SetItemText(nCount,3,dlg.m_bSend);
m_List.SetItemText(nCount,4,dlg.m_Des);
for(int i=0;i<500;i++)
{
if(m_strId[i+1].IsEmpty())
{
m_strId[i+1]=dlg.m_Id;
m_strContent[i+1]=dlg.m_Content;
m_strNum[i+1]=dlg.m_Num;
m_strbSend[i+1]=dlg.m_bSend;
m_strDes[i+1]=dlg.m_Des;
ResetIniFileVal();
break;
}
}
}
}
}
void CMsgDemoView::OnDelete()
{
// TODO: Add your command handler code here
int iOption;
CString strId,strContent;
iOption = m_List.GetSelectedCount();
//得到当前选中的行
POSITION pos = m_List.GetFirstSelectedItemPosition();
//如果选中一行
if(pos)
{
int nItem = m_List.GetNextSelectedItem(pos);
strId=m_List.GetItemText(nItem,0);
strContent=m_List.GetItemText(nItem,1);
if(MessageBox("确定要删除编号为“"+strId+"” 呼叫内容为“"+strContent+"” 的记录吗? ","询问信息",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
{
m_List.DeleteItem(nItem);
for(int i=0;i<500;i++)
{
if(m_strId[i+1]==strId)
{
m_strId[i+1].Empty();
m_strContent[i+1].Empty();
m_strNum[i+1].Empty();
m_strbSend[i+1].Empty();
m_strDes[i+1].Empty();
break;
}
}
ResetIniFileVal();
}
}
}
void CMsgDemoView::OnEdit()
{
// TODO: Add your command handler code here
int iOption;
CString strId,strNum,strbSend,strContent,strDes;
iOption = m_List.GetSelectedCount();
//得到当前选中的行
POSITION pos = m_List.GetFirstSelectedItemPosition();
//如果选中一行
if(pos)
{
int nItem = m_List.GetNextSelectedItem(pos);
strId=m_List.GetItemText(nItem,0);
strContent=m_List.GetItemText(nItem,1);
strNum=m_List.GetItemText(nItem,2);
strbSend=m_List.GetItemText(nItem,3);
strDes=m_List.GetItemText(nItem,4);
CEditMsgDlg dlg;
dlg.strId=strId;
dlg.strContent=strContent;
dlg.strNum=strNum;
dlg.strbSend=strbSend;
dlg.strDes=strDes;
if(dlg.DoModal()==IDOK)
{
BOOL bExist=FALSE,bItem=FALSE;
int nCount=m_List.GetItemCount();
CString szTempId;
for(int i=0;i<nCount;i++)
{
szTempId=m_List.GetItemText(i,0);
if(szTempId==dlg.m_Id)
{
bExist=TRUE;
if(nItem==i)//是自己本身
bItem=TRUE;
break;
}
}
if(bItem)
{
m_List.SetItemText(nItem,0,dlg.m_Id);
m_List.SetItemText(nItem,1,dlg.m_Content);
m_List.SetItemText(nItem,2,dlg.m_Num);
m_List.SetItemText(nItem,3,dlg.m_bSend);
m_List.SetItemText(nItem,4,dlg.m_Des);
//Insert buff Item Value
if(m_strId[nItem+1]==dlg.m_Id)
{
m_strContent[nItem+1]=dlg.m_Content;
m_strNum[nItem+1]=dlg.m_Num;
m_strbSend[nItem+1]=dlg.m_bSend;
m_strDes[nItem+1]=dlg.m_Des;
ResetIniFileVal();
}
}
else
{
if(bExist)
::AfxMessageBox("已经存在列队编号为“"+dlg.m_Id+"” 的消息,更新失败!");
else//将自己的ID更新
{
m_List.SetItemText(nItem,0,dlg.m_Id);
m_List.SetItemText(nItem,1,dlg.m_Content);
m_List.SetItemText(nItem,2,dlg.m_Num);
m_List.SetItemText(nItem,3,dlg.m_bSend);
m_List.SetItemText(nItem,4,dlg.m_Des);
m_strId[nItem+1]=dlg.m_Id;
m_strContent[nItem+1]=dlg.m_Content;
m_strNum[nItem+1]=dlg.m_Num;
m_strbSend[nItem+1]=dlg.m_bSend;
m_strDes[nItem+1]=dlg.m_Des;
ResetIniFileVal();
}
}
}
}
else
OnAdd();
}
BOOL CMsgDemoView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
}
void CMsgDemoView::OnDblclkMsgList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your command handler code here
int iOption;
CString strId,strNum,strbSend,strContent,strDes;
iOption = m_List.GetSelectedCount();
//得到当前选中的行
POSITION pos = m_List.GetFirstSelectedItemPosition();
//如果选中一行
if(pos)
{
int nItem = m_List.GetNextSelectedItem(pos);
strId=m_List.GetItemText(nItem,0);
strContent=m_List.GetItemText(nItem,1);
strNum=m_List.GetItemText(nItem,2);
strbSend=m_List.GetItemText(nItem,3);
strDes=m_List.GetItemText(nItem,4);
CEditMsgDlg dlg;
dlg.strId=strId;
dlg.strContent=strContent;
dlg.strNum=strNum;
dlg.strbSend=strbSend;
dlg.strDes=strDes;
if(dlg.DoModal()==IDOK)
{
BOOL bExist=FALSE,bItem=FALSE;
int nCount=m_List.GetItemCount();
CString szTempId;
for(int i=0;i<nCount;i++)
{
szTempId=m_List.GetItemText(i,0);
if(szTempId==dlg.m_Id)
{
bExist=TRUE;
if(nItem==i)//是自己本身
bItem=TRUE;
break;
}
}
if(bItem)
{
m_List.SetItemText(nItem,0,dlg.m_Id);
m_List.SetItemText(nItem,1,dlg.m_Content);
m_List.SetItemText(nItem,2,dlg.m_Num);
m_List.SetItemText(nItem,3,dlg.m_bSend);
m_List.SetItemText(nItem,4,dlg.m_Des);
//Insert buff Item Value
if(m_strId[nItem+1]==dlg.m_Id)
{
m_strContent[nItem+1]=dlg.m_Content;
m_strNum[nItem+1]=dlg.m_Num;
m_strbSend[nItem+1]=dlg.m_bSend;
m_strDes[nItem+1]=dlg.m_Des;
ResetIniFileVal();
}
}
else
{
if(bExist)
::AfxMessageBox("已经存在列队编号为“"+dlg.m_Id+"” 的消息,更新失败!");
else//将自己的ID更新
{
m_List.SetItemText(nItem,0,dlg.m_Id);
m_List.SetItemText(nItem,1,dlg.m_Content);
m_List.SetItemText(nItem,2,dlg.m_Num);
m_List.SetItemText(nItem,3,dlg.m_bSend);
m_List.SetItemText(nItem,4,dlg.m_Des);
m_strId[nItem+1]=dlg.m_Id;
m_strContent[nItem+1]=dlg.m_Content;
m_strNum[nItem+1]=dlg.m_Num;
m_strbSend[nItem+1]=dlg.m_bSend;
m_strDes[nItem+1]=dlg.m_Des;
ResetIniFileVal();
}
}
}
}
else
OnAdd();
}
void CMsgDemoView::OnSendMsg()
{
// TODO: Add your command handler code here
// TODO: Add your command handler code here
int iOption;
CString strId;
iOption = m_List.GetSelectedCount();
//得到当前选中的行
POSITION pos = m_List.GetFirstSelectedItemPosition();
//如果选中一行
if(pos)
{
int nItem = m_List.GetNextSelectedItem(pos);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -