271 lines
		
	
	
		
			8.7 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			271 lines
		
	
	
		
			8.7 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
/*
 | 
						|
 * EX24WIN.C
 | 
						|
 *
 | 
						|
 *  C/Windows Example program for ArchiveLib 1.0
 | 
						|
 *
 | 
						|
 *  Copyright (c) Greenleaf Software, Inc. 1994
 | 
						|
 *  All Rights Reserved
 | 
						|
 *
 | 
						|
 * MEMBERS/FUNCTIONS DEMONSTRATED
 | 
						|
 *
 | 
						|
 *  ALStorageSetError()
 | 
						|
 *  deleteALArchive()
 | 
						|
 *  ALArchiveCreate()
 | 
						|
 *  deleteALMonitor()
 | 
						|
 *  newALWindowsMessage()
 | 
						|
 *
 | 
						|
 * DESCRIPTION
 | 
						|
 *
 | 
						|
 *  This example program creates an archive and adds files to it, while
 | 
						|
 *  using an ALBarGraph monitor.  By default it uses INPUT*.DAT and
 | 
						|
 *  *.BAK as its input files, but you can modify this by entering new
 | 
						|
 *  data in the AL_INPUT_FILES text box.
 | 
						|
 *
 | 
						|
 *  This program uses a dialog as its main window.  Unlike most of the
 | 
						|
 *  other Windows examples, this guy doesn't have a dummy frame window
 | 
						|
 *  around the dialog.
 | 
						|
 *
 | 
						|
 *  This program is functionally equivalent to EX00WIN.CPP.  The C version
 | 
						|
 *  uses the translation layer functions to get the job done, but if
 | 
						|
 *  you put them side by side, you won't see too much difference.
 | 
						|
 *
 | 
						|
 * REVISION HISTORY
 | 
						|
 *
 | 
						|
 *  June 12, 1994  1.0A  : First release
 | 
						|
 *
 | 
						|
 *  July 11, 1994  1.0B  : Using AL_EXPORT instead of _export.  This lets
 | 
						|
 *                         the example compile and work properly under NT.
 | 
						|
 *
 | 
						|
 *  January 12, 1995 1.01A : Had to #ifdef out the GetInstanceData()
 | 
						|
 *                           call under Win32.
 | 
						|
 *
 | 
						|
 *  January 12, 1995 1.01A : Munged with the Ctl3d stuff.  Some of my 32
 | 
						|
 *                           bit compilers don't support it, so I need to
 | 
						|
 *                           put a hack in here to quietly turn it on
 | 
						|
 *                           and off.
 | 
						|
 */
 | 
						|
 | 
						|
#define STRICT
 | 
						|
#include <windows.h>
 | 
						|
#include <stdarg.h>
 | 
						|
 | 
						|
#include "arclib.h"
 | 
						|
#include "alsimple.h"
 | 
						|
#include "ex24win.h"
 | 
						|
#include "algauge.h"
 | 
						|
/*
 | 
						|
 * I don't have a 32 bit version of CTL3D.DLL for Symantec or Microsoft.
 | 
						|
 */
 | 
						|
 | 
						|
#if defined( AL_BORLAND ) || !defined( AL_FLAT_MODEL )
 | 
						|
#define AL_3D
 | 
						|
#include "ctl3d.h"
 | 
						|
#else
 | 
						|
#define Ctl3dColorChange()
 | 
						|
#define Ctl3dRegister( a )
 | 
						|
#define Ctl3dAutoSubclass( a )
 | 
						|
#define Ctl3dUnregister( a )
 | 
						|
#endif
 | 
						|
 | 
						|
int iInstanceNumber;
 | 
						|
HINSTANCE hInstance;
 | 
						|
 | 
						|
BOOL AL_EXPORT CALLBACK AboutDialogProc( HWND, UINT, WPARAM, LPARAM );
 | 
						|
 | 
						|
/*
 | 
						|
 * This the routine that gets invoked in response to the user pressing
 | 
						|
 * the compress button.  This is dispatched from the dialog procedure.
 | 
						|
 * It just creates a monitor, then a list, then an archive.  If that
 | 
						|
 * all goes okay, the wild cards get added to the list, then the Create
 | 
						|
 * procedure is called.
 | 
						|
 *
 | 
						|
 * There is one slightly tricky bit here.  The archive handle is kept in
 | 
						|
 * a global variable.  We abort the archiving procedure by calling SetError
 | 
						|
 * for that archive.  This means that we have to be really careful to set
 | 
						|
 * that handle back to zero when we destroy the archive.
 | 
						|
 */
 | 
						|
 | 
						|
