www.pudn.com > seedesk.zip > BossSeeClientView.cpp


// BossSeeClientView.cpp : implementation of the CBossSeeClientView class 
// 
/*************************************************************************** 
 *        Module               :                             * 
 *         
 *                                                                         * 
 *        Created by           : ??      Date  : 2004.9.12        * 
 *        Modified by          :                  Date  :                  * 
 *                                                                         *  
 *                   *  
 ***************************************************************************/ 
#include "stdafx.h" 
#include "BossSeeClient.h" 
#include "SetTimeDlg.h"  
#include "BossSeeClientDoc.h" 
#include "BossSeeClientView.h" 
#include "AddIPDlg.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
extern BITMAP btm; 
extern char* lpData; 
///////////////////////////////////////////////////////////////////////////// 
// CBossSeeClientView 
 
IMPLEMENT_DYNCREATE(CBossSeeClientView, CTreeView) 
 
BEGIN_MESSAGE_MAP(CBossSeeClientView, CTreeView) 
	//{{AFX_MSG_MAP(CBossSeeClientView) 
	ON_COMMAND(ID_TEST_CATCH, OnGetScreen) 
	ON_WM_TIMER() 
	ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk) 
	ON_COMMAND(ID_ADD_IP, OnAddIp) 
	ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick) 
	ON_COMMAND(ID_DELETE_ITEMCOMPUTER, OnDeleteItemcomputer) 
	ON_COMMAND(ID_CONFIG_SELCOMPUTER, OnConfigSelcomputer) 
    ON_COMMAND(ID_STOP,OnStop) 
	ON_COMMAND(ID_START,OnStart) 
    ON_COMMAND(ID_KILL,OnKill) 
	ON_COMMAND(ID_MY_HELP,OnMyHelp) 
	//}}AFX_MSG_MAP 
	// Standard printing commands 
	ON_COMMAND(ID_FILE_PRINT, CTreeView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CTreeView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CTreeView::OnFilePrintPreview) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CBossSeeClientView construction/destruction 
 
CBossSeeClientView::CBossSeeClientView() 
{ 
	// TODO: add construction code here 
   m_strSelIP="";  
   m_hTreeItemLastSel=NULL; 
   m_iTimer=1500; 
} 
 
CBossSeeClientView::~CBossSeeClientView() 
{ 
} 
 
BOOL CBossSeeClientView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	 if(!CTreeView::PreCreateWindow(cs)) return FALSE; 
	 cs.style|=TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS|TVS_SHOWSELALWAYS;  
	 return true; 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CBossSeeClientView drawing 
 
void CBossSeeClientView::OnDraw(CDC* pDC) 
{ 
	CBossSeeClientDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here 
} 
 
