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

📄 cxferwindow.cpp

📁 vc环境下的pgp源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			}
			
			LeaveCriticalSection(&mRecvCriticalSection);
			
			break;
		}
	}

	CWnd::OnTimer(TimerID);
}
              
void CXferWindow::GetFileIcon(	char* szFilePath,
								HICON* largeIcon,
								HICON* smallIcon)
{
	SHFILEINFO shellinfo;
	
	if(!SHGetFileInfo( 	szFilePath, 
						0,
						&shellinfo,
						sizeof(SHFILEINFO),
						SHGFI_ICON | SHGFI_SMALLICON ))
	{
		AfxMessageBox("Failed to Get Info.");
	}
	else
	{
		if(smallIcon)
		{
			*smallIcon = shellinfo.hIcon;
		}
		
		if(largeIcon)
		{
			if(SHGetFileInfo( 	szFilePath, 
						0,
						&shellinfo,
						sizeof(SHFILEINFO),
						SHGFI_ICON | SHGFI_LARGEICON ))
			{
				*largeIcon = shellinfo.hIcon;
			}
			
		
		}
		
		
 	}
}

BOOL CXferWindow::FileIsAFolder(char* path)
{
	char current[MAX_PATH];
	
	GetCurrentDirectory(sizeof(current), current);
	
	if(SetCurrentDirectory(path))
	{
		SetCurrentDirectory(current);
		
		return TRUE;
	}
	
	return FALSE;

}

/////////////////////////////////////////////////////////////////////////////

void CXferWindow::SetXferThread(CXferThread *xferThread)
{
	mXfer = xferThread;
	
	if(xferThread)
	{
		mXferQueue = xferThread->GetQueue();
	}
	else
	{
		mXferQueue = NULL;
	}
}

void CXferWindow::SendFolder(XferFileSpec* fs)
{
	HANDLE handle;
	WIN32_FIND_DATA wfd;
	char find[MAX_PATH];
	
	strcpy(find, fs->path);
	strcat(find, "\\*.*");
	
	handle = FindFirstFile(find, &wfd);
	
	if( INVALID_HANDLE_VALUE != handle )
	{
		do
		{
			if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				if( strcmp(wfd.cFileName, ".") && 
					strcmp(wfd.cFileName, "..") )
				{
					XferFileSpec dirfs;
					
					strcpy(dirfs.path, fs->path);
					strcat(dirfs.path, "\\");
					strcat(dirfs.path, wfd.cFileName);
					
					//dirfs.filename = strrchr(dirfs.path, '\\' );
					//dirfs.filename++;
			
					dirfs.root = dirfs.path + (fs->root - fs->path);
					
					SendFolder(&dirfs);
				}
			}
			else
			{
				strcat(fs->path, "\\");
				strcat(fs->path, wfd.cFileName);
		
				fs->filename = strrchr(fs->path, '\\' );
				fs->filename++;
		
				SendFile(fs);
			}
		
		}while( FindNextFile(handle,&wfd) );
	}
	else
	{
		char szMessage[MAX_PATH + 25];
		
		wsprintf(szMessage, "Error opening folder %s", fs->path);
		AfxMessageBox(szMessage, MB_ICONSTOP|MB_OK);
	}
}

void CXferWindow::SendFile(XferFileSpec* fs)
{
	if(mXferQueue)
	{
		XferFileSpec*myfs = (XferFileSpec*) pgp_malloc(sizeof(XferFileSpec));
		
		memcpy(myfs, fs, sizeof(XferFileSpec));
		
		if(fs->root)
		{
			myfs->root = myfs->path + (fs->root - fs->path) ;
		}
		
		myfs->filename = myfs->path + (fs->filename - fs->path) ;
		
		mXferQueue->Send(_mt_sendFile, myfs, sizeof(XferFileSpec), 0);
	}
}

