home *** CD-ROM | disk | FTP | other *** search
- //
- // EX04DLG.CPP - Component of MFC Example Program 04
- //
- // C++/DOS Example program for ArchiveLib 2.0
- //
- // Copyright (c) Greenleaf Software, Inc. 1996
- // All Rights Reserved
- //
- // MEMBERS/FUNCTIONS DEMONSTRATED
- //
- // ALCreate()
- //
- // DESCRIPTION
- //
- // This example program demonstrates the simplified interface function
- // ALCreate(). It lets you select a list of files from an input list
- // box, then inserts them into MFC00.ZIP on command. It also demonstrates
- // the use of the callback function for monitoring.
- //
- // REVISION HISTORY
- //
- // March 18, 1996 2.01A : First release
- //
-
- // ex04dlg.cpp : implementation file
- //
-
- #include "ex04std.h"
- #include "ex04mfc.h"
- #include "ex04dlg.h"
- #include "stdio.h"
-
- #include "alsimple.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()
-
- /////////////////////////////////////////////////////////////////////////////
- // CEx04mfcDlg dialog
-
- CEx04mfcDlg::CEx04mfcDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CEx04mfcDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CEx04mfcDlg)
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
-
- void CEx04mfcDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CEx04mfcDlg)
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CEx04mfcDlg, CDialog)
- //{{AFX_MSG_MAP(CEx04mfcDlg)
- 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)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CEx04mfcDlg message handlers
-
- BOOL CEx04mfcDlg::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
- //
- // These members are all used in the callback monitoring
- // function. I initialize them here so that they will
- // be available when I need them. I also fill the list box
- // with the file names from the current directory.
- //
- m_FileName = GetDlgItem( IDC_FILE );
- m_FileProgress = GetDlgItem( IDC_PROGRESS2 );
- m_JobProgress = GetDlgItem( IDC_PROGRESS1 );
- m_ListBox = (CListBox *) GetDlgItem( IDC_LIST1 );
- m_ListBox->Dir( 0, "*.*" );
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- void CEx04mfcDlg::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 CEx04mfcDlg::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 CEx04mfcDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
-
- void CEx04mfcDlg::OnExit()
- {
- // TODO: Add your control notification handler code here
- PostMessage( WM_QUIT, 0, 0 );
- }
-
- BOOL CEx04mfcDlg::DestroyWindow()
- {
- // TODO: Add your specialized code here and/or call the base class
- return CDialog::DestroyWindow();
- }
-
- void CEx04mfcDlg::OnAbout()
- {
- // TODO: Add your control notification handler code here
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
-
- BOOL CAboutDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
-
-
- //
- // The callback function under the simplified
- // interface isn't a class member. So, in order
- // to find the information I need to update the
- // user interface, I have to determine what the
- // current window object is. To do that, I have
- // to track down the main window of this app by
- // looking at the member of theApp that holds it.
- // Once I have that, updating the user interface
- // elements is a breeze.
- //
- extern CEx04mfcApp theApp;
-
- void AL_EXPORT AL_DLL_FAR my_callback( const char AL_DLL_FAR *name,
- int object_ratio,
- int job_ratio )
- {
- CEx04mfcDlg *w = (CEx04mfcDlg *) theApp.m_pMainWnd;
- if ( name ) {
- w->m_FileName->SetWindowText( name );
- //
- // This tricky bit turns off the selection status of
- // a file when it is opened.
- //
- int i = w->m_ListBox->FindString( -1, name );
- if ( i >= 0 ) {
- w->m_ListBox->SetSel( i, 0 );
- }
- }
- if ( object_ratio > 0 )
- w->m_FileProgress->SendMessage( PBM_SETPOS, object_ratio, object_ratio );
- if ( job_ratio > 0 )
- w->m_JobProgress->SendMessage( PBM_SETPOS, job_ratio, job_ratio );
- }
-
- //
- // When the compress button is pressed, I do a couple of things.
- // First, I disable the compress button for the duration of the
- // app. Second, I build a long string containing all of the file
- // names, and I separate them by commas. Given that, the call
- // to ALCreate() is a breeze.
- //
- void CEx04mfcDlg::OnCompress()
- {
- // TODO: Add your control notification handler code here
- CString s = "";
- for ( int i = 0 ; i < m_ListBox->GetCount() ; i++ ) {
- if ( m_ListBox->GetSel( i ) > 0 ) {
- CString s1;
- if ( s != "" )
- s += ",";
- m_ListBox->GetText( i, s1 );
- s += s1;
- }
- }
- CButton *b = (CButton *) GetDlgItem( IDC_COMPRESS );
- b->EnableWindow( 0 );
- ALCreate( "mfc00.zip", s, 0, my_callback );
- b->EnableWindow( 1 );
- }
-