home *** CD-ROM | disk | FTP | other *** search
/ Total C++ 2 / TOTALCTWO.iso / borland / 32addres.pak / ADR_DLGS.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  27KB  |  719 lines

  1. // BDE32 3.x - (C) Copyright 1996 by Borland International
  2.  
  3. #include "address.h"
  4.  
  5. //======================================================================
  6. //  Name:   EditSubClassProc()
  7. //
  8. //  Input:  hWnd, msg, wParam, lParam
  9. //
  10. //  Return: It returns the result of the procedure.  It can return the
  11. //          result of the original edit control if the WM_CHAR is not a
  12. //          tab character.
  13. //
  14. //  Desc:   This routine will process all I/O for the Comments edit
  15. //          control.  It does this by first checking if the tab key was
  16. //          hit inside of the comment edit control.  If it was it moves
  17. //          control to the next control item and then does NOT let the
  18. //          original edit control process the message.  However, if the
  19. //          WM_CHAR is not a tab then it lets the original edit control
  20. //          process the message.
  21. //======================================================================
  22. LPARAM CALLBACK
  23. EditSubClassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  24. {
  25.     LRESULT lResult = 0;
  26.     BOOL    bCallOrigWndProc = TRUE;
  27.  
  28.     switch (msg)
  29.     {
  30.         case WM_CHAR:
  31.             if(wParam == '\t')
  32.             {
  33.                 if(GetKeyState(VK_SHIFT)<0)
  34.                 {
  35.                     SetFocus(GetDlgItem(hMainWnd, IDE_LAST_DATE));
  36.                 }
  37.                 else
  38.                 {
  39.                     if(!NewRecMode)
  40.                     {
  41.                         SetFocus(GetDlgItem(hMainWnd, ID_ORDER));
  42.                         SendMessage(GetDlgItem(hMainWnd, ID_ORDER),
  43.                                     BM_SETSTYLE, (UINT16)BS_DEFPUSHBUTTON,
  44.                                     1L);
  45.                     }
  46.                     else
  47.                     {
  48.                         SetFocus(GetDlgItem(hMainWnd, IDOK));
  49.                         SendMessage(GetDlgItem(hMainWnd, IDOK), BM_SETSTYLE,
  50.                                 (UINT16)BS_DEFPUSHBUTTON, 1L);
  51.                     }
  52.                 }
  53.                 bCallOrigWndProc = FALSE;
  54.             }
  55.             break;
  56.     }
  57.  
  58.     if(bCallOrigWndProc)
  59.     {
  60.         lResult = CallWindowProc((WNDPROC)_wpOrigWndProc, hWnd, msg, wParam,
  61.                                  lParam);
  62.     }
  63.     return(lResult);
  64. }
  65.  
  66. //======================================================================
  67. //  Name:   AboutDlg()
  68. //
  69. //  Input:  hWnd, msg, wParam, lParam
  70. //
  71. //  Return: TRUE -  Dialog Created.
  72. //          FALSE - Dialog Failed to create.
  73. //
  74. //  Desc:   This routine will process all I/O for the ABOUT dialog.
  75. //======================================================================
  76. #ifdef __BORLANDC__
  77. #pragma argsused
  78. #endif
  79. BOOL CALLBACK
  80. AboutDlg (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  81. {
  82.     BOOL    bRet = FALSE;
  83.  
  84. #ifndef WIN32
  85.     // Done to clear the unused warning.
  86.     lParam = lParam;
  87. #endif
  88.  
  89.     switch (msg)
  90.     {
  91.         case WM_COMMAND:
  92.             switch (GET_WM_COMMAND_ID(wParam,lParam))
  93.             {
  94.                 case IDOK:
  95.                 case IDCANCEL:
  96.                     bRet = TRUE;
  97.                     EndDialog(hWnd, bRet);
  98.                     break;
  99.             }
  100.             break;
  101.     }
  102.     return(bRet);
  103. }
  104.  
  105. //======================================================================
  106. //  Name:   OrderDlg()
  107. //
  108. //  Input:  hWnd, msg, wParam, lParam.  The lParam here also contains
  109. //          the pointer to the cursor during the WM_INITDIALOG.
  110. //
  111. //  Return: TRUE -  The Index was set.
  112. //          FALSE - Index failed or user canceled the dilaog box.
  113. //
  114. //  Desc:   This routine will process all I/O for the dialog that will
  115. //          change the order  of the table (i.e. place an index).
  116. //======================================================================
  117. BOOL CALLBACK
  118. OrderDlg (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  119. {
  120.     static  phDBICur    phCur;
  121.     static  hDBIDb      hDb;
  122.     static  CHAR        szStartIndex[DBIMAXNAMELEN];
  123.     static  UINT16      iStartIndex = 0;
  124.     static  pABIDXDESC  pABIdxDesc = NULL;
  125.     static  UINT16      iNumIdxs = 0;
  126.  
  127.     UINT32      lIndex;
  128.     UINT32      lSel;
  129.     BOOL        bRet = FALSE;
  130.  
  131.     hErrorWnd = hWnd;
  132.     switch (msg)
  133.     {
  134.         case WM_INITDIALOG:
  135.  
  136.             // Get the cursor and database from the lParam of the dialog
  137.             // box.  It was sent in when creating the dialog box.
  138.             phCur = ((pAbHandles)(lParam))->phCur;
  139.             hDb = ((pAbHandles)(lParam))->hDb;
  140.  
  141.             PostMessage(hWnd, WM_SETUP, 0, 0L);
  142.  
  143.             return TRUE;
  144.  
  145.         case WM_SETUP:
  146.  
  147.             // Get the presently active index and fill the index structure
  148.             // with all the indexes that are open on the table.
  149.             if(FillIndexStr(*phCur, hDb, &pABIdxDesc, szStartIndex,
  150.                             &iNumIdxs)!=DBIERR_NONE)
  151.             {
  152.                 SendMessage(hWnd, WM_DESTROY, 0, 0L);
  153.             }
  154.  
  155.             // Fill the list box with all the index names, and set
  156.             // the name of the current index in the edit control of the
  157.             // ComboBox.
  158.             iStartIndex = FillDropList(hWnd, IDE_ORDER_COMBOBOX, iNumIdxs,
  159.                                        pABIdxDesc, szStartIndex);
  160.             break;
  161.  
  162.         case WM_DESTROY:
  163.             if(pABIdxDesc)
  164.             {
  165.                 free(pABIdxDesc);
  166.             }
  167.             break;
  168.  
  169.         case WM_COMMAND:
  170.             switch (GET_WM_COMMAND_ID(wParam,lParam))
  171.             {
  172.                 case IDE_ORDER_COMBOBOX:
  173.  
  174.                     // Add the item's position in the index array as an item
  175.                     // data.
  176.                     switch (GET_WM_COMMAND_CMD(wParam,lParam))
  177.                     {
  178.                         case CBN_SELCHANGE:
  179.                             lSel = ComboBox_GetCurSel(
  180.                                           GetDlgItem(hWnd, IDE_ORDER_COMBOBOX));
  181.                             lIndex = ComboBox_GetItemData(
  182.                                            GetDlgItem(hWnd, IDE_ORDER_COMBOBOX),
  183.                                            lSel);
  184.  
  185.                             // Put the Index Key Expression in the static
  186.                             // text box.
  187.                             SetWindowText(GetDlgItem(hWnd, IDE_ORDER_INFO),
  188.                                     pABIdxDesc[(UINT16)lIndex].szKeyExp);
  189.                             break;
  190.                     }
  191.                     break;
  192.                 case IDOK:
  193.                     // Get the selected item and its item data.
  194.                     lSel = ComboBox_GetCurSel(
  195.                                   GetDlgItem(hWnd, IDE_ORDER_COMBOBOX));
  196.                     lIndex = ComboBox_GetItemData(
  197.                                    GetDlgItem(hWnd, IDE_ORDER_COMBOBOX),
  198.                                    lSel);
  199.  
  200.                     // Check if it is the original index or a new index.
  201.                     if(iStartIndex != (UINT16)lIndex)
  202.                     {
  203.                         if(RangeSet)
  204.                         {
  205.                             if(WinMsg("You will lose the current Range "
  206.                                       "settings do you want to change "
  207.                                       "indexes anyway?", MB_ICONHAND,
  208.                                       MB_YESNO)== IDYES)
  209.                             {
  210.                                 SetIndex(phCur, pABIdxDesc[(UINT16)lIndex]
  211.                                          .szTagName);
  212.  
  213.                                 // Disable the Reset Range menu option.
  214.                                 EnableMenuItem(GetMenu(hMainWnd),
  215.                                                ID_CLEAR_RANGE, MF_GRAYED);
  216.  
  217.                                 // Reset thge global RangeSet variable to
  218.                                 // FALSE.
  219.                                 RangeSet = FALSE;
  220.                                 bRet = TRUE;
  221.                             }
  222.                             else
  223.                             {
  224.                                 bRet = FALSE;
  225.                             }
  226.                         }
  227.                         else
  228.                         {
  229.                             SetIndex(phCur, pABIdxDesc[(UINT16)lIndex]
  230.                                      .szTagName);
  231.                                     
  232.                             bRet = TRUE;
  233.                         }
  234.                     }
  235.                     else
  236.                     {
  237.                         bRet = FALSE;
  238.                     }
  239.                     EndDialog(hWnd, bRet);
  240.                     break;
  241.  
  242.                 case IDCANCEL:
  243.                     EndDialog(hWnd, bRet);
  244.                     bRet = FALSE;
  245.                     break;
  246.             }
  247.             break;
  248.     }
  249.     return(bRet);
  250. }
  251.  
  252. //======================================================================
  253. //  Name:   RangeDlg()
  254. //
  255. //  Input:  hWnd, msg, wParam, lParam.  The lParam here also contains
  256. //          the pointer to the cursor during the WM_INITDIALOG.
  257. //
  258. //  Return: TRUE -  The Range was set.
  259. //          FALSE - Range failed or user canceled the dilaog box.
  260. //
  261. //  Desc:   This routine will process all I/O for the dialog that will
  262. //          change the Range of the present cursor AND Index.
  263. //======================================================================
  264. BOOL CALLBACK
  265. RangeDlg (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  266. {
  267.  
  268.     static  phDBICur    phCur;
  269.     static  hDBIDb      hDb;
  270.     static  CHAR        szStartIndex[DBIMAXNAMELEN];
  271.     static  UINT16      iStartIndex;
  272.     static  UINT16      iNumIdxs;
  273.     static  RecordType *pHighRec = NULL;
  274.     static  RecordType *pLowRec = NULL;
  275.     static  pABIDXDESC  pABIdxDesc = NULL;
  276.  
  277.     BOOL    bRet = FALSE;
  278.     BOOL    bLowEmpty=FALSE;
  279.     BOOL    bHighEmpty=FALSE;
  280.     CHAR    szString[220];
  281.     BOOL    bLowInclude;
  282.     BOOL    bHighInclude;
  283.     UINT32  lRet;
  284.     UINT32  lIndex;
  285.     CHAR    szTemp[ADDRESSLEN];
  286.     UINT    iFldIndx;
  287.     UINT32  lSel;
  288.  
  289.     hErrorWnd = hWnd;
  290.     switch (msg)
  291.     {
  292.         case WM_INITDIALOG:
  293.  
  294.             // Get the cursor and database from the lParam of the dialog
  295.             // box.  It was sent in when creating the dialog box.
  296.             phCur = ((pAbHandles)(lParam))->phCur;
  297.             hDb = ((pAbHandles)(lParam))->hDb;
  298.             PostMessage(hWnd, WM_SETUP, 0, 0L);
  299.             return TRUE;
  300.  
  301.         case WM_SETUP:
  302.  
  303.             // Get the presently active index,and fill the index structure
  304.             // with all the indexes that are open on the table.
  305.             if(FillIndexStr(*phCur, hDb, &pABIdxDesc, szStartIndex,
  306.                             &iNumIdxs)!=DBIERR_NONE)
  307.             {
  308.                 SendMessage(hWnd, WM_DESTROY, 0, 0L);
  309.             }
  310.  
  311.             // Fill the list box with all the index names, and set
  312.             // the name of the current index in the edit control of the
  313.             // ComboBox.
  314.             iStartIndex = FillDropList(hWnd, IDE_RANGE_COMBO, iNumIdxs,
  315.                                        pABIdxDesc, szStartIndex);
  316.  
  317.             if((pHighRec = (RecordType *) malloc(1 * sizeof(RecordType)))
  318.                            == NULL)
  319.             {
  320.                 WinMsg("You have run out of memory!", MB_ICONHAND, MB_OK);
  321.                 SendMessage(hWnd, WM_DESTROY, 0, 0L);
  322.             }
  323.             if((pLowRec = (RecordType *) malloc(1 * sizeof(RecordType)))
  324.                            == NULL)
  325.             {
  326.                 WinMsg("You have run out of memory!", MB_ICONHAND, MB_OK);
  327.                 SendMessage(hWnd, WM_DESTROY, 0, 0L);
  328.             }
  329.  
  330.             memset(pLowRec, 0, sizeof(RecordType));
  331.             memset(pHighRec, 0, sizeof(RecordType));
  332.  
  333.             // Finally set the length of the input field to the appropriate
  334.             // size based upon the present index.
  335.             Edit_LimitText(GetDlgItem(hWnd, IDE_LOWRANGE),
  336.                            pABIdxDesc[iStartIndex].aiKeyLen[0]);
  337.             Edit_LimitText(GetDlgItem(hWnd, IDE_HIGHRANGE),
  338.                            pABIdxDesc[iStartIndex].aiKeyLen[0]);
  339.  
  340.             // Get the Range information from the RC file and display it
  341.             // into the static text field on the bottom of the dialog box.
  342.             LoadString(hInst, IDS_RANGE, szString, 220);
  343.             SetDlgItemText(hWnd, IDS_RANGE_TEXT, (pCHAR)szString);
  344.             bRet = TRUE;
  345.             break;
  346.  
  347.         case WM_DESTROY:
  348.             if(pLowRec)
  349.             {
  350.                 free(pLowRec);
  351.             }
  352.             if(pHighRec)
  353.             {
  354.                 free(pHighRec);
  355.             }
  356.             if(pABIdxDesc)
  357.             {
  358.                 free(pABIdxDesc);
  359.             }
  360.             break;
  361.  
  362.         case WM_COMMAND:
  363.             switch (GET_WM_COMMAND_ID(wParam,lParam))
  364.             {
  365.                 case IDE_RANGE_COMBO:
  366.                     switch(GET_WM_COMMAND_CMD(wParam,lParam))
  367.                     {
  368.                         case CBN_SELCHANGE:
  369.                             // Add the item's position in the index array as
  370.                             // an item data.
  371.                             lSel = ComboBox_GetCurSel(
  372.                                           GetDlgItem(hWnd, IDE_RANGE_COMBO));
  373.                             lIndex = ComboBox_GetItemData(
  374.                                           GetDlgItem(hWnd, IDE_RANGE_COMBO),
  375.                                           lSel);
  376.  
  377.                             GetField(pLowRec, szTemp, (UINT16)lIndex);
  378.  
  379.                             SetWindowText(GetDlgItem(hWnd, IDE_LOWRANGE),
  380.                                           szTemp);
  381.  
  382.                             GetField(pHighRec, szTemp, (UINT16)lIndex);
  383.  
  384.                             SetWindowText(GetDlgItem(hWnd, IDE_HIGHRANGE),
  385.                                           szTemp);
  386.  
  387.                             // Set the field length for the present index.
  388.                             Edit_LimitText(GetDlgItem(hWnd, IDE_LOWRANGE),
  389.                                     pABIdxDesc[(UINT16)lIndex].aiKeyLen[0]);
  390.                             Edit_LimitText(GetDlgItem(hWnd, IDE_HIGHRANGE),
  391.                                     pABIdxDesc[(UINT16)lIndex].aiKeyLen[0]);
  392.  
  393.                             bRet = TRUE;
  394.                             break;
  395.                     }
  396.                     break;
  397.                 case IDE_LOWRANGE:
  398.                 case IDE_HIGHRANGE:
  399.                     switch(GET_WM_COMMAND_CMD(wParam,lParam))
  400.                     {
  401.                         case EN_KILLFOCUS:
  402.                             lSel = ComboBox_GetCurSel(
  403.                                           GetDlgItem(hWnd, IDE_RANGE_COMBO));
  404.                             lIndex = ComboBox_GetItemData(
  405.                                           GetDlgItem(hWnd, IDE_RANGE_COMBO),
  406.                                           lSel);
  407.  
  408.                             iFldIndx = (pABIdxDesc[(UINT16)lIndex].
  409.                                                   aiKeyFld[0])-1;
  410.  
  411.                             // Get the inputed range text and save that
  412.                             // in the record structure to display again.
  413.                             GetDlgItemText(hWnd, IDE_LOWRANGE, szTemp,
  414.                                            (WPARAM)pABIdxDesc
  415.                                             [(UINT16)lIndex].aiKeyLen[0]);
  416.  
  417.                             PutField(pLowRec, szTemp, iFldIndx);
  418.                             GetDlgItemText(hWnd, IDE_HIGHRANGE, szTemp,
  419.                                             (WPARAM)pABIdxDesc
  420.                                             [(UINT16)lIndex].aiKeyLen[0]);
  421.  
  422.                             PutField(pHighRec, szTemp, iFldIndx);
  423.                             bRet = TRUE;
  424.                             break;
  425.                     }
  426.                     break;
  427.                 case IDOK:
  428.                     // Get the present state of the check boxes.
  429.                     lRet = Button_GetCheck(GetDlgItem(hWnd, IDE_BM_LOW));
  430.                     if(lRet == 1)
  431.                     {
  432.                         bLowInclude = TRUE;
  433.                     }
  434.                     else
  435.                     {
  436.                         bLowInclude = FALSE;
  437.                     }
  438.                     lRet = Button_GetCheck(GetDlgItem(hWnd, IDE_BM_HIGH));
  439.                     if(lRet == 1)
  440.                     {
  441.                         bHighInclude = TRUE;
  442.                     }
  443.                     else
  444.                     {
  445.                         bHighInclude = FALSE;
  446.                     }
  447.  
  448.                     memset(pLowRec, 0, sizeof(RecordType));
  449.                     memset(pHighRec, 0, sizeof(RecordType));
  450.  
  451.                     lSel = ComboBox_GetCurSel(
  452.                                 GetDlgItem(hWnd, IDE_RANGE_COMBO));
  453.                     lIndex = ComboBox_GetItemData(
  454.                                 GetDlgItem(hWnd, IDE_RANGE_COMBO), lSel);
  455.  
  456.                     GetDlgItemText(hWnd, IDE_LOWRANGE, szTemp, ADDRESSLEN);
  457.  
  458.                     // If the range was left empty then set the bool to
  459.                     // TRUE.
  460.                     if(strlen(szTemp)==0)
  461.                     {
  462.                         bLowEmpty = TRUE;
  463.                     }
  464.  
  465.                     // Put the text into the correct field of the
  466.                     // record structure, that is to be used by the
  467.                     // SetRange function.
  468.                     iFldIndx = (pABIdxDesc[(UINT16)lIndex].aiKeyFld[0])-1;
  469.                     PutField(pLowRec, szTemp, iFldIndx);
  470.                     GetDlgItemText(hWnd, IDE_HIGHRANGE, szTemp, ADDRESSLEN);
  471.  
  472.                     // If the range was left empty then set the bool to
  473.                     // TRUE.
  474.                     if(strlen(szTemp)==0)
  475.                     {
  476.                         bHighEmpty = TRUE;
  477.                     }
  478.  
  479.                     PutField(pHighRec, szTemp, iFldIndx);
  480.                     if(iStartIndex != (UINT16)lIndex)
  481.                     {
  482.                         SetIndex(phCur,
  483.                                 pABIdxDesc[(UINT16)lIndex].szTagName);
  484.                     }
  485.  
  486.                     // Set the range.
  487.                     if(SetRange(pHighRec, pLowRec, bHighInclude,
  488.                                 bLowInclude, *phCur, bHighEmpty,
  489.                                 bLowEmpty)==DBIERR_NONE)
  490.                     {
  491.                         if(AtEOF(*phCur))
  492.                         {
  493.                             MessageBox(hWnd, "No Records exist within the"
  494.                                        " specified range. Resetting to"
  495.                                        " original range.", "Range Error",
  496.                                        MB_ICONHAND | MB_OK);
  497.  
  498.                             // Reset the range.
  499.                             ResetRange(*phCur);
  500.  
  501.                             // Reset the index.
  502.                             SetIndex(phCur,
  503.                                     pABIdxDesc[iStartIndex].szTagName);
  504.  
  505.                             // Set the return value to RANGEERROR, which is
  506.                             // defined in the header file.
  507.                             bRet = RANGEERROR;
  508.                         }
  509.                         else
  510.                         {
  511.                             bRet = TRUE;
  512.  
  513.                             // move one record forward to move past the
  514.                             // crack that SetRange puts you at.
  515.                             GetNextRec(*phCur);
  516.                         }
  517.                     }
  518.                     else
  519.                     {
  520.                         bRet = FALSE;
  521.                     }
  522.  
  523.                     if(bRet!=RANGEERROR)
  524.                     {
  525.                         EndDialog(hWnd, bRet);
  526.                     }
  527.                     break;
  528.  
  529.                 case IDCANCEL:
  530.                     EndDialog(hWnd, FALSE);
  531.                     bRet = TRUE;
  532.                     break;
  533.             }
  534.             break;
  535.     }
  536.     return bRet;
  537. }
  538.  
  539. //======================================================================
  540. //  Name:   SearchDlg()
  541. //
  542. //  Input:  hWnd, msg, wParam, lParam.  The lParam here also contains
  543. //          the pointer to the cursor during the WM_INITDIALOG.
  544. //
  545. //  Return: TRUE -  The Search was successful.
  546. //          FALSE - The search failed or user canceled the dilaog box.
  547. //
  548. //  Desc:   This routine will process all I/O for the dialog that will
  549. //          search for a record in the table.
  550. //======================================================================
  551. BOOL CALLBACK
  552. SearchDlg (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  553. {
  554.     static  pABIDXDESC  pABIdxDesc = NULL;
  555.     static  BOOL        bErrorRet = FALSE;
  556.     static  phDBICur    phCur;
  557.     static  hDBIDb      hDb;
  558.     static  CHAR        szStartIndex[DBIMAXNAMELEN];
  559.     static  UINT16      iStartIndex;
  560.     static  UINT16      iNumIdxs;
  561.     static  RecordType  *pIndexRec = NULL;    
  562.  
  563.     BOOL                bRet = FALSE;
  564.     DBISearchCond       eSearch;
  565.     UINT32              lIndex;
  566.     UINT32              lSel;
  567.     DBIResult           rslt;
  568.     CHAR                szKey[ADDRESSLEN];    
  569.     CHAR                szString[220];
  570.  
  571.     hErrorWnd = hWnd;
  572.     switch (msg)
  573.     {
  574.         case WM_INITDIALOG:
  575.             // Get the cursor and database from the lParam of the dialog
  576.             // box.  It was sent in when creating the dialog box.
  577.             phCur = ((pAbHandles)(lParam))->phCur;
  578.             hDb = ((pAbHandles)(lParam))->hDb;
  579.  
  580.             PostMessage(hWnd, WM_SETUP, 0, 0L);
  581.             return TRUE;
  582.  
  583.         case WM_SETUP:
  584.  
  585.             if((pIndexRec = (RecordType *) malloc(1 * sizeof(RecordType)))
  586.                            == NULL)
  587.             {
  588.                 WinMsg("You have run out of memory!", MB_ICONHAND, MB_OK);
  589.                 SendMessage(hWnd, WM_DESTROY, 0, 0L);
  590.             }
  591.  
  592.             // Get the presently active index, and fill the index structure
  593.             // with all the indexes that are open on the table.
  594.             if(FillIndexStr(*phCur, hDb, &pABIdxDesc, szStartIndex,
  595.                             &iNumIdxs)!=DBIERR_NONE)
  596.             {
  597.                 SendMessage(hWnd, WM_DESTROY, 0, 0L);
  598.             }
  599.  
  600.             // Fill the list box with all the index names, and set
  601.             // the name of the current index in the edit control of the
  602.             // ComboBox.
  603.             iStartIndex = FillDropList(hWnd, IDE_SEARCH_COMBO, iNumIdxs,
  604.                                        pABIdxDesc, szStartIndex);
  605.  
  606.             // Set the field length to the appropriate size.
  607.             Edit_LimitText(GetDlgItem(hWnd, IDE_SEARCH),
  608.                            pABIdxDesc[iStartIndex].aiKeyLen[0]);
  609.  
  610.  
  611.             // Set the Checkbox to Greater than or equal.
  612.             Button_SetCheck(GetDlgItem(hWnd, IDC_GREATEREQ), TRUE);
  613.  
  614.             LoadString(hInst, IDS_SEARCH, szString, 220);
  615.             SetDlgItemText(hWnd, IDS_SEARCH_TEXT, (pCHAR)szString);
  616.             break;
  617.  
  618.         case WM_DESTROY:
  619.             if(pABIdxDesc)
  620.             {
  621.                 free(pABIdxDesc);
  622.             }
  623.             if(pIndexRec)
  624.             {
  625.                 free(pIndexRec);
  626.             }
  627.             break;
  628.  
  629.         case WM_COMMAND:
  630.             switch (GET_WM_COMMAND_ID(wParam,lParam))
  631.             {
  632.                 case IDE_SEARCH_COMBO:
  633.                     switch(GET_WM_COMMAND_CMD(wParam,lParam))
  634.                     {
  635.                         case CBN_SELCHANGE:
  636.                             // Get the new index that was chosen and set
  637.                             // the edit control's limit to the index's
  638.                             // limit.
  639.                             lSel = ComboBox_GetCurSel(
  640.                                           GetDlgItem(hWnd, IDE_SEARCH_COMBO));
  641.                             lIndex = ComboBox_GetItemData(
  642.                                           GetDlgItem(hWnd, IDE_SEARCH_COMBO),
  643.                                           lSel);
  644.  
  645.                             // Set the field length on this index.
  646.                             Edit_LimitText(GetDlgItem(hWnd, IDE_SEARCH),
  647.                                  pABIdxDesc[(UINT16)lIndex].aiKeyLen[0]);
  648.  
  649.                             // Clear the edit control.
  650.                             SendDlgItemMessage(hWnd, IDE_SEARCH,
  651.                                                WM_SETTEXT, (WPARAM)0, NULL);
  652.                             break;
  653.                     }
  654.                     break;
  655.                 case IDOK:
  656.                     // Get the new index to search on.
  657.                     lSel = ComboBox_GetCurSel(
  658.                                      GetDlgItem(hWnd, IDE_SEARCH_COMBO));
  659.                     lIndex = ComboBox_GetItemData(
  660.                                      GetDlgItem(hWnd, IDE_SEARCH_COMBO),
  661.                                      lSel);
  662.  
  663.                     // If it is the same as the original index do NOT
  664.                     // reindex.
  665.                     if(iStartIndex != (UINT16)lIndex)
  666.                     {
  667.                         SetIndex(phCur,
  668.                                 pABIdxDesc[(UINT16)lIndex].szTagName);
  669.                     }
  670.  
  671.                     GetDlgItemText(hWnd, IDE_SEARCH, szKey, ADDRESSLEN);
  672.  
  673.                     // Get the Condition checkbox.
  674.                     eSearch = GetCond(hWnd);
  675.  
  676.                     memset(pIndexRec, 0, sizeof(RecordType));
  677.  
  678.                     PutField(pIndexRec, szKey,
  679.                              (pABIdxDesc[((UINT16)lIndex)].aiKeyFld[0])-1);
  680.  
  681.                     // Search based upon the condition and the search
  682.                     // string.
  683.                     rslt = Search(*phCur, eSearch, FALSE, 0, 0, pIndexRec);
  684.  
  685.                     if(rslt == DBIERR_NONE)
  686.                     {
  687.                         bRet = TRUE;
  688.                         bErrorRet = FALSE;
  689.                     }
  690.                     else
  691.                     {
  692.                         // Check if no match was found.
  693.                         if (rslt == DBIERR_RECNOTFOUND)
  694.                         {
  695.                             MessageBox(hWnd, "Could not find a match",
  696.                                        "Search Error",
  697.                                        MB_ICONINFORMATION | MB_OK);
  698.  
  699.                             // Go to the first record as the failed search
  700.                             // has left us at a the end of the table.
  701.                             GoTop(*phCur, TRUE);
  702.                             bErrorRet = TRUE;
  703.                         }
  704.                     }
  705.                     if(!bErrorRet)
  706.                     {
  707.                         EndDialog(hWnd, bRet);
  708.                     }
  709.                     break;
  710.  
  711.                 case IDCANCEL:
  712.                     EndDialog(hWnd, FALSE);
  713.                     break;
  714.             }
  715.             break;
  716.     }
  717.     return bRet;
  718. }
  719.