vc_demoView.cpp
资源名称:vc_demo.rar [点击查看]
上传用户:zcy791212
上传日期:2013-03-06
资源大小:196k
文件大小:7k
源码类别:
Modem编程
开发平台:
Visual C++
- // vc_demoView.cpp : implementation of the CVc_demoView class
- //
- #include "stdafx.h"
- #include "gprsdll.h"
- #include "vc_demo.h"
- #include "vc_demoDoc.h"
- #include "vc_demoView.h"
- #include "mainfrm.h"
- #include "gprsdll.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CVc_demoView
- IMPLEMENT_DYNCREATE(CVc_demoView, CListView)
- BEGIN_MESSAGE_MAP(CVc_demoView, CListView)
- //{{AFX_MSG_MAP(CVc_demoView)
- ON_WM_SHOWWINDOW()
- ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustDrawList)
- ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
- ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CVc_demoView construction/destruction
- CVc_demoView::CVc_demoView()
- {
- // TODO: add construction code here
- }
- CVc_demoView::~CVc_demoView()
- {
- }
- BOOL CVc_demoView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- cs.style=cs.style | LVS_REPORT;
- return CListView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CVc_demoView drawing
- void CVc_demoView::OnDraw(CDC* pDC)
- {
- CVc_demoDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CListCtrl& refCtrl = GetListCtrl();
- refCtrl.InsertItem(0, "Item!");
- // TODO: add draw code for native data here
- }
- void CVc_demoView::OnInitialUpdate()
- {
- CListView::OnInitialUpdate();
- m_Font1.CreateFont(-MulDiv(9,this->GetDC()->GetDeviceCaps(LOGPIXELSY), 72),
- 0,0,0,FW_BOLD,FALSE,FALSE,FALSE,0,0,0,0,0,_T("Arial"));
- m_Font2.CreateFont(-MulDiv(9,this->GetDC()->GetDeviceCaps(LOGPIXELSY), 72),
- 0,0,0,FW_BOLD,FALSE,FALSE,FALSE,0,0,0,0,0,_T("Arial"));
- m_Font3.CreateFont(-MulDiv(9,this->GetDC()->GetDeviceCaps(LOGPIXELSY), 72),
- 0,0,0,FW_BOLD,FALSE,FALSE,FALSE,0,0,0,0,0,_T("Arial"));
- // TODO: You may populate your ListView with items by directly accessing
- // its list control through a call to GetListCtrl().
- }
- /////////////////////////////////////////////////////////////////////////////
- // CVc_demoView diagnostics
- #ifdef _DEBUG
- void CVc_demoView::AssertValid() const
- {
- CListView::AssertValid();
- }
- void CVc_demoView::Dump(CDumpContext& dc) const
- {
- CListView::Dump(dc);
- }
- CVc_demoDoc* CVc_demoView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVc_demoDoc)));
- return (CVc_demoDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CVc_demoView message handlers
- void CVc_demoView::OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct)
- {
- //TODO: add code to react to the user changing the view style of your window
- }
- void CVc_demoView::setViewStyle()
- {
- CListCtrl &lc=this->GetListCtrl();
- lc.SetExtendedStyle(lc.GetExStyle()
- | LVS_EX_FULLROWSELECT
- | LVS_EX_GRIDLINES
- | LVS_EX_ONECLICKACTIVATE
- | LVS_EX_HEADERDRAGDROP);
- lc.SetTextColor(0xDF16EF);
- lc.SetBkColor(0xE8FDF9);
- lc.SetTextBkColor(0xE8FDF9);
- CImageList imglist;
- imglist.Create(1,24,ILC_COLOR4,0,0);
- lc.SetImageList(&imglist,LVSIL_SMALL);
- lc.InsertColumn(0,"Modem ID号",LVCFMT_CENTER,120);
- lc.InsertColumn(1,"登录时间",LVCFMT_CENTER,180);
- lc.InsertColumn(2,"最后更新时间",LVCFMT_CENTER,180);
- lc.InsertColumn(3,"Modem电话号码",LVCFMT_CENTER,120);
- }
- void CVc_demoView::OnCustDrawList(NMHDR* pNMHDR, LRESULT* pResult)
- {
- LPNMLVCUSTOMDRAW pDraw = (LPNMLVCUSTOMDRAW)pNMHDR;
- // Determine the drawing stage.
- DWORD dwDrawStage = pDraw->nmcd.dwDrawStage;
- *pResult = CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT|CDRF_NOTIFYPOSTERASE;
- if(dwDrawStage & CDDS_ITEM)
- {
- //CSubDate* pHotel = (CSubDate*)pDraw->nmcd.lItemlParam;
- if((dwDrawStage & CDDS_SUBITEM)&&(pDraw->iSubItem == 0))
- {
- pDraw->clrText = 0x0000FF;//RGB(88,33,255);
- pDraw->clrTextBk=0xFFFEEE;
- SelectObject(pDraw->nmcd.hdc,
- (HFONT)m_Font1.m_hObject);
- *pResult |= CDRF_NEWFONT;
- }
- else if((dwDrawStage & CDDS_SUBITEM)
- && (pDraw->iSubItem <= 2))
- {
- pDraw->clrText = 0xF4F70E;//RGB(200,100,40);
- pDraw->clrTextBk=0xE8FDF9;
- SelectObject(pDraw->nmcd.hdc,
- (HFONT)m_Font3.m_hObject);
- *pResult |= CDRF_NEWFONT;
- }else{
- pDraw->clrText = 0x8888FF;//RGB(200,100,40);
- pDraw->clrTextBk=0xE8FDF9;
- SelectObject(pDraw->nmcd.hdc,
- (HFONT)m_Font1.m_hObject);
- *pResult |= CDRF_NEWFONT;
- }
- }
- }
- void CVc_demoView::OnShowWindow(BOOL bShow, UINT nStatus)
- {
- CListView::OnShowWindow(bShow, nStatus);
- this->setViewStyle();
- // TODO: Add your message handler code here
- }
- void CVc_demoView::
- InsertUserItem(ModemInfoStruct *mi)
- {
- char buf[64];
- int listitemcount;
- CListCtrl &lc=this->GetListCtrl();
- struct tm * ptm;
- listitemcount=lc.GetItemCount();
- //id
- CString str;
- str.Format("%8.8x",mi->m_modemId);
- lc.InsertItem(listitemcount,str,0);
- //logon date time
- struct tm *when;
- when = localtime((time_t*)&(mi->m_conn_time));
- sprintf(buf,"%s",
- asctime(when));
- lc.SetItemText(listitemcount,1,buf);
- //update date time
- ptm=localtime((time_t *)&mi->m_refresh_time);
- sprintf(buf,"%d-%02d-%02d %02d:%02d:%02d",
- ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,
- ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
- lc.SetItemText(listitemcount,2,buf);
- //phone no.
- lc.SetItemText(listitemcount,3,(char*)mi->m_phoneno);
- listitemcount++;
- }
- void CVc_demoView::ClearAllItem()
- {
- this->GetListCtrl().DeleteAllItems();
- }
- void CVc_demoView::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- char userid[12];
- CListCtrl &lc=GetListCtrl();
- POSITION p;
- p=lc.GetFirstSelectedItemPosition();
- int index=lc.GetNextSelectedItem(p);
- lc.GetItemText(index,0,userid,12);
- if (11==strlen(userid))
- ((CMainFrame *)::AfxGetMainWnd())->SetUserId(userid);
- else
- ((CMainFrame *)::AfxGetMainWnd())->SetUserId("");
- *pResult = 0;
- }
- void CVc_demoView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- CMenu mu,*pSubMenu;
- CPoint p;
- this->OnClick(pNMHDR,pResult);
- mu.LoadMenu(IDR_SPEEDMENU);
- pSubMenu=mu.GetSubMenu(0);
- ::GetCursorPos(&p);
- pSubMenu->TrackPopupMenu(TPM_LEFTALIGN,p.x,p.y,::AfxGetMainWnd());
- *pResult = 0;
- }