TableView.cpp
上传用户:bsw_2008
上传日期:2013-07-09
资源大小:2446k
文件大小:7k
- // TableView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "CGameHallFrame.h"
- #include "TableView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CTableView
- IMPLEMENT_DYNCREATE(CTableView, CScrollView)
- CTableView::CTableView()
- {
- EnableAutomation();
- }
- CTableView::~CTableView()
- {
- }
- void CTableView::OnFinalRelease()
- {
- // When the last reference for an automation object is released
- // OnFinalRelease is called. The base class will automatically
- // deletes the object. Add additional cleanup required for your
- // object before calling the base class.
- CScrollView::OnFinalRelease();
- }
- BEGIN_MESSAGE_MAP(CTableView, CScrollView)
- //{{AFX_MSG_MAP(CTableView)
- ON_WM_ERASEBKGND()
- ON_WM_LBUTTONDOWN()
- ON_WM_MOUSEMOVE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BEGIN_DISPATCH_MAP(CTableView, CScrollView)
- //{{AFX_DISPATCH_MAP(CTableView)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_DISPATCH_MAP
- END_DISPATCH_MAP()
- // Note: we add support for IID_ITableView to support typesafe binding
- // from VBA. This IID must match the GUID that is attached to the
- // dispinterface in the .ODL file.
- // {D85B9A88-4D08-412F-B93A-0E4B55624DF3}
- static const IID IID_ITableView =
- { 0xd85b9a88, 0x4d08, 0x412f, { 0xb9, 0x3a, 0xe, 0x4b, 0x55, 0x62, 0x4d, 0xf3 } };
- BEGIN_INTERFACE_MAP(CTableView, CScrollView)
- INTERFACE_PART(CTableView, IID_ITableView, Dispatch)
- END_INTERFACE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CTableView drawing
- void CTableView::OnInitialUpdate()
- {
- CScrollView::OnInitialUpdate();
- CSize sizeTotal;
- // TODO: calculate the total size of this view
- sizeTotal.cx =100;
- sizeTotal.cy = 100;
- SetScrollSizes(MM_TEXT, sizeTotal);
- }
- void CTableView::OnDraw(CDC* pDC)
- {
- CDocument* pDoc = GetDocument();
- DrawTable();
- //flag=1;
- // TODO: add draw code here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CTableView diagnostics
- #ifdef _DEBUG
- void CTableView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
- void CTableView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CTableView message handlers
- void CTableView::DrawTable()
- {
- CDC *pDC=GetDC();
- CDC MemDC;
- MemDC.CreateCompatibleDC(pDC);
- CRect rect;
- this->GetClientRect(rect);
- CBitmap bmpFace;
- bmpFace.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());
- CBitmap* pOldBmp = NULL;
- pOldBmp = MemDC.SelectObject(&bmpFace);
- CBitmap bitmap,face;int x,y;
- BITMAP BMap;
- bitmap.LoadBitmap(IDB_TABLE);
- face.LoadBitmap(IDB_FACE);
- bitmap.GetBitmap(&BMap);
- x=BMap.bmWidth;
- y=BMap.bmHeight;
- CDC dcMem;
- dcMem.CreateCompatibleDC(&MemDC); //创建与pDC兼容的设备上下文
- dcMem.SelectObject(&bitmap); //将位图对象选入设备上下文
- //从源设备上下文复制位图到目标设备上下文
- CBrush brush(RGB(255,255,255));
- MemDC.FillRect(rect,&brush);
- if(flag==1)
- {
- MemDC.SetStretchBltMode(HALFTONE); //设置图缩放模式
- MemDC.BitBlt(0,0,x,y,&dcMem,0,0,SRCCOPY);
- dcMem.SelectObject(&face);
- face.GetBitmap(&BMap);
- x=BMap.bmWidth;
- y=BMap.bmHeight;
- for(int i=0;i<4;i++)
- for(int j=0;j<4;j++)
- {
- if(table[j][i].north==1)
- {
- MemDC.BitBlt(63+i*156,10+j*150,x,y,&dcMem,0,0,SRCCOPY);
- }
- if(table[j][i].south==1)
- {
- MemDC.BitBlt(63+i*156,100+j*150,x,y,&dcMem,0,0,SRCCOPY);
- }
- //MemDC.BitBlt(63+i*156,100+j*150,x,y,&dcMem,0,0,SRCCOPY);
- if(table[j][i].west==1)
- {
- MemDC.BitBlt(15+i*156,56+j*150,x,y,&dcMem,0,0,SRCCOPY);
- }
- //MemDC.BitBlt(15+i*156,56+j*150,x,y,&dcMem,0,0,SRCCOPY);
- if(table[j][i].east==1)
- {
- MemDC.BitBlt(110+i*156,56+j*150,x,y,&dcMem,0,0,SRCCOPY);
- }
- //MemDC.BitBlt(110+i*156,56+j*150,x,y,&dcMem,0,0,SRCCOPY);
- }
- }
- pDC->BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),&MemDC,rect.left,rect.top,SRCCOPY);
- MemDC.SelectObject(pOldBmp);
- bmpFace.DeleteObject();
- bitmap.DeleteObject();
- brush.DeleteObject();
- MemDC.DeleteDC();
- pDC->DeleteDC();
- }
- BOOL CTableView::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: Add your message handler code here and/or call default
-
- return FALSE;
- }
- BOOL CTableView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Add your specialized code here and/or call the base class
- m_hWait=AfxGetApp()->LoadCursor(IDC_HWAIT);
- return CScrollView::PreCreateWindow(cs);
- }
- void CTableView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- BOOL f=FALSE;
- if(flag==1)
- {
- int x,y,i,j,direct=-1;
- x=point.x%156;y=point.y%150;j=point.x/156;i=point.y/150;
- if(x>63&&x<95&&y>10&&y<42)
- direct=3;
- if(x>63&&x<95&&y>100&&y<132)
- direct=1;
- if(x>15&&x<50&&y>56&&y<88)
- direct=2;
- if(x>110&&x<142&&y>56&&y<88)
- direct=0;
- if(direct>=0)
- {
- switch(direct)
- {
- case 0:if(table[i][j].east!=1)
- {
- table[i][j].east=1;
- DrawTable();f=TRUE;
- }
- break;
- case 1:if(table[i][j].south!=1)
- {
- table[i][j].south=1;
- DrawTable();f=TRUE;
- }
- break;
- case 2:if(table[i][j].west!=1)
- {
- table[i][j].west=1;
- DrawTable();f=TRUE;
- }
- break;
- case 3:if(table[i][j].north!=1)
- {
- table[i][j].north=1;
- DrawTable();f=TRUE;
- }
- break;
- default:break;
- }
- if(f)
- {
- CString a,t;
- a=char(20);a+='B';
- t.Format("%d ",i*4+j);
- a+=t;
- t.Format("%d",direct);
- a+=t;a+=char(20);
- pClient->SendString(a);
- dlg=new CGameDlg();
- dlg->desk=i*4+j;
- dlg->direct=direct;
- dlg->pClient=pClient;
- dlg->DoModal();
- delete(dlg);
- switch(direct)
- {
- case 0:table[i][j].east=0;
- DrawTable();
- break;
- case 1:
- table[i][j].south=0;
- DrawTable();
- break;
- case 2:
- table[i][j].west=0;
- DrawTable();
- break;
- case 3:
- table[i][j].north=0;
- DrawTable();
- break;
- default:break;
- }
- a.Empty();
- a=char(20);a+='P';
- t.Format("%d ",i*4+j);
- a+=t;
- t.Format("%d",direct);
- a+=t;a+=char(20);
- pClient->SendString(a);
- }
- }
- }
- CScrollView::OnLButtonDown(nFlags, point);
- }
- void CTableView::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(flag==1)
- {
- SetCapture(); //捕捉鼠标
- int x,y,i,j,direct=-1;
- x=point.x%156;y=point.y%150;j=point.x/156;i=point.y/150;
- if(x>63&&x<95&&y>10&&y<42)
- direct=3;
- if(x>63&&x<95&&y>100&&y<132)
- direct=1;
- if(x>15&&x<50&&y>56&&y<88)
- direct=2;
- if(x>110&&x<142&&y>56&&y<88)
- direct=0;
- if(direct>=0)
- {
- ::SetCursor(m_hWait); //设置光标
- }
- else
- {
- ReleaseCapture(); //释放鼠标,还原鼠标形状
- }
- }
- CScrollView::OnMouseMove(nFlags, point);
- }