testBTView.cpp
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:5k
源码类别:

P2P编程

开发平台:

Visual C++

  1. // testBTView.cpp : implementation of the CTestBTView class
  2. //
  3. #include "stdafx.h"
  4. #include "testBT.h"
  5. #include "testBTDoc.h"
  6. #include "testBTView.h"
  7. #include "EncryptedConnection.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. // CTestBTView
  16. IMPLEMENT_DYNCREATE(CTestBTView, CView)
  17. BEGIN_MESSAGE_MAP(CTestBTView, CView)
  18. //{{AFX_MSG_MAP(CTestBTView)
  19. ON_WM_CREATE()
  20. ON_NOTIFY(TCN_SELCHANGE, 10500, OnColorSelchange)
  21. ON_WM_SIZE()
  22. ON_WM_DESTROY()
  23. //}}AFX_MSG_MAP
  24. // Standard printing commands
  25. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  26. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  27. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  28. END_MESSAGE_MAP()
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CTestBTView construction/destruction
  31. CTestBTView::CTestBTView()
  32. {
  33. m_bInit = false;
  34. }
  35. CTestBTView::~CTestBTView()
  36. {
  37. }
  38. BOOL CTestBTView::PreCreateWindow(CREATESTRUCT& cs)
  39. {
  40. // TODO: Modify the Window class or styles here by modifying
  41. //  the CREATESTRUCT cs
  42. return CView::PreCreateWindow(cs);
  43. }
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CTestBTView drawing
  46. void CTestBTView::OnDraw(CDC* pDC)
  47. {
  48. CTestBTDoc* pDoc = GetDocument();
  49. ASSERT_VALID(pDoc);
  50. // TODO: add draw code for native data here
  51. }
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CTestBTView printing
  54. BOOL CTestBTView::OnPreparePrinting(CPrintInfo* pInfo)
  55. {
  56. // default preparation
  57. return DoPreparePrinting(pInfo);
  58. }
  59. void CTestBTView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  60. {
  61. // TODO: add extra initialization before printing
  62. }
  63. void CTestBTView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  64. {
  65. // TODO: add cleanup after printing
  66. }
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CTestBTView diagnostics
  69. #ifdef _DEBUG
  70. void CTestBTView::AssertValid() const
  71. {
  72. CView::AssertValid();
  73. }
  74. void CTestBTView::Dump(CDumpContext& dc) const
  75. {
  76. CView::Dump(dc);
  77. }
  78. CTestBTDoc* CTestBTView::GetDocument() // non-debug version is inline
  79. {
  80. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestBTDoc)));
  81. return (CTestBTDoc*)m_pDocument;
  82. }
  83. #endif //_DEBUG
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CTestBTView message handlers
  86. int CTestBTView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  87. {
  88. if (CView::OnCreate(lpCreateStruct) == -1)
  89. return -1;
  90. return 0;
  91. }
  92. void CTestBTView::OnInitialUpdate() 
  93. {
  94. if (m_bInit) return;
  95. m_bInit = true;
  96. ((CMainFrame*)AfxGetMainWnd())->m_MonitorBar.m_MonitorWnd.Refresh();
  97. // m_MonitorWnd.CreateEx(this, CRect(0, 0, 100, 100), 0);
  98. BOOL bCreate = m_FilesList.CreateEx(this, CRect(0,0, 100, 100), 10025, 
  99. &((CMainFrame*)AfxGetMainWnd())->m_MonitorBar.m_MonitorWnd,
  100. &((CMainFrame*)AfxGetMainWnd())->m_CategoryBar.m_CategoryBarWnd,
  101. &((CMainFrame*)AfxGetMainWnd())->m_setupRegister);
  102. if (!bCreate)
  103. {
  104. assert(false);
  105. return ;
  106. }
  107. ((CMainFrame*)AfxGetMainWnd())->m_CategoryBar.m_CategoryBarWnd.OnFileListViewInitialUpdate();
  108. m_FilesList.SetFocus();
  109. CView::OnInitialUpdate();
  110. }
  111. void CTestBTView::OnSize(UINT nType, int cx, int cy) 
  112. {
  113. if (m_FilesList.GetSafeHwnd())
  114. m_FilesList.MoveWindow(CRect(0, 0, cx, cy));
  115. // m_MonitorWnd.MoveWindow(CRect(0, cy/2, cx, cy));
  116. CView::OnSize(nType, cx, cy);
  117. }
  118. void CTestBTView::OnDestroy() 
  119. {
  120. CView::OnDestroy();
  121. }
  122. void CTestBTView::OnColorSelchange(NMHDR* pNMHDR, LRESULT* pResult)
  123. {
  124. int nColor = m_TabText.GetCurSel();
  125. for (int i=0; i<m_TabText.GetItemCount(); i++)
  126. {
  127. TC_ITEM TabCtrlItem;
  128. memset(&TabCtrlItem, 0, sizeof(TabCtrlItem));
  129. TabCtrlItem.mask = TCIF_PARAM;
  130. BOOL b = m_TabText.GetItem(i, &TabCtrlItem);
  131. assert(b);
  132. CPoint* pPoint = (CPoint*)TabCtrlItem.lParam;
  133. CEdit* pedit = (CEdit*)pPoint->y;
  134. pedit->ShowWindow(i == nColor);
  135. }
  136. }
  137. CEdit* CTestBTView::InsertItem(long hsocket, string strText)
  138. {
  139. CEdit* pedit = new CEdit();
  140. BOOL b = pedit->Create(ES_MULTILINE|WS_CHILD|WS_VISIBLE|WS_BORDER|WS_VSCROLL, 
  141. CRect(0, 0, 100, 100), this, 10555+m_TabText.GetItemCount());
  142. assert(b);
  143. CPoint* pPoint = new CPoint(hsocket, (long)pedit);
  144. TC_ITEM TabCtrlItem;
  145. memset(&TabCtrlItem, 0, sizeof(TabCtrlItem));
  146. TabCtrlItem.mask = TCIF_TEXT|TCIF_PARAM;
  147. TabCtrlItem.pszText = (char*)strText.data();
  148. TabCtrlItem.lParam = (long)pPoint;
  149. b = m_TabText.InsertItem(0, &TabCtrlItem);
  150. assert(!b);
  151. OnSize(0, 0, 0);
  152. OnColorSelchange(0, 0);
  153. return pedit;
  154. }
  155. void CTestBTView::ShowMessage(long hsocket, char* strMsg)
  156. {
  157. CEdit* pedit = 0;
  158. for (int i=0; i<m_TabText.GetItemCount(); i++)
  159. {
  160. TC_ITEM TabCtrlItem;
  161. memset(&TabCtrlItem, 0, sizeof(TabCtrlItem));
  162. TabCtrlItem.mask = TCIF_PARAM;
  163. m_TabText.GetItem(i, &TabCtrlItem);
  164. CPoint* pPoint = (CPoint*)TabCtrlItem.lParam;
  165. if (hsocket == pPoint->x)
  166. {
  167. pedit = (CEdit*)pPoint->y;
  168. break;
  169. }
  170. }
  171. if (!pedit)
  172. {
  173. CEncryptedConnection * pConn = (CEncryptedConnection *)hsocket;
  174. string strIp = "unkown";
  175. if (pConn)
  176. strIp = pConn->GetIP();
  177. pedit = InsertItem(hsocket, strIp);
  178. }
  179. pedit->ReplaceSel(strMsg);
  180. }