⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cxferwindow.cpp

📁 vc环境下的pgp源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*____________________________________________________________________________
	Copyright (C) 1996-1999 Network Associates, Inc.
	All rights reserved.

	$Id: CXferWindow.cpp,v 1.11 1999/03/10 02:42:04 heller Exp $
____________________________________________________________________________*/
#include "StdAfx.h"
#include <string.h>

#define INITGUID
#include <shlobj.h>
#undef INITGUID

#include <shellapi.h>
#include <Afxcmn.h>

#include "PGPFone.h"
#include "CPGPFone.h"
#include "PGPFWinUtils.h"
#include "CXferWindow.h"
#include "CMessageQueue.h"
#include "CWinFilePipe.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define REFRESH_TIMER 1000

static char szNoSend[]="Drop files or folders to send.";
static char szNoRecv[]="Nothing to receive.";

extern CPGPFoneApp theApp;

typedef struct ItemInfo
{	
	union
	{
		XRcvFile* xrf;
		XSendFile* xsf;
	}xf;
	
	int iconIndex;
}ItemInfo;

#define  xsf xf.xsf 
#define  xrf xf.xrf 

/////////////////////////////////////////////////////////////////////////////
// CXferWindow dialog


CXferWindow::CXferWindow()
{
	//{{AFX_DATA_INIT(CXferWindow)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	
	mXferQueue 		= NULL;
	mXfer 			= NULL;
	mNumSends 		= 0;
	mNumReceives 	= 0;
	mSendXferInfo	= NULL;
	mRecvXferInfo	= NULL;
	
}


void CXferWindow::DoDataExchange(CDataExchange* pDX)
{
	CWnd::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CXferWindow)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


/////////////////////////////////////////////////////////////////////////////
// CXferWindow message handlers

