PeerInfo.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:18k
源码类别:
P2P编程
开发平台:
Visual C++
- // PeerInfo.cpp : implementation file
- //
- #include "stdafx.h"
- #include "testbt.h"
- #include "PeerInfo.h"
- #include "PeersListCtrl.h"
- #include "FileBase.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define ID_MENUITEM_PAUSE_PEERS 52834
- #define ID_MENUITEM_CONTINUE_PEERS ID_MENUITEM_PAUSE_PEERS+1
- #define ID_MENUITEM_STOP_PEERS ID_MENUITEM_PAUSE_PEERS+2
- #define ID_MENUITEM_SHOW_PEERS_LIST ID_MENUITEM_PAUSE_PEERS+3
- /////////////////////////////////////////////////////////////////////////////
- // CPeerInfo
- CPeerInfo::CPeerInfo() : CScrollWndbase(CRect (0, 0, 600, 260))
- {
- m_pPeersListCtrl = 0;
- m_lGridWidth = 5;
- memset(m_bRefreshItem, false, eAllCount);
- m_bAbort = false;
- m_bMonitoring = false;
- }
- CPeerInfo::~CPeerInfo()
- {
- }
- BEGIN_MESSAGE_MAP(CPeerInfo, CScrollWndbase)
- //{{AFX_MSG_MAP(CPeerInfo)
- ON_WM_PAINT()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_LBUTTONDOWN()
- ON_WM_CREATE()
- ON_WM_ERASEBKGND()
- ON_WM_CONTEXTMENU()
- ON_WM_RBUTTONDOWN()
- //}}AFX_MSG_MAP
- ON_COMMAND_RANGE(ID_MENUITEM_PAUSE_PEERS, ID_MENUITEM_SHOW_PEERS_LIST, OnMenuItemPeers)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPeerInfo message handlers
- BOOL CPeerInfo::CreateEx(CWnd *pParent, CRect rc, CPeersListCtrl * pPeersListCtrl, long lID, long lParam)
- {
- m_pPeersListCtrl = pPeersListCtrl;
- return Create(0, 0, WS_CHILD|WS_BORDER|WS_VISIBLE, rc, pParent, lID);
- }
- int CPeerInfo::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CScrollWndbase::OnCreate(lpCreateStruct) == -1)
- return -1;
- m_font.CreateFont(-12, 0, 0, 0, 400, 0, 0, 0, 134, 0, 0, 0, 2, "宋体");
- m_graphHaveData.Create(CRect(20, 220, 600, 240), this);
- m_IPLocator.Create(GetDefaultModulePath());
- return 0;
- }
- void CPeerInfo::OnScrollEx()
- {
- CRect rc;
- GetClientRect(rc);
- CClientDC dc(this); // device context for painting
- CBitmap bmp;
- bmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
- CDC memdc;
- memdc.CreateCompatibleDC(&dc);
- CGdiObject* pold = memdc.SelectObject(&bmp);
- EraseBk(memdc, rc);
- DrawItem(memdc);
- dc.BitBlt(0, 0, rc.Width(), rc.Height(), &memdc, 0, 0, SRCCOPY);
- memdc.SelectObject(pold);
- // OnPaint();
- // Invalidate();
- }
- void CPeerInfo::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- DrawItem(dc);
- TRACE("rn Peer Info npaintrn");
- }
- BOOL CPeerInfo::OnEraseBkgnd(CDC* pDC)
- {
- CRect rc;
- pDC->GetClipBox(&rc);
- EraseBk(*pDC, rc);
- return TRUE;
- return CScrollWndbase::OnEraseBkgnd(pDC);
- }
- void CPeerInfo::EraseBk(CDC & dc, CRect rc)
- {
- dc.FillRect(rc, &CBrush(RGB(255, 255, 255)));
- }
- void CPeerInfo::DrawItem(CDC & dc, bool bPart)
- {
- CPoint ptTopLeft = GetTopLeft();
- dc.SetBkMode(TRANSPARENT);
- CFont* pOldFont = dc.SelectObject(&m_font);
- CRect rc;
- // GetClientRect(rc);
- // dc.FillRect(rc, &CBrush(RGB(255, 255, 255)));
- CRect rcTitle(20, 20, 170, 40);
- CRect rcContent(170, 20, 450, 40);
- rcTitle.OffsetRect(-ptTopLeft.x, -ptTopLeft.y);
- rcContent.OffsetRect(-ptTopLeft.x, -ptTopLeft.y);
- CString szText;
- //
- if (!bPart || (bPart && m_bRefreshItem[eAddr]))
- {
- if (bPart)
- {
- EraseBk(dc, rcTitle);
- EraseBk(dc, rcContent);
- }
- CFont fontHead;
- fontHead.CreateFont(-12, 0, 0, 0, FW_BOLD, 0, 0, 0, 134, 0, 0, 0, 2, "宋体");
- CFont* poldfont = dc.SelectObject(&fontHead);
- in_addr inaddress;
- inaddress.S_un.S_addr = m_conData.m_lAddr;
- szText.Format("%s:%d", inet_ntoa(inaddress), ntohs(m_conData.m_sPort));
- dc.DrawText(szText, rcTitle, DT_LEFT);
- dc.DrawText(m_strIPName, rcContent, DT_LEFT);
- dc.SelectObject(poldfont);
- }
- //
- rcTitle.OffsetRect(0, rcTitle.Height());
- rcContent.OffsetRect(0, rcContent.Height());
- if (!bPart || (bPart && m_bRefreshItem[ePeerId]))
- {
- if (bPart)
- {
- EraseBk(dc, rcTitle);
- EraseBk(dc, rcContent);
- }
- dc.DrawText("PeerId", rcTitle, DT_LEFT);
- szText = m_conData.m_strPeerId.data();
- dc.DrawText(szText, rcContent, DT_LEFT);
- }
- rcTitle.OffsetRect(0, rcTitle.Height());
- rcContent.OffsetRect(0, rcContent.Height());
- if (!bPart)
- {
- dc.MoveTo(GetRect().left + 20 - ptTopLeft.x, rcTitle.top);
- dc.LineTo(GetRect().right, rcTitle.top);
- }
- //
- rcTitle.OffsetRect(0, rcTitle.Height());
- rcContent.OffsetRect(0, rcContent.Height());
- if (!bPart || (bPart && m_bRefreshItem[eDownRate]))
- {
- if (bPart)
- {
- EraseBk(dc, rcTitle);
- EraseBk(dc, rcContent);
- }
- dc.DrawText("下载速度", rcTitle, DT_LEFT);
- szText = FormatSizeK(m_conData.m_lDownRate).data();
- dc.DrawText(szText, rcContent, DT_LEFT);
- }
- //
- rcTitle.OffsetRect(0, rcTitle.Height());
- rcContent.OffsetRect(0, rcContent.Height());
- if (!bPart || (bPart && m_bRefreshItem[eUpRate]))
- {
- if (bPart)
- {
- EraseBk(dc, rcTitle);
- EraseBk(dc, rcContent);
- }
- dc.DrawText("上传速度", rcTitle, DT_LEFT);
- szText = FormatSizeK(m_conData.m_lUpRate).data();
- dc.DrawText(szText, rcContent, DT_LEFT);
- }
- //
- rcTitle.OffsetRect(0, rcTitle.Height());
- rcContent.OffsetRect(0, rcContent.Height());
- if (!bPart || (bPart && m_bRefreshItem[eInterested]))
- {
- if (bPart)
- {
- EraseBk(dc, rcTitle);
- EraseBk(dc, rcContent);
- }
- if (m_conData.m_bInterested)
- {
- szText = "该点需要你的数据";
- dc.DrawText(szText, rcTitle, DT_LEFT);
- if (m_conData.m_bChoking)
- szText = "你拒绝传输数据";
- else
- szText = "你同意传输数据";
- dc.DrawText(szText, rcContent, DT_LEFT);
- }
- else
- {
- szText = "该点不需要你的数据";
- dc.DrawText(szText, rcTitle, DT_LEFT);
- }
- }
- rcTitle.OffsetRect(0, rcTitle.Height());
- rcContent.OffsetRect(0, rcContent.Height());
- if (!bPart || (bPart && m_bRefreshItem[eInteresting]))
- {
- if (bPart)
- {
- EraseBk(dc, rcTitle);
- EraseBk(dc, rcContent);
- }
- if (m_conData.m_bInteresting)
- {
- szText = "你需要该点的数据";
- dc.DrawText(szText, rcTitle, DT_LEFT);
- if (m_conData.m_bChoked)
- szText = "该点拒绝传输数据";
- else
- szText = "该点同意传输数据";
- dc.DrawText(szText, rcContent, DT_LEFT);
- }
- else
- {
- szText = "你不需要该点的数据";
- dc.DrawText(szText, rcTitle, DT_LEFT);
- }
- }
- //
- rcTitle.OffsetRect(0, rcTitle.Height());
- rcContent.OffsetRect(0, rcContent.Height());
- if (!bPart || (bPart && m_bRefreshItem[eState]))
- {
- if (bPart)
- {
- EraseBk(dc, rcTitle);
- EraseBk(dc, rcContent);
- }
- dc.DrawText("当前状态", rcTitle, DT_LEFT);
- if (m_bAbort)
- {
- szText = "已经中断";
- COLORREF colold = dc.SetTextColor(RGB(255, 0, 0));
- dc.DrawText(szText, rcContent, DT_LEFT);
- dc.SetTextColor(colold);
- }
- else
- {
- if (m_conData.m_bPaused)
- {
- szText = "暂停";
- }
- else if (m_conData.m_lDownRate > 0)
- {
- szText = "正在下载数据";
- }
- else if (m_conData.m_lUpRate > 0)
- {
- szText = "正在上传数据";
- }
- else
- {
- szText = "等待传送数据...";
- }
- // szText.Format("%.0f%%", m_conData.m_fPeerHavePercent*100);
- dc.DrawText(szText, rcContent, DT_LEFT);
- }
- }
- //
- rcTitle.OffsetRect(0, rcTitle.Height());
- rcContent.OffsetRect(0, rcContent.Height());
- if (!bPart)
- {
- dc.MoveTo(GetRect().left + 20 - ptTopLeft.x, rcTitle.top);
- dc.LineTo(GetRect().right, rcTitle.top);
- }
- //
- rcTitle.OffsetRect(0, rcTitle.Height());
- rcContent.OffsetRect(0, rcContent.Height());
- if (!bPart || (bPart && m_bRefreshItem[eDownCount]))
- {
- if (bPart)
- {
- EraseBk(dc, rcTitle);
- EraseBk(dc, rcContent);
- }
- dc.DrawText("已经下载", rcTitle, DT_LEFT);
- szText.Format("%.0f%%", m_conData.m_fPeerHavePercent*100);
- dc.DrawText(szText, rcContent, DT_LEFT);
- }
- dc.SelectObject(pOldFont);
- //
- // draw graph.
- //
- if (!bPart || (bPart && m_bRefreshItem[eSpeed]))
- {
- CRect rcSpeedGraph(450, 20, 600, 60);
- rcSpeedGraph.OffsetRect(-ptTopLeft.x, -ptTopLeft.y);
- // EraseBk(dc, rcSpeedGraph);
- PaintSpeedGraph(dc, rcSpeedGraph, false);
- }
- if (!bPart || (bPart && m_bRefreshItem[eHaves]))
- {
- // EraseBk(dc, rcSpeedGraph);
- m_graphHaveData.Draw(dc, CPoint(-ptTopLeft.x, -ptTopLeft.y));
- }
- }
- void CPeerInfo::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- m_bMonitoring = false;
- ShowWindow(false);
- m_pPeersListCtrl->ShowWindow(true);
- m_pPeersListCtrl->SetFocus();
- CScrollWndbase::OnLButtonDblClk(nFlags, point);
- CScrollWndbase::OnLButtonDblClk(nFlags, point);
- }
- void CPeerInfo::OnLButtonDown(UINT nFlags, CPoint point)
- {
- /*
- m_bMonitoring = false;
- ShowWindow(false);
- m_pPeersListCtrl->ShowWindow(true);
- m_pPeersListCtrl->SetFocus();
- CScrollWndbase::OnLButtonDblClk(nFlags, point);
- //*/
- SetFocus();
- CScrollWndbase::OnLButtonDown(nFlags, point);
- }
- void CPeerInfo::OnRButtonDown(UINT nFlags, CPoint point)
- {
- SetFocus();
- CScrollWndbase::OnRButtonDown(nFlags, point);
- }
- void CPeerInfo::ClosePeer()
- {
- if (!m_bMonitoring)
- assert(false);
- if (m_bAbort) return;
- m_bAbort = true;
- // memset(m_bRefreshItem, false, eAllCount);
- Invalidate();
- }
- void CPeerInfo::ShowPeer(const CConncetionData& conData)
- {
- m_bAbort = false;
- if (m_bMonitoring)
- {
- memset(m_bRefreshItem, false, eAllCount);
- m_bRefreshItem[eSpeed] = true;
- m_bRefreshItem[eState] = true;
- if (m_conData.m_vHave.size() != conData.m_vHave.size() ||
- (long)(m_conData.m_fPeerHavePercent * 100) != (long)(conData.m_fPeerHavePercent * 100))
- {
- m_bRefreshItem[eHaves] = true;
- m_graphHaveData.SetData(conData.m_vHave);
- }
- if (m_conData.m_lAddr != conData.m_lAddr)
- {
- m_bRefreshItem[eAddr] = true;
- m_bRefreshItem[ePeerId] = true;
- if (m_IPLocator.IsCreate())
- {
- m_strIPName.Empty();
- if (!m_IPLocator.FindIPName(ntohl(conData.m_lAddr), m_strIPName))
- {
- m_strIPName = "未知IP地址";
- }
- }
- }
- if (m_conData.m_lDownRate != conData.m_lDownRate )
- {
- m_bRefreshItem[eDownRate] = true;
- }
- if (m_conData.m_lUpRate != conData.m_lUpRate)
- {
- m_bRefreshItem[eUpRate] = true;
- }
- if (m_conData.m_lDownCount != conData.m_lDownCount)
- {
- m_bRefreshItem[eDownCount] = true;
- }
- if (m_conData.m_lDownRate != conData.m_lDownRate )
- {
- m_bRefreshItem[eDownRate] = true;
- }
- if (m_conData.m_lDownRate != conData.m_lDownRate )
- {
- m_bRefreshItem[eDownRate] = true;
- }
- if (m_conData.m_bInterested != conData.m_bInterested ||
- m_conData.m_bChoking != conData.m_bChoking)
- {
- m_bRefreshItem[eInterested] = true;
- }
- if (m_conData.m_bInteresting != conData.m_bInteresting ||
- m_conData.m_bChoked != conData.m_bChoked)
- {
- m_bRefreshItem[eInteresting] = true;
- }
- }
- //*/
- m_conData = conData;
- if (!m_bMonitoring)
- {
- if (m_IPLocator.IsCreate())
- {
- m_strIPName.Empty();
- if (!m_IPLocator.FindIPName(ntohl(conData.m_lAddr), m_strIPName))
- {
- m_strIPName = "未知IP地址";
- }
- }
- m_graphHaveData.SetData(m_conData.m_vHave);
- Invalidate();
- if (GetTopLeft() != CPoint(0, 0))
- ResetPos();
- }
- else
- {
- CClientDC dc(this);
- DrawItem(dc, true);
- }
- m_bMonitoring = true;
- }
- bool CPeerInfo::IsMonitoring()
- {
- return m_bMonitoring;
- }
- void CPeerInfo::PaintSpeedGraph(CDC& dc, CRect rc, bool bShowText)
- {
- //
- // Get rect.
- //
- CRect rcText = rc;
- rcText.bottom = rcText .top + 10;
- DrawFace(RGB(255, 255, 255), RGB(213, 232, 245), rc, rc, &dc);
- CRect rcUp = rc;
- rcUp.top += 10;
- rcUp.bottom -= 2;
- if (rc.Width() < 100)
- bShowText = false;
- if (bShowText)
- {
- rcUp.bottom -= 20;
- }
- // rcUp.right = rcUp.left + rcUp.Width()/2;
- CRect rcDown = rcUp;
- // rcUp.OffsetRect(rcUp.Width(), 0);
- CRect rcSpeed = rc;
- rcSpeed.top = rcSpeed.bottom - 20;
- CRect rcSpeedFrame = rcSpeed;
- rcSpeed.right = rcSpeed.left + rcSpeed.Width()/2;
- //
- // Get max value.
- //
- int iVisibleCount = rcUp.Width()/m_lGridWidth + 1;
- long lMax = 5;
- long lRet = GetMaxValue(m_conData.m_lValueUp, iVisibleCount);
- if (lRet > lMax ) lMax = lRet;
- lRet = GetMaxValue(m_conData.m_lValueDown, iVisibleCount);
- if (lRet > lMax ) lMax = lRet;
- if (lMax %5)
- lMax = (lMax/5 + 1) * 5;
- assert (lMax > 0);
- //
- // ShowText
- //
- dc.SetBkMode(TRANSPARENT);
- CFont* pOldFont = dc.SelectObject(&m_font);
- CString strText;
- strText.Format("%dK/S", lMax);
- dc.SetTextColor(RGB(0, 0, 0));
- dc.DrawText(strText, rcText, DT_RIGHT|DT_VCENTER|DT_SINGLELINE);
- dc.SelectObject(pOldFont);
- //
- // draw graph.
- //
- DrawLine(m_conData.m_lValueDown, dc, RGB(125, 172, 249), rcDown, lMax , iVisibleCount);
- DrawLine(m_conData.m_lValueUp, dc, RGB(249, 152, 111), rcUp, lMax, iVisibleCount);
- //
- // draw splitter.
- //
- CPen curPen;
- curPen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
- CPen* pOldPen = dc.SelectObject(&curPen);
- if (bShowText)
- {
- dc.MoveTo(rcSpeedFrame.left, rcSpeedFrame.top);
- dc.LineTo(rcSpeedFrame.right, rcSpeedFrame.top);
- }
- dc.MoveTo(rcUp.right, rcUp.bottom);
- dc.LineTo(rcUp.right, rc.top);
- dc.SelectObject(pOldPen);
- dc.Draw3dRect(rc, RGB(0, 0, 0), RGB(0,0,0));
- }
- long CPeerInfo::GetMaxValue( long lValue[], long lCount)
- {
- long lMax = 5;
- long lDone = 0;
- for (int i=m_conData.m_lIndex; i<CConnection::eCount; i++)
- {
- if (lValue[i] > lMax)
- lMax = lValue[i];
- if (++lDone > lCount)
- return lMax;
- }
- for (i=0; i<m_conData.m_lIndex; i++)
- {
- if (lValue[i] > lMax)
- lMax = lValue[i];
- if (++lDone > lCount)
- return lMax;
- }
- return lMax;
- }
- void CPeerInfo::DrawLine(long lValue[], CDC& dc, COLORREF cor, CRect& rc, long lMax, long iVisibleCount)
- {
- if (lMax <= 0)
- {
- assert(false);
- return;
- }
- long lDone = 0;
- long ileft = rc.left;
- int iHeight = rc.Height();
- float fUnit = (float)iHeight / lMax ;
- if (iHeight < 0)
- return;
- CPen curPen;
- curPen.CreatePen(PS_SOLID, 1, cor);
- CPen* pOldPen = dc.SelectObject(&curPen);
- dc.MoveTo(ileft, rc.bottom - (long)(lValue[m_conData.m_lIndex] * fUnit));
- ileft += m_lGridWidth;
- for (int i=m_conData.m_lIndex + 1; i<CConnection::eCount; i++)
- {
- if (lDone++ > iVisibleCount)
- break;
- dc.LineTo(ileft, rc.bottom - (long)(lValue[i] * fUnit));
- dc.MoveTo(ileft, rc.bottom - (long)(lValue[i] * fUnit));
- ileft += m_lGridWidth;
- }
- for (i=0; i<m_conData.m_lIndex; i++)
- {
- if (lDone++ > iVisibleCount)
- break;
- dc.LineTo(ileft, rc.bottom - (long)(lValue[i] * fUnit));
- dc.MoveTo(ileft, rc.bottom - (long)(lValue[i] * fUnit));
- ileft += m_lGridWidth;
- }
- dc.SelectObject(pOldPen);
- }
- void CPeerInfo::DrawFace(COLORREF Top, COLORREF Bottom, CRect& rc, CRect CalRc, CDC* pDC)
- {
- if (!CalRc.Height())
- return;
- int R, G, B;
- R = (GetRValue(Top) - GetRValue(Bottom)) / CalRc.Height();
- G = (GetGValue(Top) - GetGValue(Bottom)) / CalRc.Height();
- B = (GetBValue(Top) - GetBValue(Bottom)) / CalRc.Height();
- int ColR = GetRValue(Top), ColG = GetGValue(Top), ColB = GetBValue(Top);
- COLORREF ColMax = Top > Bottom ? Top : Bottom;
- COLORREF ColMin = Top > Bottom ? Bottom: Top;
- for(int i=0; i<rc.Height(); i++)
- {
- ColR -= R;
- ColG -= G;
- ColB -= B;
- CPen Pen;
- Pen.CreatePen(PS_SOLID, 1, RGB(ColR, ColG, ColB));
- CPen* pOldPen = pDC->SelectObject(&Pen);
- // pDC->SelectObject(&Pen);
- pDC->MoveTo(rc.left, rc.top+i);
- pDC->LineTo(rc.right, rc.top+i);
- pDC->SelectObject(pOldPen);
- Pen.DeleteObject();
- }
- }
- CString CPeerInfo::GetDefaultModulePath()
- {
- // get the directory in which the exe file exist.
- char szModuleFileName[1024] = {0};
- if (!GetModuleFileName(AfxGetApp()->m_hInstance, szModuleFileName, 1024))
- {
- assert(false);
- return "";
- }
- char path_buffer[_MAX_PATH];
- char drive[_MAX_DRIVE];
- char dir[_MAX_DIR];
- char fname[_MAX_FNAME];
- char ext[_MAX_EXT];
- _splitpath(szModuleFileName, drive, dir, fname, ext );
- _makepath(path_buffer, drive, dir, 0, 0);
- string strDatabasePath = path_buffer;
- if (strDatabasePath.size() <= 0)
- {
- assert(false);
- return "";
- }
- if (strDatabasePath[strDatabasePath.size() - 1] != '\')
- strDatabasePath+= '\';
- strDatabasePath += "ip.dat";
- return strDatabasePath.data();
- }
- void CPeerInfo::OnContextMenu(CWnd* pWnd, CPoint point)
- {
- bool bContinue = false, bPause = false, bClose = false;
- CMenu menu_bar;
- menu_bar.CreatePopupMenu();
- if (m_bMonitoring)
- {
- if (!m_bAbort)
- {
- bContinue = m_conData.m_bPaused ? true : false;
- bPause = m_conData.m_bPaused ? false : true;
- bClose = true;
- }
- else
- {
- bContinue = bPause = bClose = false;
- }
- menu_bar.AppendMenu(MF_STRING, ID_MENUITEM_SHOW_PEERS_LIST, "返回到连接列表(&B)t");
- menu_bar.AppendMenu(MF_SEPARATOR);
- menu_bar.AppendMenu(MF_STRING, ID_MENUITEM_CONTINUE_PEERS, "继续选中的连接(&X)t");
- menu_bar.AppendMenu(MF_STRING, ID_MENUITEM_PAUSE_PEERS, "暂停选中的连接(&P)t");
- menu_bar.AppendMenu(MF_STRING, ID_MENUITEM_STOP_PEERS, "关闭选中的连接(&Q)t");
- menu_bar.EnableMenuItem(ID_MENUITEM_SHOW_PEERS_LIST, MF_BYCOMMAND | MF_ENABLED);
- menu_bar.EnableMenuItem(ID_MENUITEM_CONTINUE_PEERS, MF_BYCOMMAND |
- (bContinue ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
- menu_bar.EnableMenuItem(ID_MENUITEM_PAUSE_PEERS, MF_BYCOMMAND |
- (bPause ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
- menu_bar.EnableMenuItem(ID_MENUITEM_STOP_PEERS, MF_BYCOMMAND |
- (bClose ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
- }
- CPoint posMouse;
- GetCursorPos(&posMouse);
- menu_bar.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON,posMouse.x,posMouse.y,this);
- }
- void CPeerInfo::OnMenuItemPeers(UINT uID)
- {
- if (!m_bMonitoring || !m_pPeersListCtrl || (m_bAbort&& uID != ID_MENUITEM_SHOW_PEERS_LIST))
- {
- assert(false);
- return;
- }
- switch (uID)
- {
- case ID_MENUITEM_CONTINUE_PEERS:
- {
- assert(m_conData.m_bPaused);
- m_conData.m_bPaused = false;
- ShowPeer(m_conData);
- }
- break;
- case ID_MENUITEM_PAUSE_PEERS:
- {
- assert(!m_conData.m_bPaused);
- m_conData.m_bPaused = true;
- ShowPeer(m_conData);
- }
- break;
- case ID_MENUITEM_STOP_PEERS:
- {
- ClosePeer();
- }
- break;
- case ID_MENUITEM_SHOW_PEERS_LIST:
- {
- m_bMonitoring = false;
- ShowWindow(false);
- m_pPeersListCtrl->ShowWindow(true);
- m_pPeersListCtrl->SetFocus();
- return;
- }
- break;
- default:
- {
- assert(false);
- return;
- }
- }
- m_pPeersListCtrl->OnMenuItemPeerInfo(uID, m_conData);
- }