void CXferWindow::QueueSend(XSendFile *nxs)
{
	HICON smallIcon, largeIcon;
	
	GetFileIcon(nxs->xi.filepath, &smallIcon, &largeIcon);
	
	EnterCriticalSection(&mSendCriticalSection);
	
	mNumSends++;
	
	int iconIndex = mSendSmallImageList.Add(smallIcon);	
	int itemIndex = mSendList.GetItemCount();
	
	mSendList.InsertItem(itemIndex, nxs->xi.filename, iconIndex);
	
	DestroyIcon(smallIcon);
	DestroyIcon(largeIcon);
	
	ItemInfo* info = new ItemInfo;
	
	info->iconIndex = iconIndex;
	info->xsf = nxs;

	mSendList.SetItemData( itemIndex,(DWORD) info);
	
	LeaveCriticalSection(&mSendCriticalSection);
}

void CXferWindow::QueueReceive(XRcvFile *nxr)
{
	HICON smallIcon;
	
	ShowWindow(SW_SHOW);
	
	smallIcon = (HICON)LoadImage(	theApp.m_hInstance,
							MAKEINTRESOURCE(IDI_RECVICON),
							IMAGE_ICON, 
							16, 
							16,
							LR_SHARED);
		
	EnterCriticalSection(&mRecvCriticalSection);
	
	mNumReceives++;
	
	int iconIndex = mRecvSmallImageList.Add(smallIcon);
	int itemIndex = mRecvList.GetItemCount();
	
	mRecvList.InsertItem(itemIndex, nxr->xi.filename, iconIndex);
	
	ItemInfo* info = new ItemInfo;
	
	info->iconIndex = iconIndex;
	info->xrf = nxr;

	mRecvList.SetItemData( itemIndex,(DWORD) info); 
	
	LeaveCriticalSection(&mRecvCriticalSection);
}

void CXferWindow::DequeueSend(XSendFile *nxs)
{
	EnterCriticalSection(&mSendCriticalSection);
	
	mNumSends--;
	
	int count = mSendList.GetItemCount();
	
	ItemInfo* info;
	
	for(int index = 0; index < count; index++)
	{
		info = (ItemInfo*) mSendList.GetItemData(index);

		if( info->xsf == nxs )
		{
			mSendSmallImageList.Remove(info->iconIndex);
			
			delete info;
			
			mSendList.DeleteItem(index);
		}
	}
	
	LeaveCriticalSection(&mSendCriticalSection);
}

void CXferWindow::DequeueReceive(XRcvFile *nxr)
{
	EnterCriticalSection(&mRecvCriticalSection);
	
	mNumReceives--;
	
	int count = mRecvList.GetItemCount();
	
	ItemInfo* info;
	
	for(int index = 0; index < count; index++)
	{
		info = (ItemInfo*) mRecvList.GetItemData(index);

		if( info->xrf == nxr )
		{
			//mRecvSmallImageList.Remove(info->iconIndex);
			
			delete info;
			
			mRecvList.DeleteItem(index);
		}
	}
	
	LeaveCriticalSection(&mRecvCriticalSection);
}


void CXferWindow::StartSend(XferInfo *xi)
{
	char string[256];
	HICON hIcon;
	
	mSendXferInfo = xi;
	
	mSendFile.SetWindowText(xi->filename);
	
	wsprintf(string, "0%% of %d K", xi->bytesTotal/1024);
	mSendSize.SetWindowText(string);
	
	mSendProgress.SetPos(0);
	
	EnterCriticalSection(&mSendCriticalSection);
	
	mNumSends--;
	
	ItemInfo* info = (ItemInfo*) mSendList.GetItemData(0); 
	//mSendSmallImageList.Remove(info->iconIndex);
	mSendList.DeleteItem(0);
	
	delete info;
	
	LeaveCriticalSection(&mSendCriticalSection);
}

void CXferWindow::StartReceive(XferInfo *xi)
{
	char string[256];
	
	mRecvXferInfo = xi;
	
	mRecvFile.SetWindowText(xi->filename);
	
	wsprintf(string, "0%% of %d K", xi->bytesTotal/1024);
	mRecvSize.SetWindowText(string);
	
	mRecvProgress.SetPos(0);
	
	EnterCriticalSection(&mRecvCriticalSection);
	
	mNumReceives--;
	
	ItemInfo* info = (ItemInfo*) mRecvList.GetItemData(0); 
	//mRecvSmallImageList.Remove(info->iconIndex);
	mRecvList.DeleteItem(0);
	
	delete info;
	LeaveCriticalSection(&mRecvCriticalSection);
}

