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

📄 getresourcedlg.cpp

📁 获取任何文件中的图片信息,质量越高得到的图片越多。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// GetResourceDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GetResource.h"
#include "GetResourceDlg.h"
#include "struct.h"
#include "wav.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
	
	// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA
	
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL
	
	// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGetResourceDlg dialog

CGetResourceDlg::CGetResourceDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGetResourceDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGetResourceDlg)
	m_strInputFileName = _T("");
	m_strOutputPath = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGetResourceDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGetResourceDlg)
	DDX_Text(pDX, IDC_EDIT_INPUT_FILE_NAME, m_strInputFileName);
	DDX_Text(pDX, IDC_EDIT_OUTPUT_PATH, m_strOutputPath);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGetResourceDlg, CDialog)
//{{AFX_MSG_MAP(CGetResourceDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_INPUT, OnButtonInput)
ON_BN_CLICKED(IDC_BUTTON_OUTPUT, OnButtonOutput)
ON_BN_CLICKED(IDSTART, OnStart)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGetResourceDlg message handlers

BOOL CGetResourceDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	// Add "About..." menu item to system menu.
	
	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
	
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	m_fileNumber = 0;
	m_outNumber = 0;
	m_stop = 0;
	m_status = 0;
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGetResourceDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGetResourceDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting
		
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
		
		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		
		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CGetResourceDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CGetResourceDlg::OnButtonInput() 
{
	int tempos;
	CFileDialog FileDlg(1,NULL,NULL, OFN_ALLOWMULTISELECT |OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,NULL,NULL);
	
	
	char* pBuffer = (char*)malloc(_MAX_PATH * 800);//最多允许800个文件
	memset(pBuffer,0,_MAX_PATH*800);
	FileDlg.m_ofn.lpstrFile = pBuffer;
	FileDlg.m_ofn.nMaxFile = 800*_MAX_PATH;
	
	POSITION pos;
	if(FileDlg.DoModal() == IDOK) 
	{
		m_strInputFileName.Empty();
		m_strInputFileName = FileDlg.GetPathName();
		
		pos = FileDlg.GetStartPosition();
		m_fileNumber=0;
		while (pos)
		{//求文件个数	
			m_strAllName[m_fileNumber++] = FileDlg.GetNextPathName(pos);
			if(m_fileNumber == 1023) break;//最多允许1023个文件.
		}			
	}	
	
	free(FileDlg.m_ofn.lpstrFile);
	
	
	m_strOutputPath = m_strInputFileName;
	if(m_fileNumber==1)
	{
		tempos = m_strOutputPath.ReverseFind('\\');
	    m_strOutputPath = m_strOutputPath.Left(tempos);
	}
    

	UpdateData(FALSE);
}

void CGetResourceDlg::OnButtonOutput() 
{	

 

}


void CGetResourceDlg::OnStart() 
{
	if(m_fileNumber==0)
	{
		AfxMessageBox("Please Input File!!");
		return;
	}
	
	if(!m_status)
	{
		m_stop = 0;
		m_status = 1;
		GetDlgItem(IDSTART)->SetWindowText("Stop");
		for(long i=0; i<m_fileNumber && !m_stop; i++)
		{
			getResourceFromFile(m_strAllName[i]);	
		//	AfxMessageBox(m_strAllName[i]);
		}
		
		resChangTitile(1,1);
		AfxMessageBox("Finish");		
	}
	else
	{
		m_status = 0;
		m_stop = 1;
	}
	
	GetDlgItem(IDSTART)->SetWindowText("Start");
	SetWindowText("GetResource");
	return;	
}

