示例#1
0
HBITMAP CImageFile::LoadBitmap(HINSTANCE hInstance, UINT nResourceID, LPCTSTR pszType)
{
	HMODULE hModule = (HMODULE)hInstance;
	HRSRC hRes = FindResource( hModule, MAKEINTRESOURCE( nResourceID ), pszType );
	
	if ( hRes == NULL ) return NULL;
	
	DWORD nLength		= SizeofResource( hModule, hRes );
	HGLOBAL hMemory		= ::LoadResource( hModule, hRes );
	LPCVOID pBuffer		= (LPCVOID)LockResource( hMemory );

	CImageFile pImageFile;
	return pImageFile.LoadFromMemory( pBuffer, nLength );
}
示例#2
0
void CDownloadTask::RunPreviewRequest()
{
	m_bSuccess = m_pRequest->Execute( false );	// Without threading

	if ( ! IsThreadEnabled() || m_pDownload->m_sPath.IsEmpty() ) return;

	// Save downloaded preview as png-file
	const CString strPath = m_pDownload->m_sPath + L".png";
	CImageFile pImage;
	CBuffer* pBuffer = IsPreviewAnswerValid( m_pDownload->m_oSHA1 );
	if ( pBuffer && pBuffer->m_pBuffer && pBuffer->m_nLength &&
		 pImage.LoadFromMemory( L".jpg", pBuffer->m_pBuffer, pBuffer->m_nLength, FALSE, TRUE ) &&
		 pImage.SaveToFile( (LPCTSTR)strPath, 100 ) )
	{
		// Make it hidden, so the files won't be shared
		SetFileAttributes( (LPCTSTR)strPath, FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM );
	}
	else
	{
		// Failed
		m_pDownload->m_bWaitingPreview = FALSE;
		theApp.Message( MSG_ERROR, IDS_SEARCH_DETAILS_PREVIEW_FAILED, (LPCTSTR)GetRequest() );
	}
}