home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / memsz231.zip / CONFIG.CPP < prev    next >
Text File  |  1994-02-14  |  11KB  |  287 lines

  1. /***************************************************************** CONFIG.CPP
  2.  *                                                                          *
  3.  *                        Clock Configuration Dialog                        *
  4.  *                                                                          *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_BASE
  8. #define INCL_PM
  9. #define INCL_WINSTDSPIN
  10. #include <os2.h>
  11.  
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #include "debug.h"
  16. #include "support.h"
  17.  
  18. #include "memsize.h"
  19. #include "config.h"
  20.  
  21.  
  22. /****************************************************************************
  23.  *                                                                          *
  24.  *                     Definitions & Declarations                           *
  25.  *                                                                          *
  26.  ****************************************************************************/
  27.  
  28.   // Function Prototypes
  29.  
  30. static METHODFUNCTION InitDlg ;
  31. static METHODFUNCTION Command ;
  32. static METHODFUNCTION OK ;
  33. static METHODFUNCTION Cancel ;
  34.  
  35.  
  36. /****************************************************************************
  37.  *                                                                          *
  38.  *      "Configure" Dialog Processor                                            *
  39.  *                                                                          *
  40.  ****************************************************************************/
  41.  
  42. extern MRESULT EXPENTRY ConfigureProcessor
  43. (
  44.   HWND hwnd,
  45.   ULONG msg,
  46.   MPARAM mp1,
  47.   MPARAM mp2
  48. )
  49. {
  50.  /***************************************************************************
  51.   *                             Declarations                                *
  52.   ***************************************************************************/
  53.  
  54.   static METHOD Methods [] =
  55.   {
  56.     { WM_INITDLG, InitDlg },
  57.     { WM_COMMAND, Command }
  58.   } ;
  59.  
  60.  /***************************************************************************
  61.   * Dispatch the message according to the method table and return the       *
  62.   *   result.  Any messages not defined above get handled by the system     *
  63.   *   default dialog processor.                                             *
  64.   ***************************************************************************/
  65.  
  66.   return ( DispatchMessage ( hwnd, msg, mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), WinDefDlgProc ) ) ;
  67. }
  68.  
  69. /****************************************************************************
  70.  *                                                                          *
  71.  *      Initialize Dialog                                                   *
  72.  *                                                                          *
  73.  ****************************************************************************/
  74.  
  75. static MRESULT APIENTRY InitDlg
  76.   HWND hwnd, 
  77.   ULONG msg,
  78.   MPARAM mp1, 
  79.   MPARAM mp2
  80. )
  81. {
  82.  /***************************************************************************
  83.   * Get initial parameters.                                                 *
  84.   ***************************************************************************/
  85.  
  86.   PCONFIG_PARMS Parms = (PCONFIG_PARMS) ( PVOIDFROMMP ( mp2 ) ) ;
  87.  
  88.   WinSetWindowPtr ( hwnd, QWL_USER, Parms ) ;
  89.  
  90.  /***************************************************************************
  91.   * Associate the help instance.                                            *
  92.   ***************************************************************************/
  93.  
  94.   WinSetWindowUShort ( hwnd, QWS_ID, Parms->id ) ;
  95.  
  96.   if ( Parms->hwndHelp )
  97.   {
  98.     WinAssociateHelpInstance ( Parms->hwndHelp, hwnd ) ;
  99.   }
  100.  
  101.  /***************************************************************************
  102.   * Load the list box.                                                      *
  103.   ***************************************************************************/
  104.  
  105.   for ( int i=0; i<Parms->ItemCount; i++ )
  106.   {
  107.     WinSendDlgItemMsg ( hwnd, IDD_CONFIG_ITEMS, LM_INSERTITEM,
  108.       MPFROMSHORT(LIT_END), MPFROMP(Parms->ItemNames[i]) ) ;
  109.  
  110.     if ( Parms->ItemFlags[i] )
  111.     {
  112.       WinSendDlgItemMsg ( hwnd, IDD_CONFIG_ITEMS, LM_SELECTITEM,
  113.         MPFROMSHORT(SHORT(i)), MPFROMSHORT(TRUE) ) ;
  114.     }
  115.   }
  116.  
  117.  /***************************************************************************
  118.   * Set the radio button and checkbox values.                               *
  119.   ***************************************************************************/
  120.  
  121.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_HIDECONTROLS,
  122.     BM_SETCHECK, MPFROMSHORT(Parms->HideControls), 0 ) ;
  123.  
  124.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_FLOAT,
  125.     BM_SETCHECK, MPFROMSHORT(Parms->Float), 0 ) ;
  126.  
  127.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_ANIMATE,
  128.     BM_SETCHECK, MPFROMSHORT(Parms->Animate), 0 ) ;
  129.  
  130.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_FSNAME,
  131.     BM_SETCHECK, MPFROMSHORT(Parms->ShowFileSystemNames), 0 ) ;
  132.  
  133.  /***************************************************************************
  134.   * Set the limits and initial value of the spin-button controls.           *
  135.   ***************************************************************************/
  136.  
  137.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_PRIORITY,
  138.     SPBM_SETLIMITS, (MPARAM)PRTYD_MAXIMUM, (MPARAM)0 ) ;
  139.  
  140.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_PRIORITY,
  141.     SPBM_SETCURRENTVALUE, (MPARAM)(Parms->MonitorPriority), NULL ) ;
  142.  
  143.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_TIMER,
  144.     SPBM_SETLIMITS, (MPARAM)300L, (MPARAM)10L ) ;
  145.  
  146.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_TIMER,
  147.     SPBM_SETCURRENTVALUE, (MPARAM)(Parms->TimerInterval/100), NULL ) ;
  148.  
  149.  /***************************************************************************
  150.   * Return without error.                                                   *
  151.   ***************************************************************************/
  152.  
  153.   return ( MRFROMSHORT ( FALSE ) ) ;
  154. }
  155.  
  156. /****************************************************************************
  157.  *                                                                          *
  158.  *      Process commands received by the Configure Dialog                       *
  159.  *                                                                          *
  160.  ****************************************************************************/
  161.  
  162. static MRESULT APIENTRY Command
  163.   HWND hwnd, 
  164.   ULONG msg, 
  165.   MPARAM mp1, 
  166.   MPARAM mp2
  167. )
  168. {
  169.  /***************************************************************************
  170.   * Local Declarations                                                      *
  171.   ***************************************************************************/
  172.  
  173.   static METHOD Methods [] =
  174.   {
  175.     { DID_OK,     OK     },
  176.     { DID_CANCEL, Cancel },
  177.   } ;
  178.  
  179.  /***************************************************************************
  180.   * Dispatch the message without a default message processor.               *
  181.   ***************************************************************************/
  182.  
  183.   return ( DispatchMessage ( hwnd, SHORT1FROMMP(mp1), mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), PFNWP(NULL) ) ) ;
  184. }
  185.  
  186. /****************************************************************************
  187.  *                                                                          *
  188.  *      Process the Configure Dialog's OK button being pressed.             *
  189.  *                                                                          *
  190.  ****************************************************************************/
  191.  
  192. static MRESULT APIENTRY OK
  193.   HWND hwnd, 
  194.   ULONG msg, 
  195.   MPARAM mp1, 
  196.   MPARAM mp2
  197. )
  198. {
  199.  /***************************************************************************
  200.   * Find the instance data.                                                 *
  201.   ***************************************************************************/
  202.  
  203.   PCONFIG_PARMS Parms = PCONFIG_PARMS ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  204.  
  205.  /***************************************************************************
  206.   * Query the list box items for their selection.                           *
  207.   ***************************************************************************/
  208.  
  209.   for ( int i=0; i<Parms->ItemCount; i++ ) {
  210.     Parms->ItemFlags[i] = FALSE ;
  211.   }
  212.  
  213.   SHORT Selection = LIT_FIRST ;
  214.   do {
  215.     Selection = BOOL ( SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  216.       IDD_CONFIG_ITEMS, LM_QUERYSELECTION,
  217.       MPFROMSHORT(SHORT(Selection)), 0 ) ) ) ;
  218.  
  219.     if ( Selection != LIT_NONE ) {
  220.       Parms->ItemFlags[Selection] = TRUE ;
  221.     }
  222.   }
  223.   while ( Selection != LIT_NONE ) ;
  224.  
  225.  /***************************************************************************
  226.   * Query the buttons for their new settings.                               *
  227.   ***************************************************************************/
  228.  
  229.   Parms->HideControls = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  230.     IDD_CONFIG_HIDECONTROLS, BM_QUERYCHECK, 0L, 0L ) ) ;
  231.  
  232.   Parms->Float = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  233.     IDD_CONFIG_FLOAT, BM_QUERYCHECK, 0L, 0L ) ) ;
  234.  
  235.   Parms->Animate = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  236.     IDD_CONFIG_ANIMATE, BM_QUERYCHECK, 0L, 0L ) ) ;
  237.  
  238.   Parms->ShowFileSystemNames = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  239.     IDD_CONFIG_FSNAME, BM_QUERYCHECK, 0L, 0L ) ) ;
  240.  
  241.  /***************************************************************************
  242.   * Query the spinbuttons for their new settings.                           *
  243.   ***************************************************************************/
  244.  
  245.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_PRIORITY, SPBM_QUERYVALUE,
  246.     &Parms->MonitorPriority, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID) ) ;
  247.  
  248.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_TIMER, SPBM_QUERYVALUE,
  249.     &Parms->TimerInterval, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID) ) ;
  250.  
  251.   Parms->TimerInterval *= 100 ;
  252.  
  253.  /***************************************************************************
  254.   * Dismiss the dialog with a TRUE status.                                  *
  255.   ***************************************************************************/
  256.  
  257.   WinDismissDlg ( hwnd, TRUE ) ;
  258.  
  259.   return ( 0 ) ;
  260. }
  261.  
  262. /****************************************************************************
  263.  *                                                                          *
  264.  *      Process the Configure Dialog's being cancelled.                     *
  265.  *                                                                          *
  266.  ****************************************************************************/
  267.  
  268. static MRESULT APIENTRY Cancel
  269.   HWND hwnd, 
  270.   ULONG msg, 
  271.   MPARAM mp1, 
  272.   MPARAM mp2
  273. )
  274. {
  275.  /***************************************************************************
  276.   * Dismiss the dialog with a TRUE status.                                  *
  277.   ***************************************************************************/
  278.  
  279.   WinDismissDlg ( hwnd, FALSE ) ;
  280.  
  281.   return ( 0 ) ;
  282. }
  283.