void CXferWindow::EndSend()
{
	EnterCriticalSection(&mSendCriticalSection);
	
	mSendXferInfo = NULL;
	
	mSendFile.SetWindowText(szNoSend);
	mSendSize.SetWindowText("");
	mSendProgress.SetPos(0);
	
	LeaveCriticalSection(&mSendCriticalSection);
}

void CXferWindow::EndReceive()
{
	EnterCriticalSection(&mRecvCriticalSection);
	
	mRecvXferInfo = NULL;
	mRecvFile.SetWindowText(szNoRecv);
	mRecvSize.SetWindowText("");
	mRecvProgress.SetPos(0);
	
	LeaveCriticalSection(&mRecvCriticalSection);
}


const GUID MY_CLSID_ShellLink = 
	{ 0x00021401L, 0, 0, { 0xC0,0,0,0,0,0,0,0x46 } };
const GUID MY_IID_IShellLink = 
	{ 0x000214EEL, 0, 0, { 0xC0,0,0,0,0,0,0,0x46 } };
                
HRESULT CXferWindow::ResolveLink(LPCSTR lpszLinkFile, LPSTR lpszPath) 
{ 
    HRESULT hres;     
    IShellLink* psl;     
    char szGotPath[MAX_PATH]; 
    char szDescription[MAX_PATH];     
    WIN32_FIND_DATA wfd;  
    *lpszPath = 0; // assume failure  
    
    CoInitialize(NULL);
    
    // Get a pointer to the IShellLink interface. 
    hres = CoCreateInstance(MY_CLSID_ShellLink, NULL, 
            CLSCTX_INPROC_SERVER, MY_IID_IShellLink, (void **)&psl); 
            
    if (SUCCEEDED(hres)) 
    {         
    	IPersistFile* ppf;  
    	
        // Get a pointer to the IPersistFile interface. 
        hres = psl->QueryInterface(	IID_IPersistFile, 
        							(void **)&ppf);    
             
        if (SUCCEEDED(hres)) 
        { 
        	WORD wsz[MAX_PATH];  
        	// Ensure that the string is Unicode.
        	// Load the shortcut.
        	MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, (wchar_t *)wsz, MAX_PATH);  
        	hres = ppf->Load((wchar_t *)wsz, STGM_READ); 
        
            if (SUCCEEDED(hres)) 
            {   
            	// Resolve the link. 
                hres = psl->Resolve(NULL, SLR_ANY_MATCH); 
                
                if (SUCCEEDED(hres)) 
                {  
                    // Get the path to the link target.
                    hres = psl->GetPath(szGotPath,
                        MAX_PATH, (WIN32_FIND_DATA *)&wfd,
                        SLGP_SHORTPATH);
                     
                    //if (!SUCCEEDED(hres)
                        //HandleErr(hres); // application-defined function
                        
                    // Get the description of the target.
                    hres = psl->GetDescription(szDescription, MAX_PATH);
                     
                    //if (!SUCCEEDED(hres))
                    	//HandleErr(hres); // application-defined function
                        
                    lstrcpy(lpszPath, szGotPath);
            	}
            }
            
        	// Release the pointer to the IPersistFile interface. 
    		ppf->Release();       
    	} 
    	
    	// Release the pointer to the IShellLink interface.
    	psl->Release();     
    
    }  
    
    CoUninitialize( );
    
    return hres; 
} 

	
BEGIN_MESSAGE_MAP(CXferWindow, CWnd)
	//{{AFX_MSG_MAP(CXferWindow)
	ON_WM_DROPFILES()
	ON_WM_DESTROY()
	ON_WM_TIMER()
	ON_WM_CREATE()
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

⌨️ 快捷键说明

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