home *** CD-ROM | disk | FTP | other *** search
- // BDE32 3.x - (C) Copyright 1996 by Borland International
-
- #include "address.h"
-
- //======================================================================
- // Name: FileOpenHook()
- //
- // Input: hWnd, msg, wParam, lParam.
- //
- // Return: TRUE - The table was opened successfully.
- // FALSE - The table failed to open.
- //
- // Desc: This routine will process all I/O for the dialog that will
- // open the table for us.
- //======================================================================
- BOOL FAR CALLBACK _export
- FileHook (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- #ifndef WIN32
- DLGPROC lpProc;
- #endif
- PASSSTRUCT *Passwd = NULL;
- static BOOL bUpper;
- static phDBIDb phDb;
- static UINT32 lNumAliases;
- static pDBDesc pAliases = NULL;
- static UINT32 lSel = 0;
- static BOOL bServer = FALSE;
- static pCS pCs;
- static BOOL bNew = FALSE;
-
- CHAR szAlias[MAXALIAS];
- CHAR szFile[DBIMAXNAMELEN]={0};
- DBIResult rslt;
- UINT16 iTableLen;
- CHAR szExt[5]={"\0"};
- pCHAR pszMsg = NULL;
- pCHAR pTemp;
-
- if(iMSGFileOK == message)
- {
- if(!bServer && bNew)
- {
- // Get the actual file name so that we can check if it
- // exists.
- GetFileTitle(((OPENFILENAME*)lParam)->lpstrFile, szFile,
- DBIMAXNAMELEN);
- strlwr(szFile);
- if(!ChkExt(szFile))
- {
- #ifndef WIN32
- lpProc = (DLGPROC)MakeProcInstance((FARPROC) TypeDlg,
- hInst);
-
- if(DialogBoxParam(hInst, "TypeDlg", hDlg, lpProc,
- (LONG)(void far*)szExt)==IDOK)
- #else
- if(DialogBoxParam(hInst, "TypeDlg", hDlg, TypeDlg,
- (LONG)(void far*)szExt)==IDOK)
- #endif
- {
- strcat(szFile, szExt);
- pTemp = ((OPENFILENAME*)lParam)->lpstrFile;
- pTemp[((OPENFILENAME*)lParam)->nFileOffset] = '\0';
- strcat(((OPENFILENAME*)lParam)->lpstrFile, szFile);
- #ifndef WIN32
- FreeProcInstance((FARPROC) lpProc);
- #endif
- return 0;
- }
- else
- {
- #ifndef WIN32
- FreeProcInstance((FARPROC) lpProc);
- #endif
- return 1;
- }
- }
- else
- {
- return 0;
- }
- }
- }
-
- switch (message)
- {
- case WM_INITDIALOG:
-
- // Get the Database pointer.
- pCs = (pCS)((OPENFILENAME*)lParam)->lCustData;
- phDb = pCs->phDb;
- if(pCs->uType == 1)
- {
- bNew = TRUE;
- }
- else
- {
- bNew = FALSE;
- }
-
- PostMessage(hDlg, WM_SETUP, 0, 0L);
- return TRUE;
-
- case WM_SETUP:
- // Hide the Addressbook type group if this is an open dialog.
- if(!bNew)
- {
- ShowWindow(GetDlgItem(hDlg, IDC_PERGROUP), SW_HIDE);
- ShowWindow(GetDlgItem(hDlg, IDC_BUSINESS), SW_HIDE);
- ShowWindow(GetDlgItem(hDlg, IDC_PERSONAL), SW_HIDE);
- }
-
- SetupDialog(hDlg, SW_SHOW);
-
- // Fill the Alias string with the aliases that are available to
- // the client.
- if(FillAliasStr(&pAliases, &lNumAliases)!=DBIERR_NONE)
- {
- SendMessage(hDlg, WM_DESTROY, 0, 0L);
- }
-
- // Fill the alias CB.
- FillAliasCBBox(pAliases, lNumAliases, cmb1, hDlg);
-
- // Choose the IDC_BUSINESS addressbook type as the defualt type.
- Button_SetCheck(GetDlgItem(hDlg, IDC_BUSINESS), 1);
-
- PostMessage(hDlg, WM_ALL, 0, 0L);
- bServer = FALSE;
- break;
-
- case WM_ALL:
- SetWindowText(GetDlgItem(hDlg, edt1), "*.dbf;*.db");
- PostMessage(hDlg, WM_COMMAND, IDOK, 0L);
- break;
-
- case WM_DESTROY:
- if(pAliases)
- {
- free(pAliases);
- }
- if(Passwd)
- {
- free(Passwd);
- }
- if(pszMsg)
- {
- free(pszMsg);
- }
- break;
-
- case WM_COMMAND:
- switch (GET_WM_COMMAND_ID(wParam,lParam))
- {
- case IDC_BUSINESS:
- pCs->uType = 1;
- break;
-
- case IDC_PERSONAL:
- pCs->uType = 2;
- break;
-
- case IDOK:
- if(bServer)
- {
- bIsServer = TRUE;
- memset((pCHAR)szTblName, '\0', DBIMAXTBLNAMELEN);
- GetWindowText(GetDlgItem(hDlg, edt1), szFile, 149);
-
- // Check if the table ends with a period.
- iTableLen = (UINT16)strlen((pCHAR)szFile);
- if(szFile[iTableLen - 1]=='.')
- {
- // If it does delete the period.
- szFile[iTableLen - 1] = '\0';
- }
- strcpy((pCHAR)szTblName, szFile);
-
- // Check the file case type on the server and set
- // the table name accordingly.
- if(bUpper)
- {
- strupr((pCHAR)szTblName);
- }
- else
- {
- strlwr((pCHAR)szTblName);
- }
-
- // We set the name legal.txt into the edit control
- // so that the Common Dialog DLL will not say that
- // the table name is illegal.
- SetWindowText(GetDlgItem(hDlg, edt1), "legal.txt");
-
- // Close the dialog with a TRUE return value.
- EndDialog(hDlg, TRUE);
- return FALSE;
- }
- else
- {
- bIsServer = FALSE;
- return FALSE;
- }
-
- case cmb1:
- switch (GET_WM_COMMAND_CMD(wParam,lParam))
- {
- case CBN_SELCHANGE:
- lSel = ComboBox_GetCurSel(GetDlgItem(hDlg,
- CB_GETCURSEL));
- (void)ComboBox_GetLBText(GetDlgItem(hDlg,
- CB_GETLBTEXT),
- lSel, szAlias);
-
- PostMessage(hDlg, WM_NEXTDLGCTL,
- (WPARAM)GetDlgItem(hDlg, edt1),
- (LPARAM)(BOOL) LOWORD(TRUE));
-
- // See if the alias is standard or if it is the
- // NULL alias.
- if((strnicmp(szAlias, "NULL", 4)==0) ||
- IsStandard(szAlias, pAliases, lNumAliases))
- {
- SetupDialog(hDlg, SW_SHOW);
-
- // If bServer than close the Database
- // that we opened up.
- if(bServer)
- {
- CloseDb(phDb);
- bServer = FALSE;
- OpenDB(phDb, NULL, NULL, NULL);
- }
-
- // Set the file extension to .db and .dbf
- // then send OK to display all local files.
- SetWindowText(GetDlgItem(hDlg, edt1),
- "*.db;*.dbf");
- PostMessage(hDlg, WM_COMMAND, IDOK, 0L);
- }
- // Otherwise this is a server alias. Therefore,
- // we need to know if it is a server alias.
- else
- {
- // This is a server alias - so display the
- // password dialogbox.
-
- // Hide the right side of the dialog box.
- SetupDialog(hDlg, SW_HIDE);
- SetWindowText(GetDlgItem(hDlg, edt1), "");
-
- // Clear the file list box
- SendMessage(GetDlgItem(hDlg, lst1),
- LB_RESETCONTENT, 0, 0L);
- if((Passwd = (PASSSTRUCT*) malloc
- (sizeof(PASSSTRUCT))) == NULL)
- {
- return FALSE;
- }
-
- // Copy in the alias and the physical
- // Database name.
- strcpy(Passwd->Alias, pAliases[(UINT16)
- lSel].szName);
- strcpy(Passwd->Database, pAliases[
- (UINT16)lSel].
- szPhyName);
- #ifndef WIN32
- lpProc = (DLGPROC)MakeProcInstance
- ((FARPROC) PasswdDlg, hInst);
- // Since we have get the password and
- // pass in the alias and database names
- // we need to pass in the Passwd
- // structure.
- if(DialogBoxParam(hInst, "PasswdDlg",
- hDlg, lpProc, (LONG)(void far*)
- Passwd)==IDOK)
- #else
- if(DialogBoxParam(hInst, "PasswdDlg",
- hDlg, PasswdDlg, (LONG)(void far*)
- Passwd)==IDOK)
- #endif
- {
- if(*phDb!=NULL)
- {
- CloseDb(phDb);
- }
-
- // Open the SQL Database.
- rslt=OpenDB(phDb, pAliases
- [(UINT16)lSel].szDbType,
- (pCHAR)Passwd,
- pAliases[(UINT16)lSel].
- szName);
-
- // If there were no errors then
- // get the list of available tables.
- if(rslt == DBIERR_NONE)
- {
- bServer = TRUE;
- HourGlassCursor(TRUE);
-
- // Fill the file listbox
- bUpper = FillFileList(hDlg, lst1,
- *phDb);
-
- // Set the alias as the directory
- // name in the file dialog box.
- SetWindowText(GetDlgItem(hDlg,
- stc1), pAliases[(UINT16)
- lSel].szPhyName);
-
- PostMessage(hDlg, WM_NEXTDLGCTL,
- (WPARAM)GetDlgItem(hDlg, edt1),
- (LPARAM)(BOOL) LOWORD(TRUE));
-
- HourGlassCursor(FALSE);
- }
- else
- {
- // Get the full information on
- // why the connection failed.
- DisplayError(rslt, &pszMsg);
-
- // Display the full error string.
- MessageBox(hDlg, pszMsg,
- "AddressBook Manager Error",
- MB_OK|MB_ICONINFORMATION);
-
- // Free the error string.
- free(pszMsg);
- }
- }
- #ifndef WIN32
- FreeProcInstance((FARPROC) lpProc);
- #endif
- free(Passwd);
- break;
- }
- return TRUE;
- }
- return TRUE;
- }
- break;
- }
- return FALSE;
- }
-
- //======================================================================
- // Name: PasswdDlg()
- //
- // Input: hWnd, msg, wParam, lParam. In the lParam is a structure that
- // holds the Alias, Database name, and Password string to fill.
- //
- // Return: TRUE - Password was entered.
- // FALSE - Password was not entered..
- //
- // Desc: This routine will process all I/O for the Password dialog.
- //======================================================================
- BOOL FAR CALLBACK _export
- PasswdDlg (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- BOOL bRet = FALSE;
- static PASSSTRUCT *PassWord = NULL;
-
- // Done to clear the unused warning.
- lParam = lParam;
-
- switch (msg)
- {
- case WM_INITDIALOG:
- PassWord = (PASSSTRUCT*)lParam;
- SetWindowText(GetDlgItem(hWnd, IDS_ALIAS), PassWord->Alias);
- SetWindowText(GetDlgItem(hWnd, IDS_DATABASE),
- PassWord->Database);
- PostMessage(hWnd,WM_NEXTDLGCTL,
- (WPARAM)GetDlgItem(hWnd,IDC_PASS),TRUE);
- break;
-
- case WM_COMMAND:
- switch (GET_WM_COMMAND_ID(wParam,lParam))
- {
- case IDOK:
- GetDlgItemText(hWnd, IDC_PASS, PassWord->Password,
- MAXPASSLEN -1);
- bRet = TRUE;
- EndDialog(hWnd, bRet);
- break;
-
- case IDCANCEL:
- bRet = FALSE;
- EndDialog(hWnd, bRet);
- break;
- }
- break;
- }
- return bRet;
- }
-
- //======================================================================
- // Name: TypeDlg()
- //
- // Input: hWnd, msg, wParam, lParam. In the lParam is the extension
- // string.
- //
- // Return: TRUE - Table type was chosen.
- // FALSE - Table type was not chosen.
- //
- // Desc: This routine will process all I/O for the Table Type dialog.
- //======================================================================
- BOOL FAR CALLBACK _export
- TypeDlg (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- BOOL bRet = FALSE;
- static pCHAR pszExtension;
- static CHAR szString[301] = {'\0'};
-
- // Done to clear the unused warning.
- lParam = lParam;
-
- switch (msg)
- {
- case WM_INITDIALOG:
- pszExtension = (pCHAR)lParam;
- LoadString(hInst, IDS_TABLETYPE, szString, 300);
- SetWindowText(GetDlgItem(hWnd, ID_TYPE_DESC), szString);
-
- // Choose the Paradox table type as the default.
- Button_SetCheck(GetDlgItem(hWnd, IDC_PARADOX), 1);
- break;
-
- case WM_COMMAND:
- switch (GET_WM_COMMAND_ID(wParam,lParam))
- {
- case IDOK:
- if (Button_GetCheck(GetDlgItem(hWnd, IDC_PARADOX)) == 1)
- {
- strcpy(pszExtension,".db\0");
- }
- else
- {
- strcpy(pszExtension, ".dbf\0");
- }
- bRet = TRUE;
- EndDialog(hWnd, bRet);
- break;
-
- case IDCANCEL:
- bRet = FALSE;
- EndDialog(hWnd, bRet);
- break;
- }
- break;
- }
- return(bRet);
- }
-
- //=========================================================================
- // Function: InitializeStruct()
- //
- // Input: Pointer to the common dialog structure (lpStruct), and a
- // pointer to the CREATESTRUCT structure (pCS).
- //
- // Returns: None.
- //
- // Desc: This function is used to initialize the structure for the
- // open/save file common dialog. This routine is called just
- // before the common dialogs API is called.
- //=========================================================================
- void
- InitializeStruct (LPSTR lpStruct, pCS pCs)
- {
- LPFOCHUNK lpFOChunk;
-
- lpFOChunk = (LPFOCHUNK)lpStruct;
-
- // If this is an open table structure.
- if(pCs->uType == 0)
- {
- strcpy(lpFOChunk->szTitle, "Open Table");
- }
- else
- {
- strcpy(lpFOChunk->szTitle, "New Table");
- }
-
- *(lpFOChunk->szFile) = 0;
- *(lpFOChunk->szFileTitle) = 0;
- lpFOChunk->ofn.lStructSize = sizeof(OPENFILENAME);
- lpFOChunk->ofn.hwndOwner = (HWND)hMainWnd;
- lpFOChunk->ofn.hInstance = hInst;
- lpFOChunk->ofn.lpstrFilter = NULL;
- lpFOChunk->ofn.lpstrCustomFilter = (LPSTR)NULL;
- lpFOChunk->ofn.nMaxCustFilter = 0L;
- lpFOChunk->ofn.nFilterIndex = 1L;
- lpFOChunk->ofn.lpstrFile = lpFOChunk->szFile;
- lpFOChunk->ofn.nMaxFile = (DWORD)sizeof(lpFOChunk->szFile);
- lpFOChunk->ofn.lpstrFileTitle = lpFOChunk->szFileTitle;
- lpFOChunk->ofn.nMaxFileTitle = MAXFILETITLELEN;
- lpFOChunk->ofn.lpstrInitialDir = szTblDirectory;
- lpFOChunk->ofn.lpstrTitle = lpFOChunk->szTitle;
- lpFOChunk->ofn.Flags = OFN_HIDEREADONLY |
- OFN_ENABLETEMPLATE |
- OFN_ENABLEHOOK;
- lpFOChunk->ofn.nFileOffset = 0;
- lpFOChunk->ofn.nFileExtension = 0;
- lpFOChunk->ofn.lpstrDefExt = (LPSTR)NULL;
- lpFOChunk->ofn.lCustData = (LPARAM)pCs;
- #ifndef WIN32
- lpFOChunk->ofn.lpfnHook = (FARHOOK)lpfnFileHook;
- #else
- lpFOChunk->ofn.lpfnHook = (FARHOOK)FileHook;
- #endif
- lpFOChunk->ofn.lpTemplateName = (LPSTR)MAKEINTRESOURCE
- (FILEOPENORD);
- return;
- }
-
- //=========================================================================
- // Function: ProcessCDError()
- //
- // Input: CommDlgError(UINT16), Pointer to the common dialog structure
- // (lpStruct).
- //
- // Returns: None.
- //
- // Desc: This function reports an error that has occurred during the
- // last call to a Common Dialog routine.
- //=========================================================================
- void
- ProcessCDError (UINT32 dwErrorCode)
- {
- UINT16 iStringID;
- CHAR szBuffer[200];
-
- switch(dwErrorCode)
- {
- case CDERR_DIALOGFAILURE: iStringID=IDS_DIALOGFAILURE; break;
- case CDERR_INITIALIZATION: iStringID=IDS_INITIALIZATION; break;
- case CDERR_NOTEMPLATE: iStringID=IDS_NOTEMPLATE; break;
- case CDERR_NOHINSTANCE: iStringID=IDS_NOHINSTANCE; break;
- case CDERR_LOCKRESFAILURE: iStringID=IDS_LOCKRESFAILURE; break;
- case CDERR_MEMALLOCFAILURE: iStringID=IDS_MEMALLOCFAILURE; break;
- case CDERR_MEMLOCKFAILURE: iStringID=IDS_MEMLOCKFAILURE; break;
-
- case 0: // User may have hit CANCEL or we got a *very* random
- // error
-
- default:
- return;
- }
-
- if (!LoadString(hInst, iStringID, szBuffer, sizeof(szBuffer)))
- {
- return;
- }
-
- MessageBox(hMainWnd, szBuffer, "AddressBook Error", MB_OK);
- return;
- }
-
- //=========================================================================
- // Function: ChkExt()
- //
- // Input: Pointer to a string that contains the filename to check
- // (pCHAR).
- //
- // Returns: TRUE: If the file has an extension of .db or .dbf
- // FALSE: If the file has an extension of anything else.
- //
- // Desc: This function simply checks if the filename has a .db in it.
- // It then checks if the next character is a 'f' (.dbf) or
- // a '/0' (.db). It then returns the result of its check.
- //=========================================================================
- BOOL
- ChkExt (pCHAR pszFileName)
- {
- pCHAR pName;
- BOOL bRet = FALSE;
- UINT16 i;
-
- strlwr(pszFileName);
- if((pName = strstr(pszFileName, ".db"))!=NULL)
- {
- if((pName[3]=='f') || (pName[3]=='\0'))
- {
- bRet = TRUE;
- }
- }
-
- if(!bRet)
- {
- i=0;
- while (i<strlen(pszFileName) && pszFileName[i]!='.')
- {
- i++;
- }
- pszFileName[i]='\0';
- }
- return bRet;
- }
-
- //=========================================================================
- // Function: IsStandard()
- //
- // Input: Pointer to a string that contains the Alias name(pCHAR),
- // Pointer to the alias list (pDBDesc), and the number of
- // aliases (UINT32).
- //
- // Returns: TRUE: If the alias is a standard alias.
- // FALSE: If the alias is not a standard alias.
- //
- // Desc: This function simply checks if the alias is a standard
- // alias. This is done by comparing the alias name with the
- // alias list that is passed in.
- //=========================================================================
- BOOL
- IsStandard (pCHAR pszAlias, pDBDesc pAliases, UINT32 lNumAliases)
- {
- UINT32 i;
- BOOL bRet = FALSE;
-
- for (i=0;i<lNumAliases;i++)
- {
- if(strcmpi(pAliases[(UINT16)i].szName, pszAlias)==0)
- {
- if(strcmpi(pAliases[(UINT16)i].szDbType, szCFGDBSTANDARD)==0)
- {
- bRet = TRUE;
- }
- }
- }
- return bRet;
- }
-
- //=========================================================================
- // Function: SetupDialog()
- //
- // Input: Handle to the CommonDialogBox (HWND), Value to pass
- // into the ShowWindow function like SW_HIDE (INT16).
- //
- // Returns: None.
- //
- // Desc: This function simply shows or hides the windows on the
- // right side of the common dialog box. This is done by
- // passing the second parameter of this function into the
- // ShowWindow function for each window we wish to affect.
- //=========================================================================
- void
- SetupDialog (HWND hDlg, INT16 iAction)
- {
- BOOL bFlag = TRUE;
-
- if(IsWindowVisible(GetDlgItem(hDlg, stc1)))
- {
- if(iAction == SW_SHOW)
- {
- // This way we will not redisplay what is already visable.
- bFlag = FALSE;
- }
- }
-
- if(bFlag)
- {
- ShowWindow(GetDlgItem(hDlg, stc1), iAction);
- ShowWindow(GetDlgItem(hDlg, stc5), iAction);
- ShowWindow(GetDlgItem(hDlg, stc4), iAction);
- ShowWindow(GetDlgItem(hDlg, cmb2), iAction);
- ShowWindow(GetDlgItem(hDlg, lst2), iAction);
- }
- }
-
-