int CXferWindow::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	HFONT hFont = (HFONT)GetStockObject( DEFAULT_GUI_FONT ); 
	
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	InitializeCriticalSection(&mSendCriticalSection);
	InitializeCriticalSection(&mRecvCriticalSection);
	
	const RECT rSendGroup 		= {6, 	0, 	180, 101};
	const RECT rRecvGroup 		= {178, 0, 	353, 101};
	const RECT rSendList 		= {5, 	106,178, 260};
	const RECT rRecvList		= {180, 106,354, 260};
	const RECT rSendProgress 	= {30, 	54, 155, 69};
	const RECT rRecvProgress	= {201, 54, 326, 69};
	const RECT rSendCancel 		= {63, 	75, 122, 96};
	const RECT rRecvCancel		= {235, 75, 294, 96};
	const RECT rSendFile 		= {30, 	15, 170, 28};
	const RECT rRecvFile		= {201, 15, 341, 28};
	const RECT rSendSize 		= {30, 	35, 170, 48};
	const RECT rRecvSize		= {201, 35, 341, 48};
	
	mSendGroup.Create(	"Send",
						WS_CHILD|WS_VISIBLE|BS_GROUPBOX,
						rSendGroup,
						this, IDC_STATIC);
						
	mSendGroup.SendMessage(WM_SETFONT, (WPARAM)hFont, FALSE);	
					
	mRecvGroup.Create(	"Receive",
						WS_CHILD|WS_VISIBLE|BS_GROUPBOX,
						rRecvGroup,
						this, IDC_STATIC);
						
	mRecvGroup.SendMessage(WM_SETFONT, (WPARAM)hFont, FALSE);	
						
	mSendCancel.Create(	"Cancel",
						WS_CHILD|WS_VISIBLE,
						rSendCancel,
						this, ID_CANCEL_SEND);
						
	mSendCancel.SendMessage(WM_SETFONT, (WPARAM)hFont, FALSE);	
					
	mRecvCancel.Create(	"Cancel",
						WS_CHILD|WS_VISIBLE,
						rRecvCancel,
						this, ID_CANCEL_RECV);
						
	mRecvCancel.SendMessage(WM_SETFONT, (WPARAM)hFont, FALSE);
	
	mSendList.CreateEx( WS_EX_CLIENTEDGE,
						WC_LISTVIEW,
						"",
						LVS_SMALLICON | LVS_SINGLESEL | 
						WS_BORDER | WS_TABSTOP | WS_VISIBLE |
						WS_VISIBLE | WS_CHILD, 
						rSendList.left,
						rSendList.top,
						rSendList.right - rSendList.left,
						rSendList.bottom -rSendList.top,
						GetSafeHwnd(), 
						(HMENU)IDC_SEND_LIST, 
						NULL);
						
	mSendList.SendMessage(WM_SETFONT, (WPARAM)hFont, FALSE);
	
	mRecvList.CreateEx( WS_EX_CLIENTEDGE,
						WC_LISTVIEW,
						"",
						LVS_SMALLICON | LVS_SINGLESEL | 
						WS_BORDER | WS_TABSTOP | WS_VISIBLE |
						WS_VISIBLE | WS_CHILD, 
						rRecvList.left,
						rRecvList.top,
						rRecvList.right - rRecvList.left,
						rRecvList.bottom - rRecvList.top,
						GetSafeHwnd(), 
						(HMENU)IDC_RECV_LIST, 
						NULL);
						
	mRecvList.SendMessage(WM_SETFONT, (WPARAM)hFont, FALSE);
						
	mSendSmallImageList.Create( 16, 16, 
								ILC_MASK|ILC_COLOR8, 
								5, 1024 );
								
	mRecvSmallImageList.Create( 16, 16, 
								ILC_MASK|ILC_COLOR8, 
								5, 1024 );
								
	mSendList.SetImageList(&mSendSmallImageList, LVSIL_SMALL);
	mRecvList.SetImageList(&mRecvSmallImageList, LVSIL_SMALL);
						
	mSendFile.Create(	"",
						WS_CHILD|WS_VISIBLE,
						rSendFile, this, IDC_SEND_FILE);
						
	mSendFile.SendMessage(WM_SETFONT, (WPARAM)hFont, FALSE);
	
	mRecvFile.Create(	"",
						WS_CHILD|WS_VISIBLE,
						rRecvFile, this, IDC_RECV_FILE);
						
	mRecvFile.SendMessage(WM_SETFONT, (WPARAM)hFont, FALSE);
						
	mSendSize.Create(	"",
						WS_CHILD|WS_VISIBLE,
						rSendSize, this, IDC_SEND_SIZE);
						
	mSendSize.SendMessage(WM_SETFONT, (WPARAM)hFont, FALSE);
						
	mRecvSize.Create(	"",
						WS_CHILD|WS_VISIBLE,
						rRecvSize, this, IDC_RECV_SIZE);
						
	mRecvSize.SendMessage(WM_SETFONT, (WPARAM)hFont, FALSE);	
				
	mSendProgress.Create( 	WS_CHILD|WS_VISIBLE,
							rSendProgress, this, IDC_SEND_PROGRESS);
						
	mSendProgress.SendMessage(WM_SETFONT, (WPARAM)hFont, FALSE);
						
	mRecvProgress.Create(	WS_CHILD|WS_VISIBLE,
							rRecvProgress, this, IDC_RECV_PROGRESS);
						
	mRecvProgress.SendMessage(WM_SETFONT, (WPARAM)hFont, FALSE);					
	
	mSendFile.SetWindowText(szNoSend);
	mSendSize.SetWindowText("");
	mSendProgress.SetRange(0, 100);
	mSendProgress.SetPos(0);
	
	mRecvFile.SetWindowText(szNoRecv);
	mRecvSize.SetWindowText("");
	mRecvProgress.SetRange(0, 100);
	mRecvProgress.SetPos(0);
	
	SetTimer(REFRESH_TIMER, 1000, NULL ); // refresh display each second
	
	return 0;
}


BOOL CXferWindow::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	switch(LOWORD(wParam))
	{
		case ID_CANCEL_RECV:
		{
			if(mRecvXferInfo)
			{
				mXferQueue->Send(_mt_abortReceive);
			}
		}
		
		case ID_CANCEL_SEND:
		{
			if(mSendXferInfo)
			{
				mXferQueue->Send(_mt_abortSend);
			}
		}
	}
	
	return CWnd::OnCommand(wParam, lParam);
}

