714dd74636
git-svn-id: svn://10.65.10.50/trunk@5350 c028cbd2-c16b-5b4b-a496-9718f37d4682
300 lines
7.8 KiB
C++
Executable File
300 lines
7.8 KiB
C++
Executable File
// ex00dlg.cpp : implementation file
|
|
//
|
|
|
|
#include "ex00std.h"
|
|
#include "ex00mfc.h"
|
|
#include "ex00dlg.h"
|
|
#include "winmon.h"
|
|
#include "wildcard.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)
|
|
virtual BOOL OnInitDialog();
|
|
//}}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)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CEx00mfcDlg dialog
|
|
|
|
CEx00mfcDlg::CEx00mfcDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CEx00mfcDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CEx00mfcDlg)
|
|
//}}AFX_DATA_INIT
|
|
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
|
|
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
|
}
|
|
|
|
void CEx00mfcDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CEx00mfcDlg)
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CEx00mfcDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CEx00mfcDlg)
|
|
ON_WM_SYSCOMMAND()
|
|
ON_WM_PAINT()
|
|
ON_WM_QUERYDRAGICON()
|
|
ON_BN_CLICKED(IDC_COMPRESS, OnCompress)
|
|
ON_BN_CLICKED(IDC_EXIT, OnExit)
|
|
ON_BN_CLICKED(IDC_DECOMPRESS, OnDecompress)
|
|
ON_BN_CLICKED(IDC_CLEAR, OnClear)
|
|
ON_BN_CLICKED(IDC_ABOUT, OnAbout)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CEx00mfcDlg message handlers
|
|
|
|
BOOL CEx00mfcDlg::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);
|
|
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_lb = (CListBox *) GetDlgItem( IDC_LIST1 );
|
|
m_compressor = new ALPkCompressor;
|
|
m_decompressor = new ALPkDecompressor;
|
|
m_storage = new ALWinMemory;
|
|
|
|
LoadFiles();
|
|
CAboutDlg dialog;
|
|
dialog.DoModal();
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
}
|
|
|
|
void CEx00mfcDlg::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 CEx00mfcDlg::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 CEx00mfcDlg::OnQueryDragIcon()
|
|
{
|
|
return (HCURSOR) m_hIcon;
|
|
}
|
|
|
|
void CEx00mfcDlg::LoadFiles()
|
|
{
|
|
ALWildCardExpander files( "*.*" );
|
|
char *p;
|
|
|
|
while ( p = files.GetNextFile() )
|
|
m_lb->AddString( p );
|
|
}
|
|
|
|
void CEx00mfcDlg::UpdateStatus()
|
|
{
|
|
CEdit *edit = (CEdit *)GetDlgItem( IDC_COMPRESSOR_STATUS );
|
|
if ( edit && m_compressor )
|
|
edit->SetWindowText( m_compressor->mStatus.GetStatusDetail() );
|
|
edit = (CEdit *)GetDlgItem( IDC_DECOMPRESSOR_STATUS );
|
|
if ( edit && m_decompressor )
|
|
edit->SetWindowText( m_decompressor->mStatus.GetStatusDetail() );
|
|
edit = (CEdit *)GetDlgItem( IDC_STORAGE_STATUS );
|
|
if ( edit && m_storage )
|
|
edit->SetWindowText( m_storage->mStatus.GetStatusDetail() );
|
|
}
|
|
|
|
BOOL CEx00mfcDlg::DestroyWindow()
|
|
{
|
|
// TODO: Add your specialized code here and/or call the base class
|
|
delete m_compressor;
|
|
delete m_decompressor;
|
|
delete m_storage;
|
|
return CDialog::DestroyWindow();
|
|
}
|
|
|
|
void CEx00mfcDlg::OnCompress()
|
|
{
|
|
CListBox *list_box = (CListBox *) GetDlgItem( IDC_LIST1 );
|
|
if ( list_box ) {
|
|
int sel = list_box->GetCurSel();
|
|
ALWindowsMessage monitor( AL_MONITOR_OBJECTS,
|
|
0,
|
|
AL_SEND_RATIO,
|
|
::GetDlgItem( m_hWnd,IDC_PROGRESS1 ),
|
|
PBM_SETPOS );
|
|
monitor.mlObjectStart = 0;
|
|
monitor.mlObjectSize = -1L;
|
|
CString filename;
|
|
if ( sel >= 0 )
|
|
list_box->GetText( sel, filename );
|
|
else
|
|
filename = "Intentionally bad name.doc";
|
|
ALFile file( filename );
|
|
file.mpMonitor = &monitor;
|
|
m_compressor->Compress( file, *m_storage );
|
|
}
|
|
UpdateStatus();
|
|
}
|
|
|
|
void CEx00mfcDlg::OnExit()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
PostMessage( WM_QUIT, 0, 0 );
|
|
}
|
|
|
|
void CEx00mfcDlg::OnDecompress()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
ALWindowsMessage monitor( AL_MONITOR_OBJECTS,
|
|
0,
|
|
AL_SEND_RATIO,
|
|
::GetDlgItem( m_hWnd,IDC_PROGRESS1 ),
|
|
PBM_SETPOS );
|
|
monitor.mlObjectStart = 0;
|
|
monitor.mlObjectSize = m_storage->GetSize();
|
|
ALFile file( "" );
|
|
m_storage->mpMonitor = &monitor;
|
|
m_decompressor->Decompress( *m_storage, file );
|
|
file.Delete();
|
|
m_storage->mpMonitor = 0;
|
|
UpdateStatus();
|
|
}
|
|
|
|
void CEx00mfcDlg::OnClear()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
m_compressor->ClearError();
|
|
m_decompressor->ClearError();
|
|
m_storage->ClearError();
|
|
UpdateStatus();
|
|
|
|
}
|
|
|
|
|
|
char *msg =
|
|
"This example compressed and decompresses "
|
|
"files to and from an ALMemory object. Pressing "
|
|
"the Compress button before any file is selected "
|
|
"will cause an error. Likewise, pushing Decompress "
|
|
"before anything has been compressed causes an error. "
|
|
"Once one of the three objects is in an error state, it "
|
|
"stays that way until you manually clear it.";
|
|
|
|
BOOL CAboutDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
// TODO: Add extra initialization here
|
|
CEdit *edit = (CEdit *) GetDlgItem( IDC_EDIT1 );
|
|
if ( edit )
|
|
edit->SetWindowText( msg );
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CEx00mfcDlg::OnAbout()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
CAboutDlg dialog;
|
|
dialog.DoModal();
|
|
|
|
}
|