void CBossSeeClientView::OnInitialUpdate() 
{ 
	CTreeView::OnInitialUpdate(); 
    il.Create(IDB_BITMAP1,16,1,RGB(0,255,0)); 
	CBitmap bitmap; 
	bitmap.LoadBitmap(IDB_BITMAP2); 
	il.Add(&bitmap,RGB(0,255,0)); 
    GetTreeCtrl().SetImageList(&il,TVSIL_NORMAL);//设置小图标treeview 
      HTREEITEM Htest1=GetTreeCtrl().InsertItem(_T("127.0.0.1"),0,0,TVI_ROOT,TVI_LAST);//插入默认选项 
	  HTREEITEM Htest2=GetTreeCtrl().InsertItem(_T("222.20.41.61"),0,0,TVI_ROOT,TVI_LAST); 
	// TODO: You may populate your TreeView with items by directly accessing 
	//  its tree control through a call to GetTreeCtrl(). 
	   
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CBossSeeClientView printing 
 
BOOL CBossSeeClientView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CBossSeeClientView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CBossSeeClientView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CBossSeeClientView diagnostics 
 
#ifdef _DEBUG 
void CBossSeeClientView::AssertValid() const 
{ 
	CTreeView::AssertValid(); 
} 
 
void CBossSeeClientView::Dump(CDumpContext& dc) const 
{ 
	CTreeView::Dump(dc); 
} 
 
CBossSeeClientDoc* CBossSeeClientView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBossSeeClientDoc))); 
	return (CBossSeeClientDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CBossSeeClientView message handlers 
 
void CBossSeeClientView::OnGetScreen()  
{   //通过网络获得bitmap的信息填写lpdata 
	// TODO: Add your command handler code here 
 
 
	if(m_pRecBMPSocket==NULL) return; 
	if(lpData!=NULL) 
	{delete lpData;lpData=NULL;} 
	char MSGTYPE1[30]="B"; 
      
   int BTMInfoSize=24; 
   char BTMInfoBuf[24]; 
    m_pRecBMPSocket->Send(MSGTYPE1,30); 
     int ret=m_pRecBMPSocket->Receive(BTMInfoBuf,sizeof(BITMAP)); 
	if (ret!=24) 
	{	MessageBox("failed recive 24"); return;} 
	BITMAP *BTMBUF=(BITMAP *)BTMInfoBuf; 
	btm.bmBits=BTMBUF->bmBits; 
    btm.bmBitsPixel=BTMBUF->bmBitsPixel; 
	btm.bmHeight=BTMBUF->bmHeight; 
	btm.bmPlanes=BTMBUF->bmPlanes; 
	btm.bmType=BTMBUF->bmType; 
	btm.bmWidth=BTMBUF->bmWidth; 
    btm.bmWidthBytes=BTMBUF->bmWidthBytes; 
	char MSGTYPE2[30]="D"; 
	m_pRecBMPSocket->Send(MSGTYPE2,30); 
    int size=btm.bmWidthBytes*btm.bmHeight; 
	lpData=new char[size]; 
    if(lpData==NULL) 
		MessageBox("faile memery"); 
	char *pch=lpData ; 
	int nBytesRec=0; 
	int nBytesThisTime; 
	do{                               //发送的内容较大采用循环发送完成为止 
	  nBytesThisTime=m_pRecBMPSocket->Receive(pch,size-nBytesRec); 
	  nBytesRec+=nBytesThisTime; 
	  pch+=nBytesThisTime; 
	}while(nBytesRecUpdateAllViews(NULL,NULL,NULL);//更新视图 
	///////////////////////////////////// 
	 
 
} 
 
 
 
void CBossSeeClientView::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
   if(nIDEvent==1) 
   {if(m_pRecBMPSocket!=NULL)OnGetScreen() ;}//单击树控件时会发生timer事件 
		 
	///////////////////////////////////// 
	CTreeView::OnTimer(nIDEvent); 
} 
 
 
 
void CBossSeeClientView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	 
	HTREEITEM hSelItem=GetTreeCtrl().GetSelectedItem(); 
	GetTreeCtrl().SetItemImage(hSelItem,0,1); //双击时使图像变色 
   CString strtemp=GetTreeCtrl().GetItemText(hSelItem); 
   //m_strtemp.Replace("连接上..",""); 
	if(m_strSelIP!=strtemp) 
    {   m_strSelIP=strtemp; 
		m_pRecBMPSocket=new CSocket; 
		 
     m_pRecBMPSocket->Create(); 
	 if(!m_pRecBMPSocket->Connect(m_strSelIP,2502)) 
	{ 
	 MessageBox("连接失败"); 
	 delete m_pRecBMPSocket ; 
	 m_pRecBMPSocket=NULL; 
	 return; 
	}  
	 if(m_hTreeItemLastSel!=NULL) 
	 { GetTreeCtrl().SetItemImage(m_hTreeItemLastSel,0,0); 
	    CString strLastText=GetTreeCtrl().GetItemText(m_hTreeItemLastSel); 
        strLastText.Replace("..连接上..",""); 
		GetTreeCtrl().SetItemText(m_hTreeItemLastSel,strLastText);} 
	//连接成功时加上连接上的字符 
	GetTreeCtrl().SetItemText(hSelItem,m_strSelIP+"..连接上.."); 
	m_hTreeItemLastSel=hSelItem; 
	SetTimer(1,m_iTimer,NULL);	}//初始化定时时间 
	 
	*pResult = 0; 
} 
 
void CBossSeeClientView::OnAddIp()  
{//添加ip 
	// TODO: Add your command handler code here 
	CAddIPDlg ipDlg; 
	if((ipDlg.DoModal()==IDOK)&&(ipDlg.m_strAddIP!=""))// 
   
		GetTreeCtrl().InsertItem(ipDlg.m_strAddIP,0,0,TVI_ROOT,TVI_LAST); 
     
} 
 
 
 
 
 
 
 
 
 
 
 
void CBossSeeClientView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	//点右键弹出菜单 
	HTREEITEM hSelItem=GetTreeCtrl().GetSelectedItem(); 
	 
   CString strtemp=GetTreeCtrl().GetItemText(hSelItem); 
   strtemp.Replace("..连接上..",""); 
   if(strtemp!="") 
   { CMenu pop, *pMenu; 
     POINT pt; 
     GetCursorPos(&pt); 
	 pop.LoadMenu(IDR_POPMENU); 
     pMenu = pop.GetSubMenu(0); 
	 if(m_strSelIP==strtemp) 
		 pMenu->EnableMenuItem(ID_DELETE_ITEMCOMPUTER,MF_GRAYED );//删除没有连接的主机 
	 else 
         pMenu->EnableMenuItem(ID_CONFIG_SELCOMPUTER,MF_GRAYED );//设置连接上 的主机 
	pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 
											this, NULL); 
		 
			 
   }	 
			 
			 
			 
			 
	*pResult = 0; 
} 
 
void CBossSeeClientView::OnDeleteItemcomputer()  
{   //删除树中的某项 
	// TODO: Add your command handler code here 
	HTREEITEM hSelItem=GetTreeCtrl().GetSelectedItem(); 
    GetTreeCtrl().DeleteItem(hSelItem); 
} 
 
void CBossSeeClientView::OnConfigSelcomputer()  
{ 
	// TODO: Add your command handler code here 
  CSetTimeDlg timeDlg; 
 
   if(timeDlg.DoModal()==IDOK) 
   {    
	   if(timeDlg.m_iTimer<1000) 
	   {MessageBox("时间设置过短");return;}//填入的时间必须大于1秒 
	   KillTimer(1); 
	   m_iTimer=timeDlg.m_iTimer; 
   HTREEITEM hSelItem=GetTreeCtrl().GetSelectedItem(); 
   CString strtemp=GetTreeCtrl().GetItemText(hSelItem); 
   strtemp.Replace("..连接上..",""); 
   m_pRecBMPSocket->Close(); 
   if(m_pRecBMPSocket!=NULL) 
	   m_pRecBMPSocket=NULL;//删除原来的套节字 
   m_pRecBMPSocket=new CSocket; 
		 
     m_pRecBMPSocket->Create(); 
	 if(!m_pRecBMPSocket->Connect(m_strSelIP,2502)) 
	{ 
	 MessageBox("连接失败"); 
	 delete m_pRecBMPSocket ; 
	 m_pRecBMPSocket=NULL; 
	 return; 
	}  
    
   SetTimer(1,m_iTimer,NULL);} 
} 
void CBossSeeClientView::OnStart() 
{MessageBox("start");} 
void  CBossSeeClientView::OnStop() 
{MessageBox("stop");} 
 
void CBossSeeClientView::OnKill() 
{ 
MessageBox("kill"); 
} 
 
void CBossSeeClientView::OnMyHelp() 
{ 
MessageBox("help"); 
}