vc_demoView.cpp
上传用户:zcy791212
上传日期:2013-03-06
资源大小:196k
文件大小:7k
源码类别:

Modem编程

开发平台:

Visual C++

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