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

📄 batchdlg.cpp

📁 用VC++实现LZW算法
💻 CPP
字号:
// batchdlg.cpp : implementation file
//

#include "stdafx.h"
#include "tlzw.h"
#include "batchdlg.h" 

#include "lzwtable.h"
#include "lzwcode.h"
#include "lzwfile.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBatchDlg dialog
HWND hWndDlg=NULL;
CString szFileName;
void BatchEncodedBytes(void)
{
	::SendMessage(hWndDlg,WM_LZW_ENCODE_BYTES,0,0);
}
void BatchDecodedBytes(void)
{
	::SendMessage(hWndDlg,WM_LZW_DECODE_BYTES,0,0);
}
LONG CBatchDlg::OnDecodeBytes(UINT uP,LONG lP)
{
	char szPercent[200];
	CClientDC dc(this);
	dc.SelectStockObject(WHITE_BRUSH);
	dc.Rectangle(m_rcDraw);
	dc.SelectStockObject(LTGRAY_BRUSH);
	CRect rcPercent=m_rcDraw;
	if(++m_iPercent>=101)
		m_iPercent=0;
	rcPercent.right=rcPercent.left+m_iPercent*3;
	dc.Rectangle(rcPercent);
	sprintf(szPercent,"%s %d%%",(LPCSTR)szFileName,m_iPercent);
	dc.SetBkMode(TRANSPARENT);
	dc.SetTextColor(RGB(0,0,255));
	dc.DrawText(szPercent,strlen(szPercent),m_rcDraw,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
	return 0L;
}
LONG CBatchDlg::OnEncodeBytes(UINT uP,LONG lP)
{
	if(++m_iPercent>=101)
		m_iPercent=0;
	if(m_iPercent%5!=0)
		return 0L;
	char szPercent[200];
	CClientDC dc(this);
	dc.SelectStockObject(WHITE_BRUSH);
	dc.Rectangle(m_rcDraw);
	dc.SelectStockObject(LTGRAY_BRUSH);
	CRect rcPercent=m_rcDraw;
	rcPercent.right=rcPercent.left+m_iPercent*3;
	dc.Rectangle(rcPercent);
	sprintf(szPercent,"%s %d%%",(LPCSTR)szFileName,m_iPercent);
	dc.SetTextColor(RGB(0,0,255));
	dc.SetBkMode(TRANSPARENT);
	dc.DrawText(szPercent,strlen(szPercent),m_rcDraw,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
	return 0L;
}
CBatchDlg::CBatchDlg(LPCSTR pszFileName,CStringArray* pszNameArray,CWnd* pParent /*=NULL*/)
	: CDialog(CBatchDlg::IDD, pParent),m_rcDraw(CPoint(0,50),CSize(300,30))
{
	m_iPercent=0;
	m_pszNameArray=pszNameArray;
	m_szHGLZName=pszFileName;
	m_fEncode=TRUE;
	//{{AFX_DATA_INIT(CBatchDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}
CBatchDlg::CBatchDlg(LPCSTR pszFileName,LPCSTR pszDirName,int* piPos,int iCount,CWnd* pParent /*=NULL*/)
	: CDialog(CBatchDlg::IDD, pParent),m_rcDraw(CPoint(0,50),CSize(300,30))
{
	m_szHGLZName=pszFileName;
	m_fEncode=FALSE;
	m_iPercent=0;
	m_szDirName=pszDirName;
	m_piPos=piPos;
	m_iCount=iCount;
	//{{AFX_DATA_INIT(CBatchDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

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

BEGIN_MESSAGE_MAP(CBatchDlg, CDialog)
	ON_MESSAGE(WM_LZW_DECODE_BYTES,OnDecodeBytes)
	ON_MESSAGE(WM_LZW_ENCODE_BYTES,OnEncodeBytes)
	//{{AFX_MSG_MAP(CBatchDlg)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

int FindFileName(LPCSTR pszName);
void MakeFileName(LPCSTR pszIn,char* pszOut)
{
	
}
/*{
	int iLen=strlen(pszName);
	for(int i=iLen-1;i>=0;i--)
	{
		if(pszName[i]=='\\')
			return i+1;
	}
	return 0;
}*/


/////////////////////////////////////////////////////////////////////////////
// CBatchDlg message handlers
void CBatchDlg::BeginDecode(void)
{
	CStringArray array;
	if(!LZWParseFileHead(m_szHGLZName,array))
	{
		array.RemoveAll();
		OnOK();
		return;
	}
	int iTotal=array.GetUpperBound()+1;
	if(iTotal==0 )
	{
		array.RemoveAll();
		AfxMessageBox("error batch parameter");
		OnOK();
		return;
	}
    for(int i=0;i<m_iCount;i++)
    {
		szFileName=array.GetAt(m_piPos[i]);
		//MakeFileName(szPutName,szGetName);
		m_iPercent=0;
		LZWDecodeFileOnPosition(m_szHGLZName,m_szDirName,
								(DWORD)m_piPos[i],BatchDecodedBytes);
	}
	array.RemoveAll();
	OnOK();
}
void CBatchDlg::BeginBatch(void)
{
	int iTotal=m_pszNameArray->GetUpperBound()+1;
	if(iTotal==0 )
	{
		AfxMessageBox("error batch encode parameter");
		OnOK();
		return;
	}
	char szGetName[1000];
	CString szTemp;
    for(int i=0;i<iTotal;i++)
    {
		szTemp=m_pszNameArray->GetAt(i);
		strcpy(szGetName,szTemp);
		szFileName=(szGetName+FindFileName(szGetName));
		//MakeFileName(szPutName,szGetName);
		m_iPercent=0;
		if(i==0)
			LZWEncodeFile(szGetName,m_szHGLZName,BatchEncodedBytes);
		else
			LZWAddEncodeFile(szGetName,m_szHGLZName,BatchEncodedBytes);
	}
	OnOK();
}
void CBatchDlg::OnTimer(UINT nIDEvent)
{
	CClientDC dc(this);
	dc.SelectStockObject(WHITE_BRUSH);
	dc.Rectangle(m_rcDraw);
	KillTimer(1);
	if(m_fEncode)
		BeginBatch();
	else
		BeginDecode();
	//SendMessage(WM_LZW_DECODE_BYTES);
	//SendMessage(WM_LZW_ENCODE_BYTES);
	CDialog::OnTimer(nIDEvent);
}

BOOL CBatchDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	hWndDlg=GetSafeHwnd();
	SetTimer(1,10,NULL);
	CRect rcC;
	GetClientRect(rcC);
	m_rcDraw+=CPoint((rcC.Width()-300)/2,0);
	if(!m_fEncode)
		SetWindowText("Batch DeCompress");
	return TRUE;  // return TRUE  unless you set the focus to a control
}

⌨️ 快捷键说明

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