home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a007 / 2.ddi / CWINSAMP.ZIP / DIALOGS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-15  |  12.5 KB  |  471 lines

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