void CXferWindow::OnDropFiles(HDROP hDropInfo) 
{
	UINT numFiles, count;
	char szFilePath[MAX_PATH + 1];
	XferFileSpec fs;
	
	numFiles = DragQueryFile( 	hDropInfo, 
								-1,
								szFilePath,
								sizeof(szFilePath));
							
	count = 0;
								
	while(count < numFiles)
	{
		DragQueryFile( 	hDropInfo, 
						count,
						szFilePath,
						sizeof(szFilePath));
						
		if(!strcmp((szFilePath + strlen(szFilePath) - 4), ".lnk"))
		{
			char szLinkFile[MAX_PATH + 1];
			
			strcpy(szLinkFile, szFilePath);
		
			ResolveLink(szLinkFile, szFilePath);
		}
		
		strcpy(fs.path, szFilePath);
		
		fs.filename = strrchr(fs.path, '\\' );
		fs.filename++;
				
		if(FileIsAFolder(szFilePath))
		{
			fs.root = fs.filename;
			
			SendFolder(&fs);
		}
		else
		{
			fs.root = NULL;
			SendFile(&fs);
		}

		count++;
	}
	
	CWnd::OnDropFiles(hDropInfo);
}

void CXferWindow::OnDestroy() 
{
	int index;
	KillTimer( REFRESH_TIMER );
	
	EnterCriticalSection(&mSendCriticalSection);
	EnterCriticalSection(&mRecvCriticalSection);
	
	int count = mSendList.GetItemCount();
	
	ItemInfo* info;
	
	for(index = 0; index < count; index++)
	{
		info = (ItemInfo*) mSendList.GetItemData(index);

		if( info )
		{
			delete info;
		}
	}
	
	count = mRecvList.GetItemCount();
	
	for(index = 0; index < count; index++)
	{
		info = (ItemInfo*) mRecvList.GetItemData(index);

		if( info )
		{
			delete info;
		}
	}

	
	mSendList.DeleteAllItems();
	mRecvList.DeleteAllItems();
	
	mSendSmallImageList.DeleteImageList();					
	mRecvSmallImageList.DeleteImageList();
	
	DeleteCriticalSection(&mSendCriticalSection);
	DeleteCriticalSection(&mRecvCriticalSection);
								
	CWnd::OnDestroy();
}

void CXferWindow::OnClose() 
{
	ShowWindow(SW_HIDE);
}


void CXferWindow::OnTimer(UINT TimerID)
{
	switch(TimerID)
	{
		case REFRESH_TIMER:
		{
			char string[256];
			float percentDone;
			
			EnterCriticalSection(&mSendCriticalSection);
		
			if(mSendXferInfo)
			{
				percentDone = 	((float)mSendXferInfo->bytesDone)/
								((float)mSendXferInfo->bytesTotal)*100;
				
				if(mSendXferInfo->bytesTotal < 1024)
				{
					wsprintf(string,"%lu of %lu Bytes (%d%%)", 
									mSendXferInfo->bytesDone, 
									mSendXferInfo->bytesTotal,
									(int)percentDone);
				}
				else
				{
					wsprintf(string,"%lu of %lu K (%d%%)", 
									mSendXferInfo->bytesDone/1024, 
									mSendXferInfo->bytesTotal/1024,
									(int)percentDone);			
				}
				
				mSendSize.SetWindowText(string);
		
				mSendProgress.SetPos( (int)percentDone );
			}
			
			if(!mNumSends)
			{	
				int count = mSendSmallImageList.GetImageCount();
				
				for(int i = 0; i < count; i++)
				{
					mSendSmallImageList.Remove(i);
				}
			}
			
			LeaveCriticalSection(&mSendCriticalSection);
			
			EnterCriticalSection(&mRecvCriticalSection);
			
			if(mRecvXferInfo)
			{
				percentDone = 	((float)mRecvXferInfo->bytesDone)/
								((float)mRecvXferInfo->bytesTotal)*100;
				
				if(mRecvXferInfo->bytesTotal < 1024)
				{
					wsprintf(string,"%lu of %lu Bytes (%d%%)", 
									mRecvXferInfo->bytesDone, 
									mRecvXferInfo->bytesTotal,
									(int)percentDone);
				}
				else
				{
					wsprintf(string,"%lu of %lu K (%d%%)", 
									mRecvXferInfo->bytesDone/1024, 
									mRecvXferInfo->bytesTotal/1024,
									(int)percentDone);						
				}
				
				mRecvSize.SetWindowText(string);
		
				mRecvProgress.SetPos((int)percentDone );
			}
			
			if(!mNumReceives)
			{
				int count = mRecvSmallImageList.GetImageCount();
				
				for(int i = 0; i < count; i++)
				{
					mRecvSmallImageList.Remove(i);
				}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -