testBTView.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:5k
源码类别:
P2P编程
开发平台:
Visual C++
- // testBTView.cpp : implementation of the CTestBTView class
- //
- #include "stdafx.h"
- #include "testBT.h"
- #include "testBTDoc.h"
- #include "testBTView.h"
- #include "EncryptedConnection.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CTestBTView
- IMPLEMENT_DYNCREATE(CTestBTView, CView)
- BEGIN_MESSAGE_MAP(CTestBTView, CView)
- //{{AFX_MSG_MAP(CTestBTView)
- ON_WM_CREATE()
- ON_NOTIFY(TCN_SELCHANGE, 10500, OnColorSelchange)
- ON_WM_SIZE()
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CTestBTView construction/destruction
- CTestBTView::CTestBTView()
- {
- m_bInit = false;
- }
- CTestBTView::~CTestBTView()
- {
- }
- BOOL CTestBTView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CTestBTView drawing
- void CTestBTView::OnDraw(CDC* pDC)
- {
- CTestBTDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CTestBTView printing
- BOOL CTestBTView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CTestBTView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CTestBTView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CTestBTView diagnostics
- #ifdef _DEBUG
- void CTestBTView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CTestBTView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CTestBTDoc* CTestBTView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestBTDoc)));
- return (CTestBTDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CTestBTView message handlers
- int CTestBTView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
- return 0;
- }
- void CTestBTView::OnInitialUpdate()
- {
- if (m_bInit) return;
- m_bInit = true;
- ((CMainFrame*)AfxGetMainWnd())->m_MonitorBar.m_MonitorWnd.Refresh();
- // m_MonitorWnd.CreateEx(this, CRect(0, 0, 100, 100), 0);
- BOOL bCreate = m_FilesList.CreateEx(this, CRect(0,0, 100, 100), 10025,
- &((CMainFrame*)AfxGetMainWnd())->m_MonitorBar.m_MonitorWnd,
- &((CMainFrame*)AfxGetMainWnd())->m_CategoryBar.m_CategoryBarWnd,
- &((CMainFrame*)AfxGetMainWnd())->m_setupRegister);
- if (!bCreate)
- {
- assert(false);
- return ;
- }
- ((CMainFrame*)AfxGetMainWnd())->m_CategoryBar.m_CategoryBarWnd.OnFileListViewInitialUpdate();
- m_FilesList.SetFocus();
- CView::OnInitialUpdate();
- }
- void CTestBTView::OnSize(UINT nType, int cx, int cy)
- {
- if (m_FilesList.GetSafeHwnd())
- m_FilesList.MoveWindow(CRect(0, 0, cx, cy));
- // m_MonitorWnd.MoveWindow(CRect(0, cy/2, cx, cy));
- CView::OnSize(nType, cx, cy);
- }
- void CTestBTView::OnDestroy()
- {
- CView::OnDestroy();
- }
- void CTestBTView::OnColorSelchange(NMHDR* pNMHDR, LRESULT* pResult)
- {
- int nColor = m_TabText.GetCurSel();
- for (int i=0; i<m_TabText.GetItemCount(); i++)
- {
- TC_ITEM TabCtrlItem;
- memset(&TabCtrlItem, 0, sizeof(TabCtrlItem));
- TabCtrlItem.mask = TCIF_PARAM;
- BOOL b = m_TabText.GetItem(i, &TabCtrlItem);
- assert(b);
- CPoint* pPoint = (CPoint*)TabCtrlItem.lParam;
- CEdit* pedit = (CEdit*)pPoint->y;
- pedit->ShowWindow(i == nColor);
- }
- }
- CEdit* CTestBTView::InsertItem(long hsocket, string strText)
- {
- CEdit* pedit = new CEdit();
- BOOL b = pedit->Create(ES_MULTILINE|WS_CHILD|WS_VISIBLE|WS_BORDER|WS_VSCROLL,
- CRect(0, 0, 100, 100), this, 10555+m_TabText.GetItemCount());
- assert(b);
- CPoint* pPoint = new CPoint(hsocket, (long)pedit);
- TC_ITEM TabCtrlItem;
- memset(&TabCtrlItem, 0, sizeof(TabCtrlItem));
- TabCtrlItem.mask = TCIF_TEXT|TCIF_PARAM;
- TabCtrlItem.pszText = (char*)strText.data();
- TabCtrlItem.lParam = (long)pPoint;
- b = m_TabText.InsertItem(0, &TabCtrlItem);
- assert(!b);
- OnSize(0, 0, 0);
- OnColorSelchange(0, 0);
- return pedit;
- }
- void CTestBTView::ShowMessage(long hsocket, char* strMsg)
- {
- CEdit* pedit = 0;
- for (int i=0; i<m_TabText.GetItemCount(); i++)
- {
- TC_ITEM TabCtrlItem;
- memset(&TabCtrlItem, 0, sizeof(TabCtrlItem));
- TabCtrlItem.mask = TCIF_PARAM;
- m_TabText.GetItem(i, &TabCtrlItem);
- CPoint* pPoint = (CPoint*)TabCtrlItem.lParam;
- if (hsocket == pPoint->x)
- {
- pedit = (CEdit*)pPoint->y;
- break;
- }
- }
- if (!pedit)
- {
- CEncryptedConnection * pConn = (CEncryptedConnection *)hsocket;
- string strIp = "unkown";
- if (pConn)
- strIp = pConn->GetIP();
- pedit = InsertItem(hsocket, strIp);
- }
- pedit->ReplaceSel(strMsg);
- }