HWND dialog;
 | 
						|
 | 
						|
void AL_DLL_FAR my_callback( const char AL_DLL_FAR *name,
 | 
						|
                             int object_ratio,
 | 
						|
                             int job_ratio )
 | 
						|
{
 | 
						|
    if ( name )
 | 
						|
        SetDlgItemText( dialog, AL_PROGRESS_TEXT, name );
 | 
						|
    if ( object_ratio > 0 )
 | 
						|
        SendMessage( GetDlgItem( dialog, AL_FILE_PROGRESS ),
 | 
						|
                     ALGaugeSetPosition,
 | 
						|
                     object_ratio,
 | 
						|
                     object_ratio );
 | 
						|
    if ( job_ratio > 0 )
 | 
						|
        SendMessage( GetDlgItem( dialog, AL_JOB_PROGRESS ),
 | 
						|
                     ALGaugeSetPosition,
 | 
						|
                     job_ratio,
 | 
						|
                     job_ratio );
 | 
						|
}
 | 
						|
 | 
						|
void Compress( HWND hDlg )
 | 
						|
{
 | 
						|
    char archive_name[ 128 ];
 | 
						|
    char input_name[ 128 ];
 | 
						|
 | 
						|
    EnableWindow( GetDlgItem( hDlg, AL_COMPRESS ), 0 );
 | 
						|
    dialog = hDlg;
 | 
						|
    GetDlgItemText( hDlg, AL_ARCHIVE_NAME, archive_name, 128 );
 | 
						|
    GetDlgItemText( hDlg, AL_INPUT_FILES, input_name, 128 );
 | 
						|
    ALCreate( archive_name, input_name, 0, my_callback );
 | 
						|
    dialog = 0;
 | 
						|
    EnableWindow( GetDlgItem( hDlg, AL_COMPRESS ), 1 );
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/*
 | 
						|
 * This is the dialog procedure for our main dialog.  In this program, all
 | 
						|
 * the important work gets done here.  Most of it gets down by the
 | 
						|
 * handler for WM_COMMAND, which processes the button presses from the
 | 
						|
 * dialog.
 | 
						|
 */
 | 
						|
 | 
						|
BOOL AL_EXPORT CALLBACK MainDialogProc( HWND hDlg,
 | 
						|
                                        UINT message,
 | 
						|
                                        WPARAM wParam,
 | 
						|
                                        LPARAM lParam )
 | 
						|
{
 | 
						|
    RECT rc;
 | 
						|
    char buf[ 81 ];
 | 
						|
 | 
						|
    AL_UNUSED_PARAMETER( lParam );
 | 
						|
    switch ( message ) {
 | 
						|
/*
 | 
						|
 * We respond to the init message by positioning the dialog on the screen,
 | 
						|
 * initializing the windows title, the setting up the initial values of
 | 
						|
 * all the text boxes.
 | 
						|
 */
 | 
						|
        case WM_INITDIALOG :
 | 
						|
            GetWindowRect( hDlg, &rc );
 | 
						|
            SetWindowPos( hDlg,
 | 
						|
                          0,
 | 
						|
                          ((GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2),
 | 
						|
                          ((GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2),
 | 
						|
                          0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
 | 
						|
            wsprintf( buf, "Windows example 24 <instance %d>", iInstanceNumber );
 | 
						|
            SetWindowText( hDlg, buf );
 | 
						|
            wsprintf( buf, "WIN%02d.ZIP", iInstanceNumber );
 | 
						|
            SetDlgItemText( hDlg, AL_ARCHIVE_NAME, buf );
 | 
						|
            SetDlgItemText( hDlg, AL_INPUT_FILES, "INPUT*.DAT, *.BAK" );
 | 
						|
            SetDlgItemText( hDlg, AL_PROGRESS_TEXT, "" );
 | 
						|
            return( TRUE );
 | 
						|
/*
 | 
						|
 * Have to support this message in order to make the CTL3D stuff work.
 | 
						|
 */
 | 
						|
        case WM_SYSCOLORCHANGE :
 | 
						|
           Ctl3dColorChange();
 | 
						|
           break;
 | 
						|
/*
 | 
						|
 * WM_COMMAND is for all the button presses.
 | 
						|
 */
 | 
						|
        case WM_COMMAND :
 | 
						|
            switch ( wParam ) {
 | 
						|
/*
 | 
						|
 * If the user wants to compress, we do so, but only if no compression
 | 
						|
 * is already in progress.
 | 
						|
 */
 | 
						|
                case AL_COMPRESS :
 | 
						|
                    if ( !dialog )
 | 
						|
                        Compress( hDlg );
 | 
						|
                    return TRUE;
 | 
						|
/*
 | 
						|
 * If the user wants to quit, I have to set the archive to an error status
 | 
						|
 * first.  Otherwise, the compression code will keep right on going even
 | 
						|
 * after we have killed our dialog window.  Code like this is used all over
 | 
						|
 * the place in all of the example programs.
 | 
						|
 */
 | 
						|
                case AL_EXIT :
 | 
						|
                case WM_QUIT :
 | 
						|
                case WM_DESTROY :
 | 
						|
                    if ( dialog == 0 ) {
 | 
						|
                        EndDialog( hDlg, TRUE );
 | 
						|
                        return TRUE;
 | 
						|
                    }
 | 
						|
                    return FALSE;
 | 
						|
                case AL_ABOUT :
 | 
						|
                    DialogBox( hInstance, "ALAboutDialog", 0, (DLGPROC) AboutDialogProc );
 | 
						|
                    return TRUE;
 | 
						|
            }
 | 
						|
            break;
 | 
						|
    }
 | 
						|
    return FALSE;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/*
 | 
						|
 * The about procedure just displays the about box.
 | 
						|
 */
 | 
						|
BOOL AL_EXPORT CALLBACK AboutDialogProc( HWND hDlg,
 | 
						|
                                         UINT message,
 | 
						|
                                         WPARAM wParam,
 | 
						|
                                         LPARAM lParam )
 | 
						|
{
 | 
						|
    RECT rc;
 | 
						|
 | 
						|
    AL_UNUSED_PARAMETER( lParam );
 | 
						|
 | 
						|
    switch ( message ) {
 | 
						|
        case WM_INITDIALOG :
 | 
						|
            GetWindowRect( hDlg, &rc );
 | 
						|
            SetWindowPos( hDlg,
 | 
						|
                          0,
 | 
						|
                          ((GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2),
 | 
						|
                          ((GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2),
 | 
						|
                          0, 0, SWP_NOSIZE | SWP_NOACTIVATE );
 | 
						|
            break;
 | 
						|
        case WM_COMMAND :
 | 
						|
            switch ( wParam ) {
 | 
						|
                case IDOK :
 | 
						|
                case AL_EXIT :
 | 
						|
                case WM_QUIT :
 | 
						|
                case WM_DESTROY :
 | 
						|
                    EndDialog( hDlg, TRUE );
 | 
						|
                    return TRUE;
 | 
						|
 | 
						|
            }
 | 
						|
            break;
 | 
						|
    }
 | 
						|
    return FALSE;
 | 
						|
}
 | 
						|
 | 
						|
/*
 | 
						|
 * WinMain just has to dispatch the dialog box.  It also calls the routine
 | 
						|
 * to register the ALGauge class, and it also sets up the CTL3d stuff.  Note
 | 
						|
 * that you can run multiple instances of this program, (good for testing
 | 
						|
 * the DLL), so we also get some instance info.
 | 
						|
 */
 | 
						|
 | 
						|
int PASCAL WinMain( HINSTANCE instance,
 | 
						|
                    HINSTANCE previous_instance,
 | 
						|
                    LPSTR cmd_line,
 | 
						|
                    int cmd_show )
 | 
						|
{
 | 
						|
    AL_UNUSED_PARAMETER( cmd_line );
 | 
						|
    AL_UNUSED_PARAMETER( cmd_show );
 | 
						|
 | 
						|
    hInstance = instance;
 | 
						|
    if ( previous_instance == 0 )
 | 
						|
        iInstanceNumber = 0;
 | 
						|
#if !defined( AL_FLAT_MODEL )
 | 
						|
    else {
 | 
						|
        GetInstanceData( previous_instance,
 | 
						|
                         (PBYTE) &iInstanceNumber,
 | 
						|
                         sizeof iInstanceNumber );
 | 
						|
        iInstanceNumber++;
 | 
						|
    }
 | 
						|
#endif
 | 
						|
    ALGaugeInit( hInstance, previous_instance );
 | 
						|
    Ctl3dRegister( instance );
 | 
						|
    Ctl3dAutoSubclass( instance );
 | 
						|
    DialogBox( instance, "ALMainDialog", 0, (DLGPROC) MainDialogProc );
 | 
						|
    Ctl3dUnregister( instance );
 | 
						|
    return 0;
 | 
						|
}
 |