// BDE - (C) Copyright 1994 by Borland International #include "address.h" //====================================================================== // Name: EditSubClassProc() // // Input: hWnd, msg, wParam, lParam // // Return: It returns the result of the procedure. It can return the // result of the original edit control if the WM_CHAR is not a // tab character. // // Desc: This routine will process all I/O for the Comments edit // control. It does this by first checking if the tab key was // hit inside of the comment edit control. If it was it moves // control to the next control item and then does NOT let the // original edit control process the message. However, if the // WM_CHAR is not a tab then it lets the original edit control // process the message. //====================================================================== long FAR _pascal _export EditSubClassProc(HWND hWnd, WORD msg, WORD wParam, LONG lParam) { LRESULT lResult = 0; BOOL bCallOrigWndProc = TRUE; switch (msg) { case WM_CHAR: if(wParam == '\t') { if(GetKeyState(VK_SHIFT)<0) { SetFocus(GetDlgItem(hMainWnd, IDE_LAST_DATE)); } else { if(!NewRecMode) { SetFocus(GetDlgItem(hMainWnd, ID_ORDER)); SendMessage(GetDlgItem(hMainWnd, ID_ORDER), BM_SETSTYLE, (UINT16)BS_DEFPUSHBUTTON, 1L); } else { SetFocus(GetDlgItem(hMainWnd, IDOK)); SendMessage(GetDlgItem(hMainWnd, IDOK), BM_SETSTYLE, (UINT16)BS_DEFPUSHBUTTON, 1L); } } bCallOrigWndProc = FALSE; } break; } if(bCallOrigWndProc) { lResult = CallWindowProc((WNDPROC)_wpOrigWndProc, hWnd, msg, wParam, lParam); } return(lResult); } //====================================================================== // Name: AboutDlg() // // Input: hWnd, msg, wParam, lParam // // Return: TRUE - Dialog Created. // FALSE - Dialog Failed to create. // // Desc: This routine will process all I/O for the ABOUT dialog. //====================================================================== BOOL FAR _pascal _export AboutDlg (HWND hWnd, WORD msg, WORD wParam, LONG lParam) { BOOL bRet = FALSE; // Done to clear the unused warning. lParam = lParam; switch (msg) { case WM_COMMAND: switch (wParam) { case IDOK: case IDCANCEL: bRet = TRUE; EndDialog(hWnd, bRet); break; } break; } return(bRet); } //====================================================================== // Name: OrderDlg() // // Input: hWnd, msg, wParam, lParam. The lParam here also contains // the pointer to the cursor during the WM_INITDIALOG. // // Return: TRUE - The Index was set. // FALSE - Index failed or user canceled the dilaog box. // // Desc: This routine will process all I/O for the dialog that will // change the order of the table (i.e. place an index). //====================================================================== BOOL FAR _pascal _export OrderDlg (HWND hWnd, WORD msg, WORD wParam, LONG lParam) { static phDBICur phCur; static hDBIDb hDb; static CHAR szStartIndex[DBIMAXNAMELEN]; static UINT16 iStartIndex = 0; static pABIDXDESC pABIdxDesc = NULL; static UINT16 iNumIdxs = 0; UINT32 lIndex = 0; UINT32 lSel = 0; BOOL bRet = FALSE; hErrorWnd = hWnd; switch (msg) { case WM_INITDIALOG: // Get the cursor and database from the lParam of the dialog // box. It was sent in when creating the dialog box. phCur = ((pAbHandles)(lParam))->phCur; hDb = ((pAbHandles)(lParam))->hDb; PostMessage(hWnd, WM_SETUP, 0, 0L); return TRUE; case WM_SETUP: // Get the presently active index and fill the index structure // with all the indexes that are open on the table. if(FillIndexStr(*phCur, hDb, &pABIdxDesc, szStartIndex, &iNumIdxs)!=DBIERR_NONE) { SendMessage(hWnd, WM_DESTROY, 0, 0L); } // Fill the list box with all the index names, and set // the name of the current index in the edit control of the // ComboBox. iStartIndex = FillDropList(hWnd, IDE_ORDER_COMBOBOX, iNumIdxs, pABIdxDesc, szStartIndex); break; case WM_DESTROY: if(pABIdxDesc) { free(pABIdxDesc); } break; case WM_COMMAND: switch (wParam) { case IDE_ORDER_COMBOBOX: // Add the item's position in the index array as an item // data. switch(HIWORD(lParam)) { case CBN_SELCHANGE: lSel=SendDlgItemMessage(hWnd, IDE_ORDER_COMBOBOX, CB_GETCURSEL, 0, 0L); lIndex=SendDlgItemMessage(hWnd, IDE_ORDER_COMBOBOX, CB_GETITEMDATA, (WPARAM)lSel, 0L); // Put the Index Key Expression in the static // text box. SetWindowText(GetDlgItem(hWnd, IDE_ORDER_INFO), pABIdxDesc[(UINT16)lIndex].szKeyExp); break; } break; case IDOK: // Get the selected item and its item data. lSel=SendDlgItemMessage(hWnd, IDE_ORDER_COMBOBOX, CB_GETCURSEL, 0, 0L); lIndex=SendDlgItemMessage(hWnd, IDE_ORDER_COMBOBOX, CB_GETITEMDATA, (WPARAM)lSel, 0L); // Check if it is the original index or a new index. if(iStartIndex != (UINT16)lIndex) { if(RangeSet) { if(WinMsg("You will lose the current Range " "settings do you want to change " "indexes anyway?", MB_ICONHAND, MB_YESNO)== IDYES) { SetIndex(phCur, pABIdxDesc[(UINT16)lIndex] .szTagName); // Disable the Reset Range menu option. EnableMenuItem(GetMenu(hMainWnd), ID_CLEAR_RANGE, MF_GRAYED); // Reset thge global RangeSet variable to // FALSE. RangeSet = FALSE; bRet = TRUE; } else { bRet = FALSE; } } else { SetIndex(phCur, pABIdxDesc[(UINT16)lIndex] .szTagName); bRet = TRUE; } } else { bRet = FALSE; } EndDialog(hWnd, bRet); break; case IDCANCEL: EndDialog(hWnd, bRet); bRet = FALSE; break; } break; } return(bRet); } //====================================================================== // Name: RangeDlg() // // Input: hWnd, msg, wParam, lParam. The lParam here also contains // the pointer to the cursor during the WM_INITDIALOG. // // Return: TRUE - The Range was set. // FALSE - Range failed or user canceled the dilaog box. // // Desc: This routine will process all I/O for the dialog that will // change the Range of the present cursor AND Index. //====================================================================== BOOL FAR _pascal _export RangeDlg (HWND hWnd, WORD msg, WORD wParam, LONG lParam) { static phDBICur phCur; static hDBIDb hDb; static CHAR szStartIndex[DBIMAXNAMELEN]; static UINT16 iStartIndex; static UINT16 iNumIdxs; static RecordType *pHighRec = NULL; static RecordType *pLowRec = NULL; static pABIDXDESC pABIdxDesc = NULL; BOOL bRet = FALSE; BOOL bLowEmpty=FALSE; BOOL bHighEmpty=FALSE; CHAR szString[220]; BOOL bLowInclude; BOOL bHighInclude; UINT32 lRet; UINT32 lIndex; CHAR szTemp[ADDRESSLEN]; UINT16 iFldIndx=0; UINT32 lSel; hErrorWnd = hWnd; switch (msg) { case WM_INITDIALOG: // Get the cursor and database from the lParam of the dialog // box. It was sent in when creating the dialog box. phCur = ((pAbHandles)(lParam))->phCur; hDb = ((pAbHandles)(lParam))->hDb; PostMessage(hWnd, WM_SETUP, 0, 0L); return TRUE; case WM_SETUP: // Get the presently active index,and fill the index structure // with all the indexes that are open on the table. if(FillIndexStr(*phCur, hDb, &pABIdxDesc, szStartIndex, &iNumIdxs)!=DBIERR_NONE) { SendMessage(hWnd, WM_DESTROY, 0, 0L); } // Fill the list box with all the index names, and set // the name of the current index in the edit control of the // ComboBox. iStartIndex = FillDropList(hWnd, IDE_RANGE_COMBO, iNumIdxs, pABIdxDesc, szStartIndex); if((pHighRec = (RecordType *) malloc(1 * sizeof(RecordType))) == NULL) { WinMsg("You have run out of memory!", MB_ICONHAND, MB_OK); SendMessage(hWnd, WM_DESTROY, 0, 0L); } if((pLowRec = (RecordType *) malloc(1 * sizeof(RecordType))) == NULL) { WinMsg("You have run out of memory!", MB_ICONHAND, MB_OK); SendMessage(hWnd, WM_DESTROY, 0, 0L); } memset(pLowRec, 0, sizeof(RecordType)); memset(pHighRec, 0, sizeof(RecordType)); // Finally set the length of the input field to the appropriate // size based upon the present index. SendDlgItemMessage(hWnd, IDE_LOWRANGE, EM_LIMITTEXT, (WPARAM)pABIdxDesc[iStartIndex].aiKeyLen[0], 0L); SendDlgItemMessage(hWnd, IDE_HIGHRANGE, EM_LIMITTEXT, (WPARAM)pABIdxDesc[iStartIndex].aiKeyLen[0], 0L); // Get the Range information from the RC file and display it // into the static text field on the bottom of the dialog box. LoadString(hInst, IDS_RANGE, szString, 220); SetDlgItemText(hWnd, IDS_RANGE_TEXT, (pCHAR)szString); bRet = TRUE; break; case WM_DESTROY: if(pLowRec) { free(pLowRec); } if(pHighRec) { free(pHighRec); } if(pABIdxDesc) { free(pABIdxDesc); } break; case WM_COMMAND: switch (wParam) { case IDE_RANGE_COMBO: switch(HIWORD(lParam)) { case CBN_SELCHANGE: // Add the item's position in the index array as // an item data. lSel=SendDlgItemMessage(hWnd, IDE_RANGE_COMBO, CB_GETCURSEL, 0, 0L); lIndex=SendDlgItemMessage(hWnd, IDE_RANGE_COMBO, CB_GETITEMDATA, (WPARAM)lSel, 0L); // Get the text that was entered for that index // the last time it was chosen. iFldIndx = (pABIdxDesc[(UINT16)lIndex]. aiKeyFld[0])-1; GetField(pLowRec, szTemp, (UINT16)lIndex); SetWindowText(GetDlgItem(hWnd, IDE_LOWRANGE), szTemp); GetField(pHighRec, szTemp, (UINT16)lIndex); SetWindowText(GetDlgItem(hWnd, IDE_HIGHRANGE), szTemp); // Set the field length for the present index. SendDlgItemMessage(hWnd, IDE_LOWRANGE, EM_LIMITTEXT, (WPARAM)pABIdxDesc [(UINT16)lIndex].aiKeyLen[0], 0L); SendDlgItemMessage(hWnd, IDE_HIGHRANGE, EM_LIMITTEXT, (WPARAM)pABIdxDesc [(UINT16)lIndex].aiKeyLen[0], 0L); bRet = TRUE; break; } break; case IDE_LOWRANGE: case IDE_HIGHRANGE: switch(HIWORD(lParam)) { case EN_KILLFOCUS: lSel=SendDlgItemMessage(hWnd, IDE_RANGE_COMBO, CB_GETCURSEL, 0, 0L); lIndex=SendDlgItemMessage(hWnd, IDE_RANGE_COMBO, CB_GETITEMDATA, (WPARAM)lSel, 0L); iFldIndx = (pABIdxDesc[(UINT16)lIndex]. aiKeyFld[0])-1; // Get the inputed range text and save that // in the record structure to display again. GetDlgItemText(hWnd, IDE_LOWRANGE, szTemp, (WPARAM)pABIdxDesc [(UINT16)lIndex].aiKeyLen[0]); PutField(pLowRec, szTemp, iFldIndx); GetDlgItemText(hWnd, IDE_HIGHRANGE, szTemp, (WPARAM)pABIdxDesc [(UINT16)lIndex].aiKeyLen[0]); PutField(pHighRec, szTemp, iFldIndx); bRet = TRUE; break; } break; case IDOK: // Get the present state of the check boxes. lRet = SendDlgItemMessage(hWnd, IDE_BM_LOW, BM_GETCHECK, 0, 0L); if(lRet == 1) { bLowInclude = TRUE; } else { bLowInclude = FALSE; } lRet = SendDlgItemMessage(hWnd, IDE_BM_HIGH, BM_GETCHECK, 0, 0L); if(lRet == 1) { bHighInclude = TRUE; } else { bHighInclude = FALSE; } memset(pLowRec, 0, sizeof(RecordType)); memset(pHighRec, 0, sizeof(RecordType)); lSel=SendDlgItemMessage(hWnd, IDE_RANGE_COMBO, CB_GETCURSEL, 0, 0L); lIndex=SendDlgItemMessage(hWnd, IDE_RANGE_COMBO, CB_GETITEMDATA, (WPARAM)lSel, 0L); GetDlgItemText(hWnd, IDE_LOWRANGE, szTemp, ADDRESSLEN); // If the range was left empty then set the bool to // TRUE. if(strlen(szTemp)==0) { bLowEmpty = TRUE; } // Put the text into the correct field of the // record structure, that is to be used by the // SetRange function. iFldIndx = (pABIdxDesc[(UINT16)lIndex].aiKeyFld[0])-1; PutField(pLowRec, szTemp, iFldIndx); GetDlgItemText(hWnd, IDE_HIGHRANGE, szTemp, ADDRESSLEN); // If the range was left empty then set the bool to // TRUE. if(strlen(szTemp)==0) { bHighEmpty = TRUE; } PutField(pHighRec, szTemp, iFldIndx); if(iStartIndex != (UINT16)lIndex) { SetIndex(phCur, pABIdxDesc[(UINT16)lIndex].szTagName); } // Set the range. if(SetRange(pHighRec, pLowRec, bHighInclude, bLowInclude, *phCur, bHighEmpty, bLowEmpty)==DBIERR_NONE) { if(AtEOF(*phCur)) { MessageBox(hWnd, "No Records exist within the" " specified range. Resetting to" " original range.", "Range Error", MB_ICONHAND | MB_OK); // Reset the range. ResetRange(*phCur); // Reset the index. SetIndex(phCur, pABIdxDesc[iStartIndex].szTagName); // Set the return value to RANGEERROR, which is // defined in the header file. bRet = RANGEERROR; } else { bRet = TRUE; // move one record forward to move past the // crack that SetRange puts you at. GetNextRec(*phCur); } } else { bRet = FALSE; } if(bRet!=RANGEERROR) { EndDialog(hWnd, bRet); } break; case IDCANCEL: EndDialog(hWnd, FALSE); bRet = TRUE; break; } break; } return bRet; } //====================================================================== // Name: SearchDlg() // // Input: hWnd, msg, wParam, lParam. The lParam here also contains // the pointer to the cursor during the WM_INITDIALOG. // // Return: TRUE - The Search was successful. // FALSE - The search failed or user canceled the dilaog box. // // Desc: This routine will process all I/O for the dialog that will // search for a record in the table. //====================================================================== BOOL FAR _pascal _export SearchDlg (HWND hWnd, WORD msg, WORD wParam, LONG lParam) { static pABIDXDESC pABIdxDesc = NULL; static BOOL bErrorRet = FALSE; static phDBICur phCur; static hDBIDb hDb; static CHAR szStartIndex[DBIMAXNAMELEN]; static UINT16 iStartIndex; static UINT16 iNumIdxs; static RecordType *pIndexRec = NULL; BOOL bRet = FALSE; DBISearchCond eSearch; UINT32 lIndex; UINT32 lSel; DBIResult rslt; CHAR szKey[ADDRESSLEN]; CHAR szString[220]; hErrorWnd = hWnd; switch (msg) { case WM_INITDIALOG: // Get the cursor and database from the lParam of the dialog // box. It was sent in when creating the dialog box. phCur = ((pAbHandles)(lParam))->phCur; hDb = ((pAbHandles)(lParam))->hDb; PostMessage(hWnd, WM_SETUP, 0, 0L); return TRUE; case WM_SETUP: if((pIndexRec = (RecordType *) malloc(1 * sizeof(RecordType))) == NULL) { WinMsg("You have run out of memory!", MB_ICONHAND, MB_OK); SendMessage(hWnd, WM_DESTROY, 0, 0L); } // Get the presently active index, and fill the index structure // with all the indexes that are open on the table. if(FillIndexStr(*phCur, hDb, &pABIdxDesc, szStartIndex, &iNumIdxs)!=DBIERR_NONE) { SendMessage(hWnd, WM_DESTROY, 0, 0L); } // Fill the list box with all the index names, and set // the name of the current index in the edit control of the // ComboBox. iStartIndex = FillDropList(hWnd, IDE_SEARCH_COMBO, iNumIdxs, pABIdxDesc, szStartIndex); // Set the field length to the appropriate size. SendDlgItemMessage(hWnd, IDE_SEARCH, EM_LIMITTEXT, (WPARAM)pABIdxDesc[iStartIndex].aiKeyLen[0], 0L); // Set the Checkbox to Greater than or equal. SendDlgItemMessage(hWnd, IDC_GREATEREQ, BM_SETCHECK, (WPARAM)TRUE, 0L); LoadString(hInst, IDS_SEARCH, szString, 220); SetDlgItemText(hWnd, IDS_SEARCH_TEXT, (pCHAR)szString); break; case WM_DESTROY: if(pABIdxDesc) { free(pABIdxDesc); } if(pIndexRec) { free(pIndexRec); } break; case WM_COMMAND: switch (wParam) { case IDE_SEARCH_COMBO: switch(HIWORD(lParam)) { case CBN_SELCHANGE: // Get the new index that was chosen and set // the edit control's limit to the index's // limit. lSel=SendDlgItemMessage(hWnd, IDE_SEARCH_COMBO, CB_GETCURSEL, 0, 0L); lIndex=SendDlgItemMessage(hWnd, IDE_SEARCH_COMBO, CB_GETITEMDATA, (WPARAM)lSel, 0L); // Set the field length on this index. SendDlgItemMessage(hWnd, IDE_SEARCH, EM_LIMITTEXT, (WPARAM)pABIdxDesc [(UINT16)lIndex].aiKeyLen[0], 0L); // Clear the edit control. SendDlgItemMessage(hWnd, IDE_SEARCH, WM_SETTEXT, (WPARAM)0, NULL); break; } break; case IDOK: // Get the new index to search on. lSel=SendDlgItemMessage(hWnd, IDE_SEARCH_COMBO, CB_GETCURSEL, 0, 0L); lIndex=SendDlgItemMessage(hWnd, IDE_SEARCH_COMBO, CB_GETITEMDATA, (WPARAM)lSel, 0L); // If it is the same as the original index do NOT // reindex. if(iStartIndex != (UINT16)lIndex) { SetIndex(phCur, pABIdxDesc[(UINT16)lIndex].szTagName); } GetDlgItemText(hWnd, IDE_SEARCH, szKey, ADDRESSLEN); // Get the Condition checkbox. eSearch = GetCond(hWnd); memset(pIndexRec, 0, sizeof(RecordType)); PutField(pIndexRec, szKey, (pABIdxDesc[((UINT16)lIndex)].aiKeyFld[0])-1); // Search based upon the condition and the search // string. rslt = Search(*phCur, eSearch, FALSE, 0, 0, pIndexRec); if(rslt == DBIERR_NONE) { bRet = TRUE; bErrorRet = FALSE; } else { // Check if no match was found. if (rslt == DBIERR_RECNOTFOUND) { MessageBox(hWnd, "Could not find a match", "Search Error", MB_ICONINFORMATION | MB_OK); // Go to the first record as the failed search // has left us at a the end of the table. GoTop(*phCur, TRUE); bErrorRet = TRUE; } } if(!bErrorRet) { EndDialog(hWnd, bRet); } break; case IDCANCEL: EndDialog(hWnd, FALSE); break; } break; } return bRet; }