home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Total C++ 2
/
TOTALCTWO.iso
/
borland
/
32addres.pak
/
ADR_DLGS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-06
|
27KB
|
719 lines
// BDE32 3.x - (C) Copyright 1996 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.
//======================================================================
LPARAM CALLBACK
EditSubClassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM 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.
//======================================================================
#ifdef __BORLANDC__
#pragma argsused
#endif
BOOL CALLBACK
AboutDlg (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
BOOL bRet = FALSE;
#ifndef WIN32
// Done to clear the unused warning.
lParam = lParam;
#endif
switch (msg)
{
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam,lParam))
{
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 CALLBACK
OrderDlg (HWND hWnd, UINT msg, WPARAM wParam, LPARAM 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;
UINT32 lSel;
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 (GET_WM_COMMAND_ID(wParam,lParam))
{
case IDE_ORDER_COMBOBOX:
// Add the item's position in the index array as an item
// data.
switch (GET_WM_COMMAND_CMD(wParam,lParam))
{
case CBN_SELCHANGE:
lSel = ComboBox_GetCurSel(
GetDlgItem(hWnd, IDE_ORDER_COMBOBOX));
lIndex = ComboBox_GetItemData(
GetDlgItem(hWnd, IDE_ORDER_COMBOBOX),
lSel);
// 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 = ComboBox_GetCurSel(
GetDlgItem(hWnd, IDE_ORDER_COMBOBOX));
lIndex = ComboBox_GetItemData(
GetDlgItem(hWnd, IDE_ORDER_COMBOBOX),
lSel);
// 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 CALLBACK
RangeDlg (HWND hWnd, UINT msg, WPARAM wParam, LPARAM 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];
UINT iFldIndx;
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.
Edit_LimitText(GetDlgItem(hWnd, IDE_LOWRANGE),
pABIdxDesc[iStartIndex].aiKeyLen[0]);
Edit_LimitText(GetDlgItem(hWnd, IDE_HIGHRANGE),
pABIdxDesc[iStartIndex].aiKeyLen[0]);
// 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 (GET_WM_COMMAND_ID(wParam,lParam))
{
case IDE_RANGE_COMBO:
switch(GET_WM_COMMAND_CMD(wParam,lParam))
{
case CBN_SELCHANGE:
// Add the item's position in the index array as
// an item data.
lSel = ComboBox_GetCurSel(
GetDlgItem(hWnd, IDE_RANGE_COMBO));
lIndex = ComboBox_GetItemData(
GetDlgItem(hWnd, IDE_RANGE_COMBO),
lSel);
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.
Edit_LimitText(GetDlgItem(hWnd, IDE_LOWRANGE),
pABIdxDesc[(UINT16)lIndex].aiKeyLen[0]);
Edit_LimitText(GetDlgItem(hWnd, IDE_HIGHRANGE),
pABIdxDesc[(UINT16)lIndex].aiKeyLen[0]);
bRet = TRUE;
break;
}
break;
case IDE_LOWRANGE:
case IDE_HIGHRANGE:
switch(GET_WM_COMMAND_CMD(wParam,lParam))
{
case EN_KILLFOCUS:
lSel = ComboBox_GetCurSel(
GetDlgItem(hWnd, IDE_RANGE_COMBO));
lIndex = ComboBox_GetItemData(
GetDlgItem(hWnd, IDE_RANGE_COMBO),
lSel);
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 = Button_GetCheck(GetDlgItem(hWnd, IDE_BM_LOW));
if(lRet == 1)
{
bLowInclude = TRUE;
}
else
{
bLowInclude = FALSE;
}
lRet = Button_GetCheck(GetDlgItem(hWnd, IDE_BM_HIGH));
if(lRet == 1)
{
bHighInclude = TRUE;
}
else
{
bHighInclude = FALSE;
}
memset(pLowRec, 0, sizeof(RecordType));
memset(pHighRec, 0, sizeof(RecordType));
lSel = ComboBox_GetCurSel(
GetDlgItem(hWnd, IDE_RANGE_COMBO));
lIndex = ComboBox_GetItemData(
GetDlgItem(hWnd, IDE_RANGE_COMBO), lSel);
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 CALLBACK
SearchDlg (HWND hWnd, UINT msg, WPARAM wParam, LPARAM 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.
Edit_LimitText(GetDlgItem(hWnd, IDE_SEARCH),
pABIdxDesc[iStartIndex].aiKeyLen[0]);
// Set the Checkbox to Greater than or equal.
Button_SetCheck(GetDlgItem(hWnd, IDC_GREATEREQ), TRUE);
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 (GET_WM_COMMAND_ID(wParam,lParam))
{
case IDE_SEARCH_COMBO:
switch(GET_WM_COMMAND_CMD(wParam,lParam))
{
case CBN_SELCHANGE:
// Get the new index that was chosen and set
// the edit control's limit to the index's
// limit.
lSel = ComboBox_GetCurSel(
GetDlgItem(hWnd, IDE_SEARCH_COMBO));
lIndex = ComboBox_GetItemData(
GetDlgItem(hWnd, IDE_SEARCH_COMBO),
lSel);
// Set the field length on this index.
Edit_LimitText(GetDlgItem(hWnd, IDE_SEARCH),
pABIdxDesc[(UINT16)lIndex].aiKeyLen[0]);
// 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 = ComboBox_GetCurSel(
GetDlgItem(hWnd, IDE_SEARCH_COMBO));
lIndex = ComboBox_GetItemData(
GetDlgItem(hWnd, IDE_SEARCH_COMBO),
lSel);
// 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;
}