home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a039 / 3.ddi / WINSAMP.ZIP / DIALOGS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-11  |  15.2 KB  |  457 lines

  1. #include "wfonedex.h"
  2. #include "pxengine.h"
  3.  
  4. #include <stdlib.h>
  5.  
  6. /******************************************************************************
  7.  
  8.     Function:
  9.  
  10.         BOOL FAR PASCAL FonedexDlgProc( HWND hDlg, unsigned iMessage, WORD wParam,
  11.                                         LONG lParam );
  12.  
  13.     Arguments:
  14.         hDlg            HWND dialogbox handle
  15.         iMessage        unsigned which is type of message
  16.         wParam          WORD parameter
  17.         lParam          LONG parameter
  18.  
  19.     Description:
  20.         Processes messages for dialog box.
  21.         The user can add, delete, update, and search for items in the
  22.         phone database.
  23.  
  24.     Returns:
  25.         TRUE is returned to Windows if it processes a message,
  26.         and FALSE ( 0 ) if DefDlgProc should handle the message.
  27.  
  28. ******************************************************************************/
  29. BOOL FAR PASCAL FonedexDlgProc( HWND hDlg, unsigned iMessage, WORD wParam,
  30.                                 LONG lParam )
  31. {
  32.     char Buffer[MAXFIELDSIZE];
  33.     HCURSOR hCursor;
  34.  
  35.     FARPROC lpfnAboutDlgProc;
  36.     static FARPROC lpfnSearchDlgProc;
  37.     static int bAutoUpdate = FALSE;  /* At start, Auto-update is turned off. */
  38.  
  39.     /*
  40.         nCurrentField is the id of the most recently selected field of the
  41.         fonedex form; nCurrentField - IDD_FIRST is the index into the array
  42.         'names' that is the name of the field.
  43.     */
  44.     static WORD nCurrentField = IDD_LASTNAMEEDIT;
  45.  
  46.  
  47.     switch ( iMessage )
  48.     {
  49.         case WM_INITDIALOG:
  50.  
  51.             lpfnSearchDlgProc = MakeProcInstance( SearchDlgProc, hInst );
  52.  
  53.             /* If the initialization fails, exit */
  54.             if ( Init() ) {
  55.                 SendMessage( hDlg, WM_CLOSE, 0, 0L );
  56.                 break;
  57.             }
  58.  
  59.             /* If the table is not empty, display first record. */
  60.             if ( PXRecFirst( tblHandle ) == PXERR_TABLEEMPTY )
  61.                 break;
  62.             bAutoUpdate = FALSE;
  63.             PostMessage( hDlg, WM_COMMAND, IDD_HOME, 0L );
  64.  
  65.             break;
  66.  
  67.         case WM_COMMAND:
  68.             switch ( wParam )
  69.             {
  70.                 case IDD_LASTNAMEEDIT:
  71.                 case IDD_FIRSTNAMEEDIT:
  72.                 case IDD_ADDRESSEDIT:
  73.                 case IDD_CITYEDIT:
  74.                 case IDD_STATEEDIT:
  75.                 case IDD_ZIPEDIT:
  76.                 case IDD_PHONEEDIT:
  77.                 case IDD_DATEEDIT:
  78.                 case IDD_NOTESEDIT:
  79.  
  80.                     /* Set field on which to search to field corresponding to
  81.                        current edit control */
  82.                     if ( HIWORD( lParam ) == EN_SETFOCUS )
  83.                         nCurrentField = wParam;
  84.                     break;
  85.  
  86.                 case IDD_NEWRECORD:
  87.  
  88.                     /* Before creating a new record, save current record
  89.                        if necessary. */
  90.                     if ( bAutoUpdate )
  91.                         ProcessRecord();
  92.                     GetDlgItemText( hDlg, nCurrentField, Buffer,
  93.                                     MAXFIELDSIZE );
  94.  
  95.                     /* Display a blank record and append a new record with
  96.                        blank fields to the Fonedex table. */
  97.                     BlankDisplayedRecord();
  98.                     SetRecord();
  99.                     /* If the new record could not be added to the table
  100.                        (eg, if there already is a record with blank last
  101.                        and first name fields), display record that was
  102.                        current before attempt to append. */
  103.                     if ( Error( PXRecAppend( tblHandle, recHandle ) ) )
  104.                         DisplayRecord();
  105.                     Error( PXRecGet ( tblHandle, recHandle ) );
  106.                     Error( PXRecBufCopy ( recHandle, SaveRecHandle ) );
  107.                     SetFocus( GetDlgItem( hDlg, IDD_LASTNAMEEDIT ) );
  108.                     break;
  109.  
  110.                 case IDD_UPDATE:
  111.  
  112.                     ProcessRecord();
  113.                     break;
  114.  
  115.                 case IDD_DELETE:
  116.  
  117.                     if ( MessageBox( hDlg,
  118.                             "Are you sure you want to delete the current record from the Fonedex?",
  119.                             "Delete Current Record",
  120.                             MB_OKCANCEL | MB_DEFBUTTON2 ) != IDOK )
  121.                         break;
  122.                     Error( PXRecDelete( tblHandle ) );
  123.                     DisplayRecord();
  124.  
  125.                     break;
  126.  
  127.                 case IDD_EMPTYTABLE:
  128.  
  129.                     if ( MessageBox( hDlg,
  130.                             "Are you sure you want to empty the Fonedex?",
  131.                             "Empty Table",
  132.                             MB_OKCANCEL | MB_DEFBUTTON2 ) != IDOK )
  133.                         break;
  134.  
  135.                     hCursor = SetCursor( LoadCursor( NULL, IDC_WAIT ) );
  136.                     /* The table must be closed before it can be emptied. */
  137.                     if( CloseFonedex() == FALSE )
  138.                     {
  139.                         Message( "Table could not be emptied." );
  140.                     }
  141.  
  142.                     /* Remove all records from the table */
  143.                     Error( PXTblEmpty( DATAFILE ) );
  144.  
  145.                     /* Reopen the (now empty) table. */
  146.                     OpenFonedex();
  147.  
  148.                     BlankDisplayedRecord();
  149.  
  150.                     SetCursor( hCursor );
  151.  
  152.                     break;
  153.  
  154.                 case IDD_SEARCH:
  155.  
  156.                     /* Refresh Table for Multi User Environment */
  157.                     PXNetTblRefresh( tblHandle );
  158.                     /* Before performing search, save current record
  159.                        if necessary. */
  160.                     if ( bAutoUpdate )
  161.                         ProcessRecord();
  162.                     DialogBox( hInst, "Search", hDlg, lpfnSearchDlgProc );
  163.                     break;
  164.  
  165.                 case IDD_AUTOUPDATE:
  166.  
  167.                     bAutoUpdate = !bAutoUpdate;
  168.                     CheckDlgButton( hDlg, IDD_AUTOUPDATE, bAutoUpdate );
  169.                     break;
  170.  
  171.                 case IDD_HOME:
  172.  
  173.                     /* Refresh Table for Multi User Environment */
  174.                     PXNetTblRefresh( tblHandle );
  175.                     /* Before changing record, save current record
  176.                        if necessary. */
  177.                     if ( bAutoUpdate )
  178.                         ProcessRecord();
  179.                     /* Move to the first record of the table. */
  180.                     if ( Error( PXRecFirst( tblHandle ) ) )
  181.                         break;
  182.                     DisplayRecord();
  183.                     break;
  184.  
  185.                 case IDD_PRIOR:
  186.                     
  187.                     PXNetTblRefresh( tblHandle );
  188.                     if ( bAutoUpdate )
  189.                         ProcessRecord();
  190.                     /* Move to the previous record of the table. */
  191.                     if ( Error( PXRecPrev( tblHandle ) ) )
  192.                         break;
  193.                     DisplayRecord();
  194.                     break;
  195.  
  196.                 case IDD_NEXT:
  197.  
  198.                     PXNetTblRefresh( tblHandle );
  199.                     if ( bAutoUpdate )
  200.                         ProcessRecord();
  201.                     /* Move to the next record of the table. */
  202.                     if ( Error( PXRecNext( tblHandle ) ) )
  203.                         break;
  204.                     DisplayRecord();
  205.                     break;
  206.  
  207.                 case IDD_END:
  208.  
  209.                     PXNetTblRefresh( tblHandle );
  210.                     if ( bAutoUpdate ) 
  211.                         ProcessRecord();
  212.                     /* Move to the last record of the table. */
  213.                     if ( Error( PXRecLast( tblHandle ) ) )
  214.                         break;
  215.                     DisplayRecord();
  216.                     break;
  217.  
  218.                 case IDD_QUIT:
  219.  
  220.                     /* Before exiting, save current record. */
  221.                     if ( bAutoUpdate )
  222.                         ProcessRecord();
  223.                     SendMessage( hDlg, WM_CLOSE, 0, 0L );
  224.                     break;
  225.  
  226.                 default:
  227.  
  228.                     return FALSE;
  229.             }
  230.             break;
  231.  
  232.         case WM_SYSCOMMAND:
  233.             switch ( wParam )
  234.             {
  235.                 case IDM_ABOUT:
  236.  
  237.                     lpfnAboutDlgProc = MakeProcInstance( AboutDlgProc, hInst );
  238.                     DialogBox( hInst, "About", hDlg, lpfnAboutDlgProc );
  239.                     FreeProcInstance( lpfnAboutDlgProc );
  240.                     break;
  241.  
  242.                 default:
  243.                     return FALSE;
  244.             }
  245.             break;
  246.  
  247.         case WM_CLOSE:
  248.  
  249.             FreeProcInstance( lpfnSearchDlgProc );
  250.  
  251.             /* If the table is open, close it and free the record buffer. */
  252.             if ( TableIsOpen )
  253.                 CloseFonedex();
  254.  
  255.             /* Terminate the engine. */
  256.             Error( PXExit() );
  257.  
  258.             /* Send a WM_DESTROY message. */
  259.             DestroyWindow( hDlg );
  260.             hDlgModeless = 0;
  261.             break;
  262.  
  263.         case WM_DESTROY:
  264.  
  265.             PostQuitMessage( 0 );
  266.             break;
  267.  
  268.         default:
  269.  
  270.             return FALSE;
  271.     }
  272.  
  273.     return FALSE;
  274. }
  275.  
  276.  
  277. /******************************************************************************
  278.  
  279.     Function:
  280.  
  281.         BOOL FAR PASCAL SearchDlgProc( HWND hDlg, unsigned iMessage, WORD wParam,
  282.                                        LONG lParam );
  283.  
  284.     Arguments:
  285.         hDlg            HWND which is the handle to the Search dialog box
  286.         iMessage        unsigned which is type of message
  287.         wParam          WORD parameter
  288.         lParam          LONG parameter
  289.  
  290.     Description:
  291.         Processes messages for Search dialog box.
  292.  
  293.     Returns:
  294.         TRUE is returned to Windows if it processes a message,
  295.         and FALSE ( 0 ) if DefDlgProc should handle the message.
  296.  
  297. ******************************************************************************/
  298. #ifdef __BORLANDC__
  299. #pragma argsused       /* This pragma is used for Borland C++ */
  300. #endif
  301. BOOL FAR PASCAL SearchDlgProc( HWND hDlg, unsigned iMessage, WORD wParam,
  302.                                LONG lParam )
  303. {
  304.     /* Initial values of dialog box settings. */
  305.     static int nSearchField = IDD_LASTNAMEEDIT;
  306.     static int nSearchMode = IDD_SEARCHFIRST;
  307.     static int bContinueSearch = FALSE;
  308.     static char szSearchBuffer[MAXFIELDSIZE] = "";
  309.  
  310.     HCURSOR hCursor;    /* Handle to a cursor. */
  311.  
  312.     switch ( iMessage )
  313.     {
  314.         case WM_INITDIALOG:
  315.  
  316.             /* Make initial button settings. */
  317.             CheckRadioButton( hDlg, IDD_LASTNAMEEDIT, IDD_NOTESEDIT, nSearchField );
  318.             SetDlgItemText( hDlg, IDD_SEARCHSTRINGEDIT, szSearchBuffer );
  319.             CheckRadioButton( hDlg, IDD_SEARCHFIRST, IDD_SEARCHNEXT, nSearchMode );
  320.             CheckDlgButton( hDlg, IDD_CONTINUESEARCH, bContinueSearch );
  321.             PostMessage( hDlg, WM_NEXTDLGCTL, GetDlgItem( hDlg, IDD_SEARCHSTRINGEDIT ) , 1L );
  322.             SendDlgItemMessage( hDlg, IDD_SEARCHSTRINGEDIT, EM_SETSEL, 0, 0xFFFF0000);
  323.             break;
  324.  
  325.         case WM_COMMAND:
  326.             switch ( wParam )
  327.             {
  328.                 /* Determine which field of the table on which to search. */
  329.                 case IDD_LASTNAMEEDIT:
  330.                 case IDD_FIRSTNAMEEDIT:
  331.                 case IDD_ADDRESSEDIT:
  332.                 case IDD_CITYEDIT:
  333.                 case IDD_STATEEDIT:
  334.                 case IDD_ZIPEDIT:
  335.                 case IDD_PHONEEDIT:
  336.                 case IDD_DATEEDIT:
  337.                 case IDD_NOTESEDIT:
  338.  
  339.                     nSearchField = wParam;
  340.                     CheckRadioButton( hDlg, IDD_LASTNAMEEDIT, IDD_NOTESEDIT,
  341.                                       wParam );
  342.                     break;
  343.  
  344.                 /* Determine whether to begin the search at the first record
  345.                    or from the record after the current record. */
  346.                 case IDD_SEARCHFIRST:
  347.                 case IDD_SEARCHNEXT:
  348.  
  349.                     nSearchMode = wParam;
  350.                     CheckRadioButton( hDlg, IDD_SEARCHFIRST, IDD_SEARCHNEXT,
  351.                                       wParam );
  352.                     break;
  353.  
  354.                 /* If this button is checked, another search may be processed
  355.                    without having to reinvoke the search dialog box. */
  356.                 case IDD_CONTINUESEARCH:
  357.  
  358.                     bContinueSearch = !bContinueSearch;
  359.                     CheckDlgButton( hDlg, IDD_CONTINUESEARCH, bContinueSearch );
  360.                     break;
  361.  
  362.                 /* Start the search. */
  363.                 case IDD_OK:
  364.  
  365.                     hCursor = SetCursor( LoadCursor( NULL, IDC_WAIT ) );
  366.                     GetDlgItemText( hDlg, IDD_SEARCHSTRINGEDIT, szSearchBuffer,
  367.                                     MAXFIELDSIZE );
  368.  
  369.                     /*
  370.                         nSearchField - IDD_FIRST + 1 is the (Paradox) field
  371.                         number of the record field on which to search.
  372.                     */
  373.                     if ( ! Search( nSearchField - IDD_FIRST + 1, szSearchBuffer,
  374.                             ( nSearchMode == IDD_SEARCHFIRST ) ? SEARCHFIRST : SEARCHNEXT ) )
  375.                     {
  376.                         MessageBox( hDlg, "Search Failed.", "Search Message",
  377.                             MB_OK | MB_ICONHAND );
  378.                     }
  379.                     SetCursor( hCursor );
  380.  
  381.                     if ( ! bContinueSearch )
  382.                         EndDialog( hDlg, 0 );
  383.                     break;
  384.  
  385.                 /* Exit the dialog box. */
  386.                 case IDD_CANCEL:
  387.  
  388.                     GetDlgItemText( hDlg, IDD_SEARCHSTRINGEDIT, szSearchBuffer,
  389.                                     MAXFIELDSIZE );
  390.                     EndDialog( hDlg, 0 );
  391.                     break;
  392.  
  393.                 default:
  394.  
  395.                     return FALSE;
  396.             }
  397.             break;
  398.  
  399.         case WM_CLOSE:
  400.             SendMessage( hDlg, WM_COMMAND, IDD_CANCEL, 0L );
  401.             break;
  402.  
  403.         default:
  404.  
  405.             return FALSE;
  406.     }
  407.  
  408.     return TRUE;
  409. }
  410.  
  411.  
  412. /******************************************************************************
  413.  
  414.     Function:
  415.  
  416.         BOOL FAR PASCAL AboutDlgProc( HWND hDlg, unsigned iMessage, WORD wParam,
  417.                                       LONG lParam );
  418.  
  419.     Arguments:
  420.         hDlg            HWND dialogbox handle
  421.         iMessage        unsigned which is type of message
  422.         wParam          WORD parameter
  423.         lParam          LONG parameter
  424.  
  425.     Description:
  426.         Processes messages for "About" dialog box
  427.  
  428.     Returns:
  429.         TRUE is returned to Windows if it processes a message,
  430.         and FALSE ( 0 ) if DefDlgProc should handle the message.
  431.  
  432. ******************************************************************************/
  433. #ifdef __BORLANDC__
  434. #pragma argsused        /* This pragma is used for Borland C++ */
  435. #endif
  436. BOOL FAR PASCAL AboutDlgProc( HWND hDlg, unsigned iMessage, WORD wParam,
  437.                               LONG lParam )
  438. {
  439.     switch ( iMessage ) {
  440.  
  441.         case WM_INITDIALOG:
  442.  
  443.             return TRUE;
  444.  
  445.         case WM_COMMAND:
  446.  
  447.             if ( wParam == IDOK || wParam == IDCANCEL ) {
  448.                 EndDialog( hDlg, TRUE );
  449.                 return TRUE;
  450.             }
  451.             break;
  452.  
  453.     }
  454.  
  455.     return FALSE;
  456. }
  457.