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

📄 copyfilename.cpp

📁 这是一本学习 window编程的很好的参考教材
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// CopyFileName.cpp : Implementation of CCopyFileName

#include "stdafx.h"
#include "CopyFileName.h"
// CCopyFileName
#include "file2eth.h"

int g_nCount;
#ifdef DEBUG
	#define dbg_log MyTrace
#else
   #define dbg_log   __noop
#endif

typedef struct tagFileName{
	TCHAR szFileName[MAX_PATH];
}FILENAME,*PFILENAME;
PFILENAME  g_szFileNameArray;


TCHAR g_szCurDir[MAX_PATH+1];
DWORD g_dwIP;
DWORD g_ID;
TCHAR 	g_szLocalName[256];

HANDLE g_hQuitServiceEvent=NULL;
CSHProgressWnd* pDlg=NULL;
BOOL bEndSend=FALSE;
DWORD SendFile(TCHAR * szFileName)
{

	TCHAR szMsg[1024];
	__try{
		sendfile(pDlg,szFileName,g_ID);
		//	HANDLE hFile=CreateFile(szFileName,
		//		GENERIC_READ,
		//		FILE_SHARE_READ,
		//		NULL,
		//		OPEN_EXISTING,
		//		FILE_ATTRIBUTE_NORMAL,
		//		NULL);
		//	if(hFile==INVALID_HANDLE_VALUE)return 0;
		//	DWORD dwHigh;
		//	DWORD dwFileLen=GetFileSize(hFile,&dwHigh);
		//	pDlg->SetLineText(1,szFileName);

		//	pDlg->UpdateProgress ( 0, dwFileLen );

		//	PacketInfo pi;
		//	ZeroMemory((void*)&pi,DATA_LEN);
		//	pi.dwFlag=FILE_HEADER_FLAG;
		//	pi.dwLen=sizeof(FILE_HEADER);
		//	pi.fh.dwFileLen=dwFileLen;


		//	_tcscpy(pi.fh.szFileName,szFileName+_tcslen(g_szCurDir)+1);
		//	DWORD dwCheckSum=checksum((BYTE*)pi.fh.szFileName,_tcslen(pi.fh.szFileName));
		//	pi.fh.dwFileHash=dwCheckSum;
		//	int writelen,i=0;
		//	//char buff[DATA_LEN];
		//	BOOL bInputEnd=FALSE;
		//	DWORD dwWaitResult; 
		//	pi.ID=g_ID;
		//	writelen=SendData((char*)&pi,DATA_LEN);
		//	pi.dwFlag=FILE_BODY_FLAG;
		//	pi.dwLen=sizeof(FILE_BODY);
		//	pi.fb.dwFileHash=dwCheckSum;
		//	
		//	DWORD dwCount=0;
		//	pi.fb.dwFilePos=dwCount;
		//	while(!bInputEnd)
		//	{
		//		if (pDlg->HasUserCanceled()) {
		//			bInputEnd=TRUE;
		//			bEndSend=TRUE;
		//			pDlg->EndDialog();
		//			goto exit;
		//		}
		//		DWORD dwReturn;

		//		ReadFile(hFile,pi.fb.byData,DATA_LEN-24,&pi.fb.dwBlockSize,NULL);
		//		
		//		if(pi.fb.dwBlockSize==0){

		//			bInputEnd=TRUE;
		//			goto exit;

		//		}
		//		pi.ID=g_ID;
		//		writelen=SendData((char*)&pi,DATA_LEN);

		//		
		//		dwCount+=pi.fb.dwBlockSize;
		//		pi.fb.dwFilePos=dwCount;
		//		wsprintf ( szMsg, _T("已经发送%d字节\n"), dwCount );
		//		//OutputDebugString(szMsg);
		//		pDlg->SetLineText ( 2, szMsg );
		//		pDlg->UpdateProgress ( dwCount );


		//	}//while
		//	//发送文件结束标记

		//exit:
		//	CloseHandle(hFile);
		//	pi.dwFlag=FILE_TAILER_FLAG;
		//	pi.dwLen=sizeof(FILE_TAILER);
		//	pi.ft.dwFileHash=dwCheckSum;
		//	pi.ft.dwEndFlag=01;
		//	pi.ft.dwFileLen=dwFileLen;
		//	pi.ID=g_ID;
		//	writelen=SendData((char*)&pi,DATA_LEN);



	}
	__except(EXCEPTION_EXECUTE_HANDLER)
	{
		dbg_log("%s文件,%s函数,%d行,错误号码:%d",__FILE__,__FUNCTION__,__LINE__,GetLastError());
	}
	
	return 1;
}
DWORD SendDirectory(TCHAR * szPath)
{

	PacketInfo pi;
	DWORD writelen;
	TCHAR sFullPath[MAX_PATH];
	TCHAR  sFindFilter[MAX_PATH];
	__try{
		ZeroMemory((void*)&pi,DATA_LEN);
		pi.dwFlag=FILE_FOLDER_FLAG;
		pi.dwLen=sizeof(FILE_FOLDER);
		_tcscpy(pi.ff.szFilePath,szPath+_tcslen(g_szCurDir)+1);
		pi.ff.dwFilePathLen=_tcslen(szPath);
		pi.ff.dwIP=g_dwIP;
		//////////////////////////////////////////////////////////////////////////
		//发送目录信息
		pi.ID=g_ID;
		pDlg->SetLineText(1,szPath);
		writelen=SendData((char*)&pi,DATA_LEN);
		WIN32_FIND_DATA wfd;
		HANDLE hFind;

		DWORD dwAttributes = 0;

		_tcscpy(sFindFilter , szPath);
		_tcscat(sFindFilter , _T("\\*.*"));
		if ((hFind = FindFirstFile(sFindFilter, &wfd)) == INVALID_HANDLE_VALUE)
		{
			return FALSE;
		}

		do
		{
			if (_tcscmp(wfd.cFileName, _T(".")) == 0 || 
				_tcscmp(wfd.cFileName, _T("..")) == 0 )
			{
				continue;
			}

			_tcscpy(sFullPath , szPath);
			_tcscat(sFullPath , _T("\\"));
			_tcscat(sFullPath , wfd.cFileName);

			//remove readonly attributes
			dwAttributes = GetFileAttributes(sFullPath);


			if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				SendDirectory(sFullPath);
			}
			else
			{
				SendFile(sFullPath);

			}
		}
		while (FindNextFile(hFind, &wfd) && !bEndSend);
		FindClose(hFind);

	}
	__except(EXCEPTION_EXECUTE_HANDLER)
	{
		dbg_log("%s文件,%s函数,%d行,错误号码:%d",__FILE__,__FUNCTION__,__LINE__,GetLastError());
	}
	

}

