BilliardsFormView.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:3k
源码类别:

游戏

开发平台:

Visual C++

  1. // BilliardsFormView.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Billiards.h"
  5. #include "BilliardsFormView.h"
  6. #include "BilliardsDoc.h"
  7. #include "BilliardsPlayView.h"
  8. #include "MainFrm.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CBilliardsFormView
  16. IMPLEMENT_DYNCREATE(CBilliardsFormView, CFormView)
  17. CBilliardsFormView::CBilliardsFormView()
  18. : CFormView(CBilliardsFormView::IDD)
  19. {
  20. //{{AFX_DATA_INIT(CBilliardsFormView)
  21. m_strMSG = _T("");
  22.     m_WhiteBrush=new CBrush(HS_CROSS,RGB(255,255,255));
  23. m_BlueBrush=new CBrush(HS_CROSS,RGB(220,220,255));
  24.     
  25. //}}AFX_DATA_INIT
  26. }
  27. CBilliardsFormView::~CBilliardsFormView()
  28. {
  29. }
  30. void CBilliardsFormView::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CFormView::DoDataExchange(pDX);
  33. //{{AFX_DATA_MAP(CBilliardsFormView)
  34. DDX_Control(pDX, IDC_PROGRESS_POWER, m_ctlProgressPower);
  35. DDX_Control(pDX, IDC_LIST_MSG, m_ctlListMSG);
  36. DDX_Text(pDX, IDC_EDIT_MSG, m_strMSG);
  37. DDX_Control(pDX, IDC_BUTTON_SEND, m_BtnSend);
  38. DDX_Control(pDX, IDC_BUTTON_SHOOT, m_BtnShoot);
  39. //}}AFX_DATA_MAP
  40.     m_ctlProgressPower.SetRange(0,100);
  41.     m_ctlProgressPower.SetPos(0);
  42. }
  43. BEGIN_MESSAGE_MAP(CBilliardsFormView, CFormView)
  44. //{{AFX_MSG_MAP(CBilliardsFormView)
  45. ON_BN_CLICKED(IDC_BUTTON_SEND, OnButtonSend)
  46. ON_BN_CLICKED(IDC_BUTTON_SHOOT, OnButtonShoot)
  47. ON_WM_CTLCOLOR()
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CBilliardsFormView diagnostics
  52. #ifdef _DEBUG
  53. void CBilliardsFormView::AssertValid() const
  54. {
  55. CFormView::AssertValid();
  56. }
  57. void CBilliardsFormView::Dump(CDumpContext& dc) const
  58. {
  59. CFormView::Dump(dc);
  60. }
  61. #endif //_DEBUG
  62. CBilliardsDoc* CBilliardsFormView::GetDocument() // non-debug version is inline
  63. {
  64. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBilliardsDoc)));
  65. return (CBilliardsDoc*)m_pDocument;
  66. }
  67. void CBilliardsFormView::OnButtonSend() 
  68. {
  69. CBilliardsDoc* pDoc = GetDocument();
  70.     CPropertyItem* pItem;
  71. UpdateData();
  72.     if(m_strMSG.IsEmpty())
  73. {
  74. AfxMessageBox("空消息不发送",MB_OK);
  75.         pItem=NULL;
  76.     }
  77.     else
  78. {
  79. if(pDoc->m_bPlayer==SERVER)
  80. pItem = new CPropertyItem(pDoc->m_strServer,m_strMSG,PIT_EDIT,"");
  81.             
  82. else
  83. pItem = new CPropertyItem(pDoc->m_strClient,m_strMSG,PIT_EDIT,"");
  84.         
  85. m_ctlListMSG.AddPropItem(pItem);
  86. m_strMSG.Insert(0,"1");
  87. pDoc->m_pClientSocket->Send(m_strMSG,m_strMSG.GetLength());
  88. }
  89. }
  90. void CBilliardsFormView::OnButtonShoot() 
  91. {
  92.     CBilliardsPlayView *pView=(CBilliardsPlayView *)((CMainFrame *)AfxGetMainWnd())->m_wndSplitter.GetPane(0,0);
  93.     pView->HitBall();
  94. }
  95. HBRUSH CBilliardsFormView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
  96. {
  97. HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
  98.     /*
  99.     if(nCtlColor==CTLCOLOR_DLG||nCtlColor==CTLCOLOR_STATIC||nCtlColor==CTLCOLOR_BTN){
  100.         pDC->SetBkColor(RGB(255,255,255));
  101.         return (HBRUSH)(m_WhiteBrush->GetSafeHandle());
  102.     }
  103.     */
  104. if(nCtlColor==CTLCOLOR_EDIT||nCtlColor==CTLCOLOR_LISTBOX)
  105. {
  106. pDC->SetBkColor(RGB(220,220,255));
  107.         return (HBRUSH)(m_BlueBrush->GetSafeHandle());
  108. }
  109. return hbr;
  110. }