266 lines
		
	
	
		
			6.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			266 lines
		
	
	
		
			6.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| // ex03dlg.cpp : implementation file
 | |
| //
 | |
| 
 | |
| #include "ex03std.h"
 | |
| #include "ex03mfc.h"
 | |
| #include "ex03dlg.h"
 | |
| #include "stdio.h"
 | |
| 
 | |
| #include "wildcard.h"
 | |
| #include "glarc.h"
 | |
| #include "winmon.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()
 | |
| 
 | |
| /////////////////////////////////////////////////////////////////////////////
 | |
| // CEx03mfcDlg dialog
 | |
| 
 | |
| CEx03mfcDlg::CEx03mfcDlg(CWnd* pParent /*=NULL*/)
 | |
| 	: CDialog(CEx03mfcDlg::IDD, pParent),
 | |
|       m_Archive( m_File )
 | |
| {
 | |
| 	//{{AFX_DATA_INIT(CEx03mfcDlg)
 | |
| 	//}}AFX_DATA_INIT
 | |
| 	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
 | |
| 	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
 | |
| }
 | |
| 
 | |
| void CEx03mfcDlg::DoDataExchange(CDataExchange* pDX)
 | |
| {
 | |
| 	CDialog::DoDataExchange(pDX);
 | |
| 	//{{AFX_DATA_MAP(CEx03mfcDlg)
 | |
| 	//}}AFX_DATA_MAP
 | |
| }
 | |
| 
 | |
| BEGIN_MESSAGE_MAP(CEx03mfcDlg, CDialog)
 | |
| 	//{{AFX_MSG_MAP(CEx03mfcDlg)
 | |
| 	ON_WM_SYSCOMMAND()
 | |
| 	ON_WM_PAINT()
 | |
| 	ON_WM_QUERYDRAGICON()
 | |
| 	ON_BN_CLICKED(IDC_EXIT, OnExit)
 | |
| 	ON_BN_CLICKED(IDC_ABOUT, OnAbout)
 | |
| 	ON_BN_CLICKED(IDC_COMPRESS, OnCompress)
 | |
| 	ON_BN_CLICKED(IDC_CLEAR, OnClear)
 | |
| 	//}}AFX_MSG_MAP
 | |
| END_MESSAGE_MAP()
 | |
| 
 | |
| /////////////////////////////////////////////////////////////////////////////
 | |
| // CEx03mfcDlg message handlers
 | |
| 
 | |
| BOOL CEx03mfcDlg::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
 | |
| 	CAboutDlg dlgAbout;
 | |
| 	dlgAbout.DoModal();
 | |
|     CListBox *lb = (CListBox *) GetDlgItem( IDC_LIST1 );
 | |
|     if ( lb ) {
 | |
|         lb->AddString( "A Bogus File 1");
 | |
|         lb->AddString( "A Bogus File 2");
 | |
|         lb->AddString( "A Bogus File 3");
 | |
|         ALWildCardExpander ex( "*.*" );
 | |
|         char *p;
 | |
|         while ( p = ex.GetNextFile() )
 | |
|             lb->AddString( p );
 | |
|     }
 | |
|     m_pMonitor = new ALWindowsMessage( AL_MONITOR_OBJECTS, 
 | |
|                                        ::GetDlgItem( m_hWnd, IDC_FILE ), 
 | |
|                                        AL_SEND_RATIO, 
 | |
|                                        ::GetDlgItem( m_hWnd, IDC_PROGRESS1 ), 
 | |
|                                        PBM_SETPOS );
 | |
|     m_pList = new ALEntryList( m_pMonitor, GlTools() );
 | |
|     UpdateStatus();
 | |
|     return TRUE;  // return TRUE  unless you set the focus to a control
 | |
| }
 | |
| 
 | |
| void CEx03mfcDlg::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 CEx03mfcDlg::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 CEx03mfcDlg::OnQueryDragIcon()
 | |
| {
 | |
| 	return (HCURSOR) m_hIcon;
 | |
| }
 | |
| 
 | |
| 
 | |
| void CEx03mfcDlg::OnExit() 
 | |
| {
 | |
| 	// TODO: Add your control notification handler code here
 | |
|     PostMessage( WM_QUIT, 0, 0 );
 | |
| }
 | |
| 
 | |
| BOOL CEx03mfcDlg::DestroyWindow() 
 | |
| {
 | |
| 	// TODO: Add your specialized code here and/or call the base class
 | |
|     delete m_pMonitor;
 | |
|     delete m_pList;
 | |
|     return CDialog::DestroyWindow();
 | |
| }
 | |
| 
 | |
| void CEx03mfcDlg::OnAbout()
 | |
| {
 | |
| 	// TODO: Add your control notification handler code here
 | |
| 	CAboutDlg dlgAbout;
 | |
| 	dlgAbout.DoModal();
 | |
| }
 | |
| 
 | |
| void CEx03mfcDlg::UpdateStatus()
 | |
| {
 | |
|     CEdit *edit = (CEdit *) GetDlgItem( IDC_ARCHIVE_STATUS );
 | |
|     if ( edit )
 | |
|         edit->SetWindowText( m_Archive.mStatus.GetStatusString() );
 | |
|     edit = (CEdit *) GetDlgItem( IDC_LIST_STATUS );
 | |
|     if ( edit )
 | |
|         edit->SetWindowText( m_pList->mStatus.GetStatusString() );
 | |
| }
 | |
| 
 | |
| char *about = 
 | |
| "This program creates an in-memory archive "
 | |
| "using the files you select from the list box. "
 | |
| "You can intentionally force an error by selecting "
 | |
| "the Bogus files from the list. The error condition "
 | |
| "sticks until you call the ClearError() function to "
 | |
| "fix it";
 | |
| 
 | |
| BOOL CAboutDlg::OnInitDialog() 
 | |
| {
 | |
| 	CDialog::OnInitDialog();
 | |
| 	
 | |
| 	// TODO: Add extra initialization here
 | |
| 	CEdit *edit = (CEdit *) GetDlgItem( IDC_EDIT1 );
 | |
|     if ( edit )
 | |
|         edit->SetWindowText( about );
 | |
| 	return TRUE;  // return TRUE unless you set the focus to a control
 | |
| 	              // EXCEPTION: OCX Property Pages should return FALSE
 | |
| }
 | |
| 
 | |
| 
 | |
| void CEx03mfcDlg::OnCompress() 
 | |
| {
 | |
| 	// TODO: Add your control notification handler code here
 | |
|     delete m_pList;
 | |
|     m_pList = new ALEntryList( m_pMonitor, GlTools() );
 | |
|     m_pList->MakeEntriesFromListBox( m_hWnd, IDC_LIST1 );
 | |
|     m_Archive.Create( *m_pList );
 | |
|     if ( m_Archive.mStatus < 0 )
 | |
|         m_pList->mStatus.SetError( AL_INTERNAL_ERROR, "Failure during compression" );
 | |
|     UpdateStatus();
 | |
| }
 | |
| 
 | |
| void CEx03mfcDlg::OnClear() 
 | |
| {
 | |
| 	// TODO: Add your control notification handler code here
 | |
|     m_Archive.ClearError();
 | |
|     m_pList->ClearError();
 | |
|     UpdateStatus();
 | |
| }
 |