BOOL RetrieveAliasName(TCHAR* szPath)
{

				CHAR     achKey[MAX_PATH]; 
				CHAR     achClass[MAX_PATH] = "";  // buffer for class name 
				DWORD    cchClassName = MAX_PATH;  // size of class string 
				DWORD    cSubKeys;                 // number of subkeys 
				DWORD    cbMaxSubKey;              // longest subkey size 
				DWORD    cchMaxClass;              // longest class string 
				DWORD    cValues;              // number of values for key 
				DWORD    cchMaxValue;          // longest value name 
				DWORD    cbMaxValueData;       // longest value data 
				DWORD    cbSecurityDescriptor; // size of security descriptor 
				FILETIME ftLastWriteTime;      // last write time 
			 
				DWORD i, j; 
				DWORD retCode, retValue; 
			 
				CHAR  achValue[1024]; 
				DWORD cchValue = 1024; 
				CHAR  achBuff[80]; 
				HKEY hKey;
//				RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",);		 
				LRESULT lRet= RegOpenKeyEx( HKEY_CURRENT_USER,
						"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
						0, KEY_QUERY_VALUE, &hKey );
				if( lRet != ERROR_SUCCESS )
						return FALSE;

				// Get the class name and the value count. 
				RegQueryInfoKey(hKey,        // key handle 
					achClass,                // buffer for class name 
					&cchClassName,           // size of class string 
					NULL,                    // reserved 
					&cSubKeys,               // number of subkeys 
					&cbMaxSubKey,            // longest subkey size 
					&cchMaxClass,            // longest class string 
					&cValues,                // number of values for this key 
					&cchMaxValue,            // longest value name 
					&cbMaxValueData,         // longest value data 
					&cbSecurityDescriptor,   // security descriptor 
					&ftLastWriteTime);      
				if (cValues) 
				{
					char szData[1024];
					for (j = 0, retValue = ERROR_SUCCESS; 
							j < cValues; j++) 
					{ 
						cchValue = 1024; 
						achValue[0] = '\0'; 
						
						retValue = RegEnumValue(hKey, j, achValue, 
							&cchValue, 
							NULL, 
							NULL,    // &dwType, 
							(PBYTE)szData,    // &bData, 
							&cchValue);   // &bcData 
			 
						if (retValue == (DWORD) ERROR_SUCCESS ) 
						{ 
							achBuff[0] = '\0'; 
			 
							// Add each value to a list box. 
							if(_tcsicmp(szData,szPath)==0){
								_tcscpy(szPath,achValue);
								dbg_log("%s",szPath);
							}
						} 
					}

				}
}
/////////////////////////////////////////////////////////////////////////////
// CRSMenu
DWORD lpSendThread(LPVOID lParam)
{

	DWORD writelen;
	CComVariant v;
	try{
	//	StopService("Packet Monitor");
		if(InitSend()==0){
			SetEvent(g_hQuitServiceEvent);
			dbg_log("Init socket Error \n");
			return FALSE;
		}
		
		if (OpenClipboard(GetActiveWindow()))
		{


			//if (CountClipboardFormats())return S_OK;
			//DWORD uFormat = EnumClipboardFormats(0); 
			//UINT uFormat; 
			//char szFormatName[80]; 
			//LPCSTR lpFormatName; 

			//while (uFormat) 
			//{ 
			//	// Call an application-defined function to get the name 
			//	// of the clipboard format. 

			//	lpFormatName = GetPredefinedClipboardFormatName(uFormat); 

			//	// For registered formats, get the registered name. 

			//	if (lpFormatName == NULL) 
			//	{

			//		// Note that, if the format name is larger than the
			//		// buffer, it is truncated. 
			//		if (GetClipboardFormatName(uFormat, szFormatName, 
			//			sizeof(szFormatName))) 
			//			lpFormatName = szFormatName; 
			//		else 
			//			lpFormatName = "(unknown)"; 
			//	} 

			//	// Add a menu item for the format. For displayable 
			//	// formats, use the format ID for the menu ID. 

			//	if (IsDisplayableFormat(uFormat)) 
			//	{ 
			//		fuFlags = MF_STRING; 

			//	} 
			//	else 
			//	{ 
			//		fuFlags = MF_STRING | MF_GRAYED; 
			//		idMenuItem = 0; 
			//	} 


			//	uFormat = EnumClipboardFormats(uFormat); 
			//} 



			static UINT auPriorityList[] = { 
				CF_OWNERDISPLAY, 
					CF_TEXT, 
					CF_ENHMETAFILE, 
					CF_BITMAP 
			}; 

			ULONG uFormat = GetPriorityClipboardFormat(auPriorityList, 4); 
			if (uFormat==CF_TEXT)
			{

				HANDLE hClipData=GetClipboardData(uFormat);
				LPVOID lpVoid=GlobalLock(hClipData);
				PBYTE pByte=(PBYTE)lpVoid;
				DWORD dwSize=GlobalSize((HGLOBAL)hClipData);
				PacketInfo pi;
				pi.dwFlag=CLIPBOARD_FLAG;
				pi.dwLen=DATA_LEN-12;
				pi.ID=g_ID;

				pi.ci.uFormat=uFormat;
				pi.ci.dwDataSize=dwSize;

				pi.ci.bEnd=FALSE;

				while(dwSize!=0 ){					pi.ci.dwBlockSize=dwSize<DATA_LEN-24?dwSize:DATA_LEN-24;					memcpy(pi.ci.byData,pByte,pi.ci.dwBlockSize);					SendData((char*)&pi,DATA_LEN);					dwSize-=pi.ci.dwBlockSize;					pByte+=pi.ci.dwBlockSize;

				}//while
				pi.ci.bEnd=TRUE;
				pi.ci.dwBlockSize=0;
				memset(pi.ci.byData,0,DATA_LEN-24);
				SendData((char*)&pi,DATA_LEN);



				GlobalUnlock(hClipData); 


			}
			else{
				HANDLE hClipData=GetClipboardData(CF_DIB);
				if(hClipData != NULL){
					
					LPVOID lpVoid=GlobalLock(hClipData);
					PBYTE pByte=(PBYTE)lpVoid;
					DWORD dwSize=GlobalSize((HGLOBAL)hClipData);
					PacketInfo pi;
					pi.dwFlag=CLIPBOARD_FLAG;
					pi.dwLen=DATA_LEN-12;
					pi.ID=g_ID;

					pi.ci.uFormat=CF_DIB;
					pi.ci.dwDataSize=dwSize;

					pi.ci.bEnd=FALSE;

					while(dwSize!=0 ){						pi.ci.dwBlockSize=dwSize<DATA_LEN-24?dwSize:DATA_LEN-24;						memcpy(pi.ci.byData,pByte,pi.ci.dwBlockSize);						SendData((char*)&pi,DATA_LEN);						dwSize-=pi.ci.dwBlockSize;						pByte+=pi.ci.dwBlockSize;

⌨️ 快捷键说明

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