void CGetResourceDlg::getResourceFromFile(CString strFileName) 
{
	FILE* fp;
	MSG msg;
	long pos;
	long len;

	uChar pData[3040];
	int tempos;
	
	fp = fopen(strFileName,"rb");
	if(!fp) return;

	fseek(fp,0,SEEK_END);
	len = ftell(fp);
	fseek(fp,0,SEEK_SET);
	
	pos = 0;
	while(pos<len && !m_stop)
	{		
		// good
		while(::PeekMessage(&msg,NULL, 0,0,PM_REMOVE))
		{
			TranslateMessage(&msg);
		    DispatchMessage(&msg);
		}
		//
		
		fseek(fp,pos,SEEK_SET);
		memset(pData,0,3040);
		fread(pData,3000,1,fp);//why is 3000
		
		tempos =0;
		while(tempos < 3000)
		{   //  I think some wrong exist,may be use case is better
			if(pData[tempos]==0xff && pData[tempos+1]==0xd8 && pData[tempos+2]==0xff)
			{//JPEG
				pos=resSaveJPEG(fp,pos+tempos,len);
				resChangTitile(len,pos);
				break;
			}
			if(!strnicmp((char*)pData+tempos,"BM",2))
			{//BMP
				pos=resSaveBMP(fp,pos+tempos,len);
				resChangTitile(len,pos);
				break;
			}
			if(!strnicmp((char*)pData+tempos,"gif89a",6)||!strnicmp((char*)pData+tempos,"gif87a",6))
			{//gif
				pos = resSaveGIF(fp,pos+tempos,len);
				resChangTitile(len,pos);
				break;
			
			}
            	if(pData[tempos]==0x89 && pData[tempos+1]==0x50 && pData[tempos+2]==0x4e && pData[tempos+3]==0x47 && pData[tempos+4]==0x0d && pData[tempos+5]==0x0a && pData[tempos+6]==0x1a && pData[tempos+7]==0x0a )
			{//png
				pos = resSavePNG(fp,pos+tempos,len);
				resChangTitile(len,pos);
				break;
			
			}
				if(pData[tempos]==0xff && (pData[tempos+1])==0xfB)
				{//mp3
				   if(pData[tempos+1]&0x08>>3== 0 || pData[tempos+1]&0x08>>3==1)
				   {
				      if(pData[tempos+1]&0x06>>1== 2 || pData[tempos+1]&0x06==6 || pData[tempos+1]&0x06>>1==6)
					  {
					      pos = resSaveMP3(fp,pos+tempos,len);
						  resChangTitile(len,pos);
						  break;

					  }
				   }
				}
				if(!strnicmp((char *)pData+tempos,"WAVE",4))
				{//WAV
				   pos = resSaveWAV(fp,pos+tempos,len);
				   resChangTitile(len,pos);
					break;
				}
			tempos++;
		}

		if(tempos==3000)
		{
			resChangTitile(len,pos);
			pos += (3000-12);// change by juhua
		}
	}
	
	fclose(fp);
}


void CGetResourceDlg::resChangTitile(long len, long pos) 
{
	float per;
	CString strTmp;

	per = (float)pos/len;
	per *= 100;
	strTmp.Format("Percent:%.2f%%,File Name: %s",per,m_strInputFileName);
	SetWindowText(strTmp);
}


//	if(!strncmp((char*)pData+tempos,"BM",2)&& pData[tempos+6]==0x0 && pData[tempos+7]==0x0 &&pData[tempos+8]==0x0 && pData[tempos+9]==0x0 && pData[tempos+26] ==0x01 && pData[tempos+27] == 0x00)
long CGetResourceDlg::resSaveBMP(FILE* fp,long posStart,long len) 
{
	uChar* pData;
	unsigned long segLen;
	unsigned long  temLen;
	long  *temL;
	short * temS;
	
	fseek(fp,posStart+2,SEEK_SET);
	fread(&segLen,4,1,fp);
	if(segLen > 3*1024*1024) 
		return posStart+1;//最大为3MB

	pData = (uChar*)malloc(segLen+8);
	if(!pData) return posStart+1;
	memset(pData,0,segLen+8);

	fseek(fp,posStart,SEEK_SET);
	temLen=fread(pData,1,segLen,fp);
	if(temLen==segLen)
	{   
		  temL = (long *)(pData+6);
		  if(*temL)
		  {
			return posStart+1;
		  }

			temS = (short *)(pData+26);
		  if((*temS)!=1)
		  {
			return posStart+1;
		  }

		temS = (short *) (pData+28);
		if(*temS!=1l && *temS!=4l && *temS!=8l && *temS!=16l && *temS!=24l  && *temS!=32l)
		{
		  return posStart+1;
		}

        temL = (long *)( pData+30);
		if(*temL != 0l && *temL != 1l && *temL != 2l && *temL != 3l )
		{
		   return posStart+1;
		}


         

⌨️ 快捷键说明

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