home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / vrac / altd201a.zip / EXAMPLES.ARJ / EXAMPLES / EX24WIN.C < prev    next >
C/C++ Source or Header  |  1996-04-19  |  8KB  |  258 lines

  1. /*
  2.  * EX24WIN.C
  3.  *
  4.  *  C/Windows Example program for ArchiveLib 1.0
  5.  *
  6.  *  Copyright (c) Greenleaf Software, Inc. 1996
  7.  *  All Rights Reserved
  8.  *
  9.  * MEMBERS/FUNCTIONS DEMONSTRATED
  10.  *
  11.  *  ALCreate()
  12.  *
  13.  * DESCRIPTION
  14.  *
  15.  *  This example program creates an archive and adds files to it, while
  16.  *  using an ALBarGraph monitor.  By default it uses BUILD*.* and
  17.  *  *.BAK as its input files, but you can modify this by entering new
  18.  *  data in the AL_INPUT_FILES text box.
  19.  *
  20.  *  This program uses a dialog as its main window.  Unlike most of the
  21.  *  other Windows examples, this guy doesn't have a dummy frame window
  22.  *  around the dialog.
  23.  *
  24.  *  The program also demonstrates the use of a callback function
  25.  *  under the simplified interface.  The callback function is
  26.  *  called periodically, and takes care of keepin the user interface
  27.  *  updated.
  28.  *
  29.  * REVISION HISTORY
  30.  *
  31.  *  March 18, 1996  2.01A  : Added documentation and prepared for
  32.  *                           the simple interface test drive package.
  33.  */
  34.  
  35. #define STRICT
  36. #include <windows.h>
  37. #include <stdarg.h>
  38.  
  39. #include "alsimple.h"
  40. #include "ex24win.h"
  41. #include "algauge.h"
  42. /*
  43.  * I don't have a 32 bit version of CTL3D.DLL for Symantec or Microsoft.
  44.  */
  45.  
  46. #if defined( AL_BORLAND ) || !defined( AL_FLAT_MODEL )
  47. #define AL_3D
  48. #include "ctl3d.h"
  49. #else
  50. #define Ctl3dColorChange()
  51. #define Ctl3dRegister( a )
  52. #define Ctl3dAutoSubclass( a )
  53. #define Ctl3dUnregister( a )
  54. #endif
  55.  
  56. int iInstanceNumber;
  57. HINSTANCE hInstance;
  58.  
  59. BOOL AL_EXPORT CALLBACK AboutDialogProc( HWND, UINT, WPARAM, LPARAM );
  60.  
  61. HWND dialog;
  62.  
  63. /*
  64.  * This is the callback function that is called during compression.
  65.  * When a file is first opened for insertion into the archive,
  66.  * the filename parameter is passed in the name parameter, and the
  67.  * two ratios are passed with values of -1.  When a progress update
  68.  * is taking place, the name is passed with a value of 0 (null pointer),
  69.  * and the two ratios are passed with valid data.
  70.  *
  71.  */
  72. void AL_EXPORT AL_DLL_FAR my_callback( const char AL_DLL_FAR *name,
  73.                                        int object_ratio,
  74.                                        int job_ratio )
  75. {
  76.     if ( name )
  77.         SetDlgItemText( dialog, AL_PROGRESS_TEXT, name );
  78.     if ( object_ratio > 0 )
  79.         SendMessage( GetDlgItem( dialog, AL_FILE_PROGRESS ),
  80.                      ALGaugeSetPosition,
  81.                      object_ratio,
  82.                      object_ratio );
  83.     if ( job_ratio > 0 )
  84.         SendMessage( GetDlgItem( dialog, AL_JOB_PROGRESS ),
  85.                      ALGaugeSetPosition,
  86.                      job_ratio,
  87.                      job_ratio );
  88. }
  89.  
  90. /*
  91.  * This the routine that gets invoked in response to the user pressing
  92.  * the compress button.  This is dispatched from the dialog procedure.
  93.  * It calls ALCreate() in the simplifed interface, which does all of
  94.  * the hard work.
  95.  */
  96.  
  97. void Compress( HWND hDlg )
  98. {
  99.     char archive_name[ 128 ];
  100.     char input_name[ 128 ];
  101.  
  102.     EnableWindow( GetDlgItem( hDlg, AL_COMPRESS ), 0 );
  103.     dialog = hDlg;
  104.     GetDlgItemText( hDlg, AL_ARCHIVE_NAME, archive_name, 128 );
  105.     GetDlgItemText( hDlg, AL_INPUT_FILES, input_name, 128 );
  106.     ALCreate( archive_name, input_name, 0, (CALLBACK_FN) my_callback );
  107.     dialog = 0;
  108.     EnableWindow( GetDlgItem( hDlg, AL_COMPRESS ), 1 );
  109. }
  110.  
  111.  
  112. /*
  113.  * This is the dialog procedure for our main dialog.  In this program, all
  114.  * the important work gets done here.  Most of it gets down by the
  115.  * handler for WM_COMMAND, which processes the button presses from the
  116.  * dialog.
  117.  */
  118.  
  119. BOOL AL_EXPORT CALLBACK MainDialogProc( HWND hDlg,
  120.                                         UINT message,
  121.                                         WPARAM wParam,
  122.                                         LPARAM lParam )
  123. {
  124.     RECT rc;
  125.     char buf[ 81 ];
  126.  
  127.     AL_UNUSED_PARAMETER( lParam );
  128.     switch ( message ) {
  129. /*
  130.  * We respond to the init message by positioning the dialog on the screen,
  131.  * initializing the windows title, the setting up the initial values of
  132.  * all the text boxes.
  133.  */
  134.         case WM_INITDIALOG :
  135.             GetWindowRect( hDlg, &rc );
  136.             SetWindowPos( hDlg,
  137.                           0,
  138.                           ((GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2),
  139.                           ((GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2),
  140.                           0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
  141.             wsprintf( buf, "Windows example 24 <instance %d>", iInstanceNumber );
  142.             SetWindowText( hDlg, buf );
  143.             wsprintf( buf, "WIN%02d.ZIP", iInstanceNumber );
  144.             SetDlgItemText( hDlg, AL_ARCHIVE_NAME, buf );
  145.             SetDlgItemText( hDlg, AL_INPUT_FILES, "BUILD*.*, *.BAK" );
  146.             SetDlgItemText( hDlg, AL_PROGRESS_TEXT, "" );
  147.             return( TRUE );
  148. /*
  149.  * Have to support this message in order to make the CTL3D stuff work.
  150.  */
  151.         case WM_SYSCOLORCHANGE :
  152.            Ctl3dColorChange();
  153.            break;
  154. /*
  155.  * WM_COMMAND is for all the button presses.
  156.  */
  157.         case WM_COMMAND :
  158.             switch ( wParam ) {
  159. /*
  160.  * If the user wants to compress, we do so, but only if no compression
  161.  * is already in progress.
  162.  */
  163.                 case AL_COMPRESS :
  164.                     if ( !dialog )
  165.                         Compress( hDlg );
  166.                     return TRUE;
  167. /*
  168.  * Note that when you are using the simplified interface, there
  169.  * isn't a quick and easy way to abort your compression routine.
  170.  */
  171.                 case AL_EXIT :
  172.                 case WM_QUIT :
  173.                 case WM_DESTROY :
  174.                     if ( dialog == 0 ) {
  175.                         EndDialog( hDlg, TRUE );
  176.                         return TRUE;
  177.                     }
  178.                     return FALSE;
  179.                 case AL_ABOUT :
  180.                     DialogBox( hInstance, "ALAboutDialog", 0, (DLGPROC) AboutDialogProc );
  181.                     return TRUE;
  182.             }
  183.             break;
  184.     }
  185.     return FALSE;
  186. }
  187.  
  188.  
  189. /*
  190.  * The about procedure just displays the about box.
  191.  */
  192. BOOL AL_EXPORT CALLBACK AboutDialogProc( HWND hDlg,
  193.                                          UINT message,
  194.                                          WPARAM wParam,
  195.                                          LPARAM lParam )
  196. {
  197.     RECT rc;
  198.  
  199.     AL_UNUSED_PARAMETER( lParam );
  200.  
  201.     switch ( message ) {
  202.         case WM_INITDIALOG :
  203.             GetWindowRect( hDlg, &rc );
  204.             SetWindowPos( hDlg,
  205.                           0,
  206.                           ((GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2),
  207.                           ((GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2),
  208.                           0, 0, SWP_NOSIZE | SWP_NOACTIVATE );
  209.             break;
  210.         case WM_COMMAND :
  211.             switch ( wParam ) {
  212.                 case IDOK :
  213.                 case AL_EXIT :
  214.                 case WM_QUIT :
  215.                 case WM_DESTROY :
  216.                     EndDialog( hDlg, TRUE );
  217.                     return TRUE;
  218.  
  219.             }
  220.             break;
  221.     }
  222.     return FALSE;
  223. }
  224.  
  225. /*
  226.  * WinMain just has to dispatch the dialog box.  It also calls the routine
  227.  * to register the ALGauge class, and it also sets up the CTL3d stuff.  Note
  228.  * that you can run multiple instances of this program, (good for testing
  229.  * the DLL), so we also get some instance info.
  230.  */
  231.  
  232. int AL_WIN_MAIN_FAR PASCAL WinMain( HINSTANCE instance,
  233.                                     HINSTANCE previous_instance,
  234.                                     LPSTR cmd_line,
  235.                                     int cmd_show )
  236. {
  237.         AL_UNUSED_PARAMETER( cmd_line );
  238.         AL_UNUSED_PARAMETER( cmd_show );
  239.  
  240.     hInstance = instance;
  241.     if ( previous_instance == 0 )
  242.         iInstanceNumber = 0;
  243. #if !defined( AL_FLAT_MODEL )
  244.     else {
  245.         GetInstanceData( previous_instance,
  246.                          (PBYTE)(void _near *)&iInstanceNumber,
  247.                          sizeof iInstanceNumber );
  248.         iInstanceNumber++;
  249.     }
  250. #endif
  251.     ALGaugeInit( hInstance, previous_instance );
  252.     Ctl3dRegister( instance );
  253.     Ctl3dAutoSubclass( instance );
  254.     DialogBox( instance, "ALMainDialog", 0, (DLGPROC) MainDialogProc );
  255.     Ctl3dUnregister( instance );
  256.     return 0;
  257. }
  258.