vc_demoView.cpp
上传用户:sdxhgc
上传日期:2013-09-14
资源大小:388k
文件大小:7k
源码类别:

通讯编程

开发平台:

Visual C++

  1. // vc_demoView.cpp : implementation of the CVc_demoView class
  2. //
  3. #include "stdafx.h"
  4. #include "vc_demo.h"
  5. #include "vc_demoDoc.h"
  6. #include "vc_demoView.h"
  7. #include "mainfrm.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CVc_demoView
  15. IMPLEMENT_DYNCREATE(CVc_demoView, CListView)
  16. BEGIN_MESSAGE_MAP(CVc_demoView, CListView)
  17. //{{AFX_MSG_MAP(CVc_demoView)
  18. ON_WM_SHOWWINDOW()
  19. ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustDrawList)
  20. ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
  21. ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
  22. //}}AFX_MSG_MAP
  23. END_MESSAGE_MAP()
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CVc_demoView construction/destruction
  26. CVc_demoView::CVc_demoView()
  27. {
  28. // TODO: add construction code here
  29. }
  30. CVc_demoView::~CVc_demoView()
  31. {
  32. }
  33. BOOL CVc_demoView::PreCreateWindow(CREATESTRUCT& cs)
  34. {
  35. // TODO: Modify the Window class or styles here by modifying
  36. //  the CREATESTRUCT cs
  37.     cs.style=cs.style | LVS_REPORT;
  38. return CListView::PreCreateWindow(cs);
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CVc_demoView drawing
  42. void CVc_demoView::OnDraw(CDC* pDC)
  43. {
  44. CVc_demoDoc* pDoc = GetDocument();
  45. ASSERT_VALID(pDoc);
  46. CListCtrl& refCtrl = GetListCtrl();
  47. refCtrl.InsertItem(0, "Item!");
  48. // TODO: add draw code for native data here
  49. }
  50. void CVc_demoView::OnInitialUpdate()
  51. {
  52. CListView::OnInitialUpdate();
  53. m_Font1.CreateFont(-MulDiv(9,this->GetDC()->GetDeviceCaps(LOGPIXELSY), 72),
  54.                         0,0,0,FW_BOLD,FALSE,FALSE,FALSE,0,0,0,0,0,_T("Arial"));
  55. m_Font2.CreateFont(-MulDiv(9,this->GetDC()->GetDeviceCaps(LOGPIXELSY), 72),
  56.                         0,0,0,FW_BOLD,FALSE,FALSE,FALSE,0,0,0,0,0,_T("Arial"));
  57. m_Font3.CreateFont(-MulDiv(9,this->GetDC()->GetDeviceCaps(LOGPIXELSY), 72),
  58.                         0,0,0,FW_BOLD,FALSE,FALSE,FALSE,0,0,0,0,0,_T("Arial"));
  59. // TODO: You may populate your ListView with items by directly accessing
  60. //  its list control through a call to GetListCtrl().
  61. }
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CVc_demoView diagnostics
  64. #ifdef _DEBUG
  65. void CVc_demoView::AssertValid() const
  66. {
  67. CListView::AssertValid();
  68. }
  69. void CVc_demoView::Dump(CDumpContext& dc) const
  70. {
  71. CListView::Dump(dc);
  72. }
  73. CVc_demoDoc* CVc_demoView::GetDocument() // non-debug version is inline
  74. {
  75. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVc_demoDoc)));
  76. return (CVc_demoDoc*)m_pDocument;
  77. }
  78. #endif //_DEBUG
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CVc_demoView message handlers
  81. void CVc_demoView::OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct)
  82. {
  83. //TODO: add code to react to the user changing the view style of your window
  84. }
  85. void CVc_demoView::setViewStyle()
  86. {
  87. CListCtrl &lc=this->GetListCtrl();
  88. lc.SetExtendedStyle(lc.GetExStyle() 
  89.     | LVS_EX_FULLROWSELECT
  90. | LVS_EX_GRIDLINES
  91. | LVS_EX_ONECLICKACTIVATE
  92. | LVS_EX_HEADERDRAGDROP);
  93. lc.SetTextColor(0xDF16EF);
  94. lc.SetBkColor(0xE8FDF9);
  95. lc.SetTextBkColor(0xE8FDF9);
  96.     CImageList imglist;
  97. imglist.Create(1,24,ILC_COLOR4,0,0);
  98. lc.SetImageList(&imglist,LVSIL_SMALL);
  99. lc.InsertColumn(0,"DTU号码",LVCFMT_CENTER,100);
  100. lc.InsertColumn(1,"登录时间",LVCFMT_CENTER,180);
  101. lc.InsertColumn(2,"最后注册时间",LVCFMT_CENTER,180);
  102. lc.InsertColumn(3,"终端IP地址",LVCFMT_CENTER,120);
  103. lc.InsertColumn(4,"终端端口",LVCFMT_CENTER,80);
  104. lc.InsertColumn(5,"网关出口IP地址",LVCFMT_CENTER,120);
  105. lc.InsertColumn(6,"网关出口端口",LVCFMT_CENTER,90);
  106. }
  107. void CVc_demoView::OnCustDrawList(NMHDR* pNMHDR, LRESULT* pResult)
  108. {
  109.     LPNMLVCUSTOMDRAW pDraw = (LPNMLVCUSTOMDRAW)pNMHDR;
  110.     // Determine the drawing stage.
  111.     DWORD dwDrawStage = pDraw->nmcd.dwDrawStage;
  112.     *pResult = CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT|CDRF_NOTIFYPOSTERASE;
  113.     if(dwDrawStage & CDDS_ITEM)
  114.     {
  115.         //CSubDate* pHotel = (CSubDate*)pDraw->nmcd.lItemlParam;
  116. if((dwDrawStage & CDDS_SUBITEM)&&(pDraw->iSubItem == 0))
  117.         {
  118. pDraw->clrText = 0x0000FF;//RGB(88,33,255);
  119. pDraw->clrTextBk=0xFFFEEE;
  120. SelectObject(pDraw->nmcd.hdc,
  121. (HFONT)m_Font1.m_hObject);
  122. *pResult |= CDRF_NEWFONT;
  123.         }
  124.         else if((dwDrawStage & CDDS_SUBITEM) 
  125. && (pDraw->iSubItem <= 2))
  126.         {
  127. pDraw->clrText = 0xDF16EF;//RGB(200,100,40);
  128. pDraw->clrTextBk=0xE8FDF9;
  129. SelectObject(pDraw->nmcd.hdc,
  130. (HFONT)m_Font3.m_hObject);
  131. *pResult |= CDRF_NEWFONT;
  132.         }else{
  133. pDraw->clrText = 0x8888FF;//RGB(200,100,40);
  134. pDraw->clrTextBk=0xE8FDF9;
  135. SelectObject(pDraw->nmcd.hdc,
  136. (HFONT)m_Font1.m_hObject);
  137. *pResult |= CDRF_NEWFONT;
  138. }
  139.     }
  140. }
  141. void CVc_demoView::OnShowWindow(BOOL bShow, UINT nStatus) 
  142. {
  143. CListView::OnShowWindow(bShow, nStatus);
  144. this->setViewStyle();
  145. // TODO: Add your message handler code here
  146. }
  147. void CVc_demoView::
  148.     InsertUserItem(char * userid,char * logon_date,
  149.    char * update_date,unsigned long localip,
  150.    unsigned short localport,unsigned long gwip,
  151.    unsigned short gwport)
  152. {
  153.     char buf[64],*ch;
  154. int listitemcount;
  155. CListCtrl &lc=this->GetListCtrl();
  156.     struct tm * ptm;
  157.     listitemcount=lc.GetItemCount();
  158. lc.InsertItem(listitemcount,userid,0);
  159. //logon date time
  160. lc.SetItemText(listitemcount,1,logon_date);
  161. //update date time
  162. ptm=localtime((time_t *)update_date);
  163. sprintf(buf,"%d-%02d-%02d %02d:%02d:%02d",
  164. ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,
  165. ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
  166. lc.SetItemText(listitemcount,2,buf);
  167. //DTU local ip and local port
  168. ch=(char *)&localip;
  169.     sprintf(buf,"%u.%u.%u.%u",(*(ch+3))&0xFF,
  170.               (*(ch+2))&0xFF,
  171.               (*(ch+1))&0xFF,
  172.   (*(ch+0))&0xFF);
  173. lc.SetItemText(listitemcount,3,buf);
  174. sprintf(buf,"%d",localport);
  175. lc.SetItemText(listitemcount,4,buf);
  176. //ip and port of the gateway that DTU pass
  177. ch=(char *)&gwip;
  178.     sprintf(buf,"%u.%u.%u.%u",(*(ch+3))&0xFF,
  179.                           (*(ch+2))&0xFF,
  180.                       (*(ch+1))&0xFF,
  181.   (*(ch+0))&0xFF);
  182. lc.SetItemText(listitemcount,5,buf);
  183. sprintf(buf,"%d",gwport);
  184. lc.SetItemText(listitemcount,6,buf);
  185. listitemcount++;
  186. }
  187. void CVc_demoView::ClearAllItem()
  188. {
  189. this->GetListCtrl().DeleteAllItems();
  190. }
  191. void CVc_demoView::OnClick(NMHDR* pNMHDR, LRESULT* pResult) 
  192. {
  193. // TODO: Add your control notification handler code here
  194. char userid[12];
  195. CListCtrl &lc=GetListCtrl();
  196. POSITION p;
  197. p=lc.GetFirstSelectedItemPosition();
  198. int index=lc.GetNextSelectedItem(p);
  199. lc.GetItemText(index,0,userid,12);
  200. if (11==strlen(userid))
  201. ((CMainFrame *)::AfxGetMainWnd())->SetUserId(userid);
  202. else
  203. ((CMainFrame *)::AfxGetMainWnd())->SetUserId("");
  204. *pResult = 0;
  205. }
  206. void CVc_demoView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) 
  207. {
  208. // TODO: Add your control notification handler code here
  209.     CMenu mu,*pSubMenu;
  210. CPoint p;
  211. this->OnClick(pNMHDR,pResult);
  212. mu.LoadMenu(IDR_SPEEDMENU);
  213. pSubMenu=mu.GetSubMenu(0);
  214. ::GetCursorPos(&p);
  215. pSubMenu->TrackPopupMenu(TPM_LEFTALIGN,p.x,p.y,::AfxGetMainWnd());
  216. *pResult = 0;
  217. }