home *** CD-ROM | disk | FTP | other *** search
- //*---------------------------------------------------------------------------------
- //| ODBC Sample Translation DLL and Tool
- //|
- //| This code is furnished on an as-is basis as part of the ODBC SDK and is
- //| intended for example purposes only.
- //|
- //| Title: OPTIONS.C
- //|
- //| Purpose:
- //| This module contains the code required to edit TRNSLCHK.INI as well
- //| as to handle any subsequent dialogs (eg: Filter).
- //|
- //*---------------------------------------------------------------------------------
-
- VSZFile;
-
- #include "options.h"
- #include <string.h>
- #include <commdlg.h>
- #include <stdlib.h>
- #include <stdio.h>
- #ifndef WIN32
- #include "W16MACRO.H"
- #else
- #include <windowsx.h>
- #endif
-
- //------------------------------------------------------------------------
- // Declare global variables
- //------------------------------------------------------------------------
-
- char OutStr[_MAXBUFF];
- LPSTR szFileTitleTrace = "Trace";
- LPSTR szFileTitleBrowse = "Browse";
- LPSTR szLogSpec = "Log File (*.LOG)\0*.LOG\0All Files (*.*)\0*.*\0";
- LPSTR szDLLSpec = "Translate DLL (*.DLL)\0*.DLL\0All Files (*.*)\0*.*\0";
- LPSTR szNone = "None";
- LPSTR szInstalled = "Installed";
- LPSTR szEmpty = "\0";
- LPSTR szOne = "1";
- LPSTR szZero = "0";
- LPSTR szNA = "N/A";
- LPSTR szTRNSLCHK = "TRNSLCHK";
- LPSTR szTRANSECTION = "Translate DLLs";
- LPSTR szTRANSLATEDLL = "TranslateDLL";
- LPSTR szTRACEFILE = "TraceFile";
- LPSTR szTRACEOPTION = "TraceOption";
- LPSTR szCALLOPTION = "CallOption";
- LPSTR szDISPLAYOPTION = "DisplayOption";
- LPSTR szCFILTER = "CFilter";
- LPSTR szSQLFILTER = "SqlFilter";
- LPSTR szDEFAULT = "Default";
- LPSTR szTRNSLCHKOPTIONS = "TRNSLCHK Options";
- LPSTR szWowLog = "TRNSLCHK.LOG";
- LPSTR szWARNOPT = "Warn On Unload";
- LPSTR szDeleteEntry = "Delete entry %s?";
- LPSTR szps = "%s";
- LPSTR szpd = "%d";
- LPSTR szpu = "%u";
- LPSTR szplu = "%lu";
-
- #ifndef WIN32
- LPSTR szTRNSLCHKINI = "TRNSLCHK.INI";
- #else
- LPSTR szTRNSLCHKINI = "TRNSLC32.INI";
- #endif
-
- LPSTR szMustSaveNew = "Must save new entry or choose existing before exiting.";
- LPSTR szSaveChanges = "Save Translate Entry \"%s\"?";
- LPSTR szWinTitle = "ODBC Translation DLL Spy";
- LPSTR szOutOfMemory = "Memory is very low. Please close other applications.";
-
- dCSEG(int) SqlMasks[NumSqlMasks] = {
- // idval
- // -------------------------
- IDX_BIGINT,
- IDX_BINARY,
- IDX_BIT,
- IDX_CHAR,
- IDX_DATE,
- IDX_DECIMAL,
- IDX_DOUBLE,
- IDX_FLOAT,
- IDX_INTEGER,
- IDX_LONGVARBINARY,
- IDX_LONGVARCHAR,
- IDX_NUMERIC,
- IDX_REAL,
- IDX_SMALLINT,
- IDX_TIME,
- IDX_TIMESTAMP,
- IDX_TINYINT,
- IDX_VARBINARY,
- IDX_VARCHAR,
- };
-
- dCSEG(int) CMasks[NumCMasks] = {
- // idval
- // -------------------------
- IDX_C_BINARY,
- IDX_C_BIT,
- IDX_C_CHAR,
- IDX_C_DATE,
- IDX_C_DOUBLE,
- IDX_C_FLOAT,
- IDX_C_LONG,
- IDX_C_SHORT,
- IDX_C_TIME,
- IDX_C_TIMESTAMP,
- IDX_C_TINYINT,
- };
-
-
- //*------------------------------------------------------------------------
- //| Function Prototypes
- //*------------------------------------------------------------------------
- BOOL LoadTranslateLib(OPTIONS FAR * opt);
- void WINAPI strtoupper(LPSTR str);
- void FtoA(SFLOAT flt, LPSTR outstr);
- void DtoA(SDOUBLE dbl, LPSTR outstr);
-
-
-
-
- //*------------------------------------------------------------------------
- //| DisplayAbout:
- //| Display the about box for this app.
- //*------------------------------------------------------------------------
- void INTFUN DisplayAbout(HWND hwnd, HINSTANCE hInst)
- {
- DLGPROC dlgproc;
-
- dlgproc = MakeProcInstance(AboutWndProc, hInst);
- if(-1 == DialogBox(hInst, "ABOUTBOX", hwnd, dlgproc))
- MessageBox(hwnd, "Could not open dialog box.",
- "About", MB_ICONEXCLAMATION);
- FreeProcInstance((FARPROC) dlgproc);
- }
-
-
-
-
-
-
- //*------------------------------------------------------------------------
- //| AboutWndProc:
- //| Handle the About messages
- //*------------------------------------------------------------------------
- BOOL EXTFUN AboutWndProc(HWND hDlg,
- UINT msg,
- WPARAM wParam,
- LPARAM lParam)
- {
- switch(msg) {
- case WM_INITDIALOG:
- CenterDialog(hDlg);
- return FALSE;
-
-
- case WM_COMMAND:
- SendMessage(hDlg, WM_CLOSE, 0, 0L);
- return TRUE;
-
-
- case WM_CLOSE:
- EndDialog(hDlg, FALSE);
- return TRUE;
-
-
- default:
- return FALSE;
- }
- }
-
-
-
-
-
- //*------------------------------------------------------------------------
- //| HandleOptions:
- //| Displays our Options dialog to allow .ini changes and/or current
- //| session changes.
- //*------------------------------------------------------------------------
- void INTFUN HandleOptions(HWND hwnd, HINSTANCE hInst, OPTIONS FAR * opt)
- {
- DLGPROC dlgproc;
- LPARAMSTRUCT lp;
-
- lp.hInst = hInst;
- lp.val = (void FAR *)opt;
-
- dlgproc = MakeProcInstance(OptionsWndProc, hInst);
- if(-1 == DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_OPTIONS), hwnd, dlgproc,
- (LPARAM)(LPARAMSTRUCT FAR *)&lp))
- MessageBox(hwnd, "Could not open dialog box.",
- "Options", MB_ICONEXCLAMATION);
- FreeProcInstance((FARPROC) dlgproc);
- }
-
-
-
-
-
-
- //*------------------------------------------------------------------------
- //| OptionsWndProc:
- //| Handle the options messages
- //*------------------------------------------------------------------------
- BOOL EXTFUN OptionsWndProc(HWND hDlg,
- UINT msg,
- WPARAM wParam,
- LPARAM lParam)
- {
- int dex=0;
- char tmpbuff[_SMALLBUFF];
- static BOOL fNeedSave, fEditChange;
- static HGLOBAL hmem_opt;
- static OPTIONS FAR * opt;
- static OPTIONS FAR * savedopt;
- static HINSTANCE hInst;
- static LPARAMSTRUCT FAR * lp;
- UDWORD cf, sf;
- BOOL flag;
-
- switch(msg) {
- case WM_INITDIALOG:
- lp = (LPARAMSTRUCT FAR *)lParam;
- savedopt = (OPTIONS FAR *)lp->val;
- hmem_opt = GlobalAlloc(LMEM_FIXED, sizeof(*opt));
- opt = (OPTIONS FAR *) GlobalLock(hmem_opt);
- memcpy(opt, savedopt, sizeof(*opt));
- hInst = lp->hInst;
- fNeedSave = FALSE;
- fEditChange = FALSE;
- CenterDialog(hDlg);
- PopulateEntries(hDlg, IDC_TRANENTRY, opt);
- SendMessage(hDlg, USER_ENABLEBUTTONS, 0, 0L);
- return TRUE;
-
-
- case WM_COMMAND:
- switch(GET_WM_COMMAND_ID(wParam, lParam)) {
- //-------------------------------------------------------------
- // Check for Check box changes
- //-------------------------------------------------------------
- case IDX_TRACE:
- fNeedSave = TRUE;
- opt->fTrace = IsDlgButtonChecked(hDlg, IDX_TRACE);
- if(opt->fTrace && (opt->szFile[0] == '\0'))
- SendMessage(hDlg, WM_COMMAND, IDB_TRACE, 0L);
- if(opt->fTrace && (opt->szFile[0] == '\0')) {
- opt->fTrace = FALSE;
- CheckDlgButton(hDlg, IDX_TRACE, opt->fTrace);
- }
- return TRUE;
-
- case IDX_CALLDLL:
- fNeedSave = TRUE;
- opt->fCallDLL = IsDlgButtonChecked(hDlg, IDX_CALLDLL);
- if(opt->fCallDLL && opt->szDLL[0] == '\0')
- SendMessage(hDlg, WM_COMMAND, IDB_TRANSLATE, 0L);
- if(opt->fCallDLL && opt->szDLL[0] == '\0') {
- opt->fCallDLL = FALSE;
- CheckDlgButton(hDlg, IDX_CALLDLL, opt->fCallDLL);
- }
- return TRUE;
-
- case IDX_DISPLAY:
- fNeedSave = TRUE;
- return TRUE;
-
-
- //-------------------------------------------------------------
- // Now check for button clicks
- //-------------------------------------------------------------
- case IDB_SETDEFAULT:
- WritePrivateProfileString(szTRNSLCHKOPTIONS, szDEFAULT,
- opt->szEntry,
- szTRNSLCHKINI);
- SetFocus(GetDlgItem(hDlg, IDB_DONE));
- return TRUE;
-
- case IDB_SAVE:
- opt->fTrace = IsDlgButtonChecked(hDlg, IDX_TRACE);
- opt->fCallDLL = IsDlgButtonChecked(hDlg, IDX_CALLDLL);
- opt->fDisplay = IsDlgButtonChecked(hDlg, IDX_DISPLAY);
- memcpy(savedopt, opt, sizeof(*opt)); //copy info
- WriteIniInfo(savedopt);
- SetFocus(GetDlgItem(hDlg, IDB_DONE));
- fNeedSave = FALSE;
- if(opt->fNewEntry)
- PopulateEntries(hDlg, IDC_TRANENTRY, opt);
- opt->fNewEntry = FALSE;
- return TRUE;
-
- case IDOK: // Enter key with no focus
- case IDCANCEL: // Escape keys
- case IDB_DONE:
- if(fEditChange) {
- SendMessage(hDlg, WM_COMMAND, IDC_TRANENTRY,
- MAKELPARAM(0, CBN_KILLFOCUS));
- return TRUE; // Treat like an OK button
- }
- if(!SaveUserChanges(hDlg, &fNeedSave,(LPSTR)opt->szEntry))
- return TRUE;
- if(opt->fNewEntry) {
- MessageBox(hDlg, szMustSaveNew, szWinTitle,
- MB_OK);
- return TRUE;
- }
- #ifndef TRANSPEC_DEFS
- // Now load the user's library if there is one. If the
- // load fails, make user fix the entry.
- if(opt->fCallDLL)
- if(!LoadTranslateLib(opt))
- return TRUE;
- #endif
- SendMessage(hDlg, WM_CLOSE, 0, 0L);
- return TRUE;
-
- case IDB_TRACE:
- if(!GetFileSpec(hDlg, opt->szFile, (LPSTR)szFileTitleTrace, (LPSTR)szLogSpec, OFN_CREATEPROMPT))
- return TRUE;
- fNeedSave = TRUE;
- opt->fTrace = TRUE;
- SetWindowText(GetDlgItem(hDlg, IDT_TRACEFILE), opt->szFile);
- CheckDlgButton(hDlg, IDX_TRACE, opt->fTrace);
- SetFocus(GetDlgItem(hDlg, IDB_DONE));
- return TRUE;
-
- case IDB_TRANSLATE:
- if(!GetFileSpec(hDlg, opt->szDLL, (LPSTR)szFileTitleBrowse, (LPSTR)szDLLSpec,OFN_FILEMUSTEXIST)) //no create prompt
- return TRUE;
- fNeedSave = TRUE;
- opt->fCallDLL = TRUE;
- SetWindowText(GetDlgItem(hDlg, IDT_TRANSLATEDLL), opt->szDLL);
- CheckDlgButton(hDlg, IDX_CALLDLL, opt->fCallDLL);
- SetFocus(GetDlgItem(hDlg, IDB_DONE));
- return TRUE;
-
- case IDB_DELETE:
- wsprintf(OutStr, szDeleteEntry, (LPSTR)opt->szEntry);
- if(IDYES == MessageBox(hDlg, OutStr, szWinTitle, MB_YESNO)) {
- DeleteIniInfo(opt);
- GetIniInfo(opt, TRUE); // Get default
- PopulateEntries(hDlg, IDC_TRANENTRY, opt);
- SendMessage(hDlg, USER_UPDATEENTRY, 0, 0L);
- }
- return TRUE;
-
-
- case IDB_FILTER:
- cf = opt->CFilter;
- sf = opt->SqlFilter;
- DisplayFilter(hDlg, hInst, opt);
- SetFocus(GetDlgItem(hDlg, IDB_DONE));
- if(cf != opt->CFilter ||
- sf != opt->SqlFilter)
- fNeedSave = TRUE;
- return TRUE;
-
- case IDB_ABOUT:
- DisplayAbout(hDlg, hInst);
- SetFocus(GetDlgItem(hDlg, IDB_DONE));
- return TRUE;
-
-
- default:
- break;
- }
-
-
- //-------------------------------------------------------------
- // If it wasn't a button click, check for a CBN_KILLFOCUS
- // which means that we have lost focus on a combo box.
- //-------------------------------------------------------------
- switch(GET_WM_COMMAND_CMD(wParam, lParam)) {
- //---------------------------------------------------------------
- // Following is received when the user select a different
- // entry from the list box.
- //---------------------------------------------------------------
- case CBN_SELCHANGE:
- SendMessage(hDlg, USER_SELCHANGE, 0, 0L);
- return TRUE;
-
- //---------------------------------------------------------------
- // When the user makes edit changes, we need to know
- //---------------------------------------------------------------
- case CBN_EDITCHANGE:
- fEditChange = TRUE;
- return FALSE;
-
- //---------------------------------------------------------------
- // Following is received when Translate Entry looses focus.
- // If the user has made no edit changes, then we are o.k.
- // as is so we just return. If edit changes have been
- // made, however, then we need to see if we have a new entry.
- //---------------------------------------------------------------
- case CBN_KILLFOCUS:
- if(!fEditChange)
- return TRUE;
- GetText(hDlg, IDC_TRANENTRY, (LPSTR)tmpbuff);
- if(lstrcmpi(tmpbuff, opt->szEntry) == 0)
- return TRUE; // Typed in same name
- if(!SaveUserChanges(hDlg, &fNeedSave,(LPSTR)opt->szEntry)) {
- return TRUE;
- }
- flag = (BOOL) SendDlgItemMessage(hDlg, IDC_TRANENTRY,
- CB_FINDSTRINGEXACT, 0, (LPARAM)(LPSTR)tmpbuff);
- if(flag != CB_ERR) { // Already in list
- SendDlgItemMessage(hDlg, IDC_TRANENTRY, CB_SETCURSEL,
- (WPARAM)flag, 0L);
- SendMessage(hDlg, USER_SELCHANGE, 0, 0L);
- return TRUE;
- }
- lstrcpy(opt->szEntry, tmpbuff);
- SendMessage(hDlg, USER_UPDATEENTRY, 0, 0L);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- return FALSE; // End of WM_COMMAND
-
-
- case WM_CLOSE:
- if(!SaveUserChanges(hDlg, &fNeedSave,(LPSTR)opt->szEntry))
- return TRUE;
- GlobalUnlock(hmem_opt);
- GlobalFree(hmem_opt);
- EndDialog(hDlg, FALSE);
- return TRUE;
-
-
- case USER_ENABLEBUTTONS:
- SetWindowText(GetDlgItem(hDlg, IDT_TRACEFILE), opt->szFile);
- SetWindowText(GetDlgItem(hDlg, IDT_TRANSLATEDLL), opt->szDLL);
- CheckDlgButton(hDlg, IDX_TRACE, opt->fTrace);
- CheckDlgButton(hDlg, IDX_CALLDLL, opt->fCallDLL);
- CheckDlgButton(hDlg, IDX_DISPLAY, opt->fDisplay);
- flag = opt->fIsTranChk ? FALSE : TRUE;
- EnableWindow(GetDlgItem(hDlg, IDB_TRANSLATE), flag);
- EnableWindow(GetDlgItem(hDlg, IDX_CALLDLL), flag);
- EnableWindow(GetDlgItem(hDlg, IDB_DELETE), flag);
- SetFocus(GetDlgItem(hDlg, IDB_DONE));
- return TRUE;
-
-
- case USER_UPDATEENTRY:
- GetIniInfo(opt, FALSE);
- fNeedSave = opt->fNewEntry;
- fEditChange = FALSE;
- SendMessage(hDlg, USER_ENABLEBUTTONS, 0, 0L);
- return TRUE;
-
- case USER_SELCHANGE:
- if(!SaveUserChanges(hDlg, &fNeedSave,(LPSTR)opt->szEntry))
- return TRUE;
- opt->fNewEntry = FALSE;
- SendDlgItemMessage(hDlg, IDC_TRANENTRY, CB_GETLBTEXT,
- (WPARAM)SendDlgItemMessage(hDlg, IDC_TRANENTRY, CB_GETCURSEL, 0, 0L),
- (LPARAM)(LPSTR)opt->szEntry);
- SendMessage(hDlg, USER_UPDATEENTRY, 0, 0L);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- return FALSE;
- }
-
-
-
-
-
-
- //*------------------------------------------------------------------------
- //| DisplayFilter:
- //| Display the filter box to allow data types to be stripped out
- //*------------------------------------------------------------------------
- void INTFUN DisplayFilter(HWND hwnd, HINSTANCE hInst, OPTIONS FAR * opt)
- {
- DLGPROC dlgproc;
-
- dlgproc = MakeProcInstance(FilterWndProc, hInst);
- if(-1 == DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_FILTER), hwnd, dlgproc, (LPARAM)opt))
- MessageBox(hwnd, "Could not open dialog box.",
- "Filter", MB_ICONEXCLAMATION);
- FreeProcInstance((FARPROC) dlgproc);
- }
-
-
-
-
-
- //*------------------------------------------------------------------------
- //| FilterWndProc:
- //| Handle the filter messages
- //*------------------------------------------------------------------------
- BOOL EXTFUN FilterWndProc(HWND hDlg,
- UINT msg,
- WPARAM wParam,
- LPARAM lParam)
- {
- UDWORD dex;
- static OPTIONS FAR * opt;
-
- switch(msg) {
- case WM_INITDIALOG:
- opt = (OPTIONS FAR *)lParam;
- CenterDialog(hDlg);
- for(dex=0; dex<NumSqlMasks; dex++)
- CheckDlgButton(hDlg,
- SqlMasks[dex],
- BITTEST(opt->SqlFilter, dex));
- for(dex=0; dex<NumCMasks; dex++)
- CheckDlgButton(hDlg,
- CMasks[dex],
- BITTEST(opt->CFilter, dex));
- return FALSE;
-
-
- case WM_COMMAND:
- switch(GET_WM_COMMAND_ID(wParam, lParam)) {
- case IDOK:
- opt->SqlFilter = 0;
- opt->CFilter = 0;
- for(dex=0; dex<NumSqlMasks; dex++)
- if(IsDlgButtonChecked(hDlg, SqlMasks[dex]))
- BITSET(opt->SqlFilter, dex);
- for(dex=0; dex<NumCMasks; dex++)
- if(IsDlgButtonChecked(hDlg, CMasks[dex]))
- BITSET(opt->CFilter, dex);
- SendMessage(hDlg, WM_CLOSE, 0, 0L);
- return TRUE;
-
- case IDCANCEL:
- case IDB_CANCEL:
- SendMessage(hDlg, WM_CLOSE, 0, 0L);
- return TRUE;
-
- default:
- return FALSE;
- }
- return TRUE;
-
-
- case WM_CLOSE:
- EndDialog(hDlg, FALSE);
- return TRUE;
-
-
- default:
- return FALSE;
- }
- }
-
-
-
-
- //*------------------------------------------------------------------------
- //| SaveUserChanges:
- //| If required, asks user if they want to save changes made.
- //|
- //| Returns TRUE if the caller can procede, FALSE if they should cancel
- //*------------------------------------------------------------------------
- BOOL INTFUN SaveUserChanges(HWND hDlg, BOOL FAR * fSave, LPSTR szEntry)
- {
- int flag;
- char msg[100];
-
- if(!*fSave)
- return TRUE; // Nothing to save
- wsprintf(msg,(LPSTR) szSaveChanges, szEntry);
- flag = MessageBox(hDlg, msg,(LPSTR)szWinTitle, MB_YESNOCANCEL);
-
- switch(flag)
- {
- case IDCANCEL:
- return FALSE;
- case IDYES:
- SendMessage(hDlg, WM_COMMAND, IDB_SAVE, 0L);
- *fSave = FALSE;
- return TRUE;
- case IDNO:
- *fSave = FALSE;
- return TRUE;
- }
- }
-
-
-
-
-
- //*------------------------------------------------------------------------
- //| SetIniDefaults:
- //| Set default values for the options info
- //*------------------------------------------------------------------------
- void INTFUN SetIniDefaults(OPTIONS FAR * opt)
- {
- lstrcpy(opt->szFile, szWowLog);
- opt->szDLL[0] = '\0';
- opt->fTrace = FALSE;
- opt->fCallDLL = FALSE;
- opt->fDisplay = TRUE;
- opt->CFilter = (UDWORD) -1; // Show everything possible
- opt->SqlFilter = (UDWORD) -1; // Show everything possible
- }
-
-
-
-
- //*------------------------------------------------------------------------
- //| GetIniInfo:
- //| This function reads the default value out of the TRNSLCHK.INI file.
- //| if this file does not exist, one is created.
- //*------------------------------------------------------------------------
- void INTFUN GetIniInfo(OPTIONS FAR * opt, BOOL fUseDefault)
- {
- char tmpbuff[_SMALLBUFF];
- char szFilter[25];
-
- // Retrieve the warn flag
- opt->fWarn = GetPrivateProfileInt(szTRNSLCHKOPTIONS, szWARNOPT,
- TRUE, szTRNSLCHKINI);
-
- if(fUseDefault) {
- if(!GetPrivateProfileString((LPSTR)szTRNSLCHKOPTIONS, (LPSTR)szDEFAULT,
- NULL, (LPSTR)opt->szEntry, sizeof(opt->szEntry), (LPSTR)szTRNSLCHKINI)) {
- // File does not exist or entry not found, try to retrieve TRNSLCHK
- // just in case the user performed a delete operation which
- // deleted the default value
- if(!GetPrivateProfileString(szTRANSECTION, opt->szEntry,
- NULL, OutStr, sizeof(OutStr), szTRNSLCHKINI)) {
- // Default not found and neither was TRNSLCHK, therefore we
- // must create TRNSLCHK.INI from scratch
- lstrcpy(opt->szEntry, szTRNSLCHK);
- SetIniDefaults(opt);
- lstrcpy(opt->szDLL, szNA);
- opt->fNewEntry = FALSE;
- WritePrivateProfileString((LPSTR)szTRANSECTION, (LPSTR)szTRNSLCHK, (LPSTR)szInstalled,
- (LPSTR)szTRNSLCHKINI);
- WritePrivateProfileString(szTRNSLCHKOPTIONS, szDISPLAYOPTION,
- szOne, szTRNSLCHKINI);
- WritePrivateProfileString(szTRNSLCHKOPTIONS, szDEFAULT,
- szTRNSLCHK, szTRNSLCHKINI);
- WritePrivateProfileString(szTRNSLCHK, szTRANSLATEDLL,
- szNA, szTRNSLCHKINI);
- WritePrivateProfileString(szTRNSLCHK, szTRACEFILE,
- szWowLog, szTRNSLCHKINI);
- WritePrivateProfileString(szTRNSLCHK, szTRACEOPTION,
- szZero, szTRNSLCHKINI);
- WritePrivateProfileString(szTRNSLCHK, szCALLOPTION,
- szNA, szTRNSLCHKINI);
- WritePrivateProfileString(szTRNSLCHK, szDISPLAYOPTION,
- szOne, szTRNSLCHKINI);
- wsprintf(tmpbuff, szplu, opt->CFilter);
- WritePrivateProfileString(szTRNSLCHK, szCFILTER,
- tmpbuff, szTRNSLCHKINI);
- wsprintf(tmpbuff, szplu, opt->SqlFilter);
- WritePrivateProfileString(szTRNSLCHK, szSQLFILTER,
- tmpbuff, szTRNSLCHKINI);
- return;
- }
- }
- }
- else { // See if our entry exists. If not, set defaults
- if(!GetPrivateProfileString(szTRANSECTION, opt->szEntry,
- NULL, OutStr, sizeof(OutStr), szTRNSLCHKINI)) {
- SetIniDefaults(opt);
- opt->fNewEntry = TRUE;
- opt->fIsTranChk = !lstrcmp(opt->szEntry, szTRNSLCHK);
- return;
- }
- }
-
-
- // See if we are using TRNSLCHK.DLL
- opt->fIsTranChk = !lstrcmp(opt->szEntry, szTRNSLCHK);
-
-
- // Get all but TranslateDLL and CallOption, which may not be loaded
- // if the default is TRNSLCHK.
- opt->fTrace = GetPrivateProfileInt(opt->szEntry, szTRACEOPTION,
- FALSE, szTRNSLCHKINI);
- if(!GetPrivateProfileString(opt->szEntry, szTRACEFILE,
- NULL, opt->szFile, _SMALLBUFF, szTRNSLCHKINI)) {
- opt->szFile[0] = '\0'; // No file to trace to
- opt->fTrace = FALSE; // Therefore you cannot
- }
-
-
- // Retrieve display options and filters for all sources
- opt->fDisplay = GetPrivateProfileInt(opt->szEntry, szDISPLAYOPTION,
- FALSE, szTRNSLCHKINI);
-
- if(GetPrivateProfileString(opt->szEntry, szCFILTER,
- NULL, szFilter, sizeof(szFilter), szTRNSLCHKINI))
- opt->CFilter = strtoul((LPSTR)szFilter,NULL,10);
- else
- opt->CFilter = (UDWORD) -1; //sets all bits
-
- if(GetPrivateProfileString(opt->szEntry, szSQLFILTER,
- NULL, szFilter, sizeof(szFilter), szTRNSLCHKINI))
- opt->SqlFilter = strtoul((LPSTR)szFilter,NULL,10);
- else
- opt->SqlFilter = (UDWORD) -1; //sets all bits
-
-
- // If the default entry is TRNSLCHK, then we handle differently
- if(opt->fIsTranChk) {
- opt->szDLL[0] = '\0';
- opt->fCallDLL = FALSE;
- return;
- }
-
- opt->fCallDLL = GetPrivateProfileInt(opt->szEntry, szCALLOPTION,
- FALSE, szTRNSLCHKINI);
- if(!GetPrivateProfileString(opt->szEntry, szTRANSLATEDLL,
- NULL, opt->szDLL, _SMALLBUFF, szTRNSLCHKINI)) {
- opt->szDLL[0] = '\0'; // No dll to call
- opt->fCallDLL = FALSE; // Therefore you cannot
- }
- }
-
-
-
-
-
- //*------------------------------------------------------------------------
- //| WriteIniInfo:
- //| This outputs the values for the current entry.
- //*------------------------------------------------------------------------
- void INTFUN WriteIniInfo(OPTIONS FAR * opt)
- {
- char tmpbuff[25];
-
- WritePrivateProfileString(szTRANSECTION, opt->szEntry, szInstalled,
- szTRNSLCHKINI);
- WritePrivateProfileString(opt->szEntry, szTRANSLATEDLL,
- opt->szDLL, szTRNSLCHKINI);
- WritePrivateProfileString(opt->szEntry, szTRACEFILE,
- opt->szFile, szTRNSLCHKINI);
-
- wsprintf(tmpbuff, szpd, opt->fTrace);
- WritePrivateProfileString(opt->szEntry, szTRACEOPTION,
- tmpbuff, szTRNSLCHKINI);
-
- wsprintf(tmpbuff, szpd, opt->fCallDLL);
- WritePrivateProfileString(opt->szEntry, szCALLOPTION,
- tmpbuff, szTRNSLCHKINI);
-
- wsprintf(tmpbuff, szpd, opt->fDisplay);
- WritePrivateProfileString(opt->szEntry, szDISPLAYOPTION,
- tmpbuff, szTRNSLCHKINI);
-
- wsprintf(tmpbuff, szplu, opt->CFilter);
- WritePrivateProfileString(opt->szEntry, szCFILTER,
- tmpbuff, szTRNSLCHKINI);
-
- wsprintf(tmpbuff, szplu, opt->SqlFilter);
- WritePrivateProfileString(opt->szEntry, szSQLFILTER,
- tmpbuff, szTRNSLCHKINI);
-
- wsprintf(tmpbuff, szpd, opt->fWarn);
- WritePrivateProfileString(szTRNSLCHKOPTIONS, szWARNOPT,
- tmpbuff, szTRNSLCHKINI);
-
- return;
- }
-
-
-
-
-
- //*------------------------------------------------------------------------
- //| DeleteIniInfo:
- //| Delete a translate entry from the ini file.
- //*------------------------------------------------------------------------
- void INTFUN DeleteIniInfo(OPTIONS FAR * opt)
- {
- WritePrivateProfileString(szTRANSECTION, opt->szEntry, NULL, szTRNSLCHKINI);
- WritePrivateProfileString(opt->szEntry, NULL, NULL, szTRNSLCHKINI);
-
- return;
- }
-
-
-
-
-
- //*------------------------------------------------------------------------
- //| GetFileSpec:
- //| Uses the commdlg functions to get the spec for a file.
- //| Parms:
- //| hwnd - Window handle of parent
- //| szInFile - Output for file name
- //| szTitle - Title for window
- //| szFilter - Filter for file names
- //| Returns:
- //| TRUE if successfull, FALSE otherwise
- //*------------------------------------------------------------------------
- BOOL INTFUN GetFileSpec(HWND hwnd, LPSTR szInFile, LPSTR szTitle, LPSTR szFilter, DWORD dwAttrib)
- {
- HFILE hFile;
- OPENFILENAME lpofn;
- char szFile[_SMALLBUFF];
- char szDirName[_SMALLBUFF];
-
- memset(&lpofn, 0, sizeof(OPENFILENAME));
- szFile[0] = '\0';
- GetWindowsDirectory(szDirName, sizeof(szDirName));
- lpofn.lStructSize = sizeof(OPENFILENAME);
- lpofn.hwndOwner = hwnd;
- lpofn.lpstrFilter = szFilter;
- lpofn.nFilterIndex = 1;
- lpofn.lpstrFile = szFile;
- lpofn.nMaxFile = sizeof(szFile);
- lpofn.lpstrFileTitle = szTitle;
- lpofn.nMaxFileTitle = sizeof(szTitle);
- lpofn.lpstrInitialDir = szDirName;
- lpofn.Flags = dwAttrib | OFN_NOREADONLYRETURN | OFN_HIDEREADONLY;
- if(!GetOpenFileName(&lpofn))
- return FALSE;
-
- hFile = _lopen(szFile, OF_READ);
- WinAssert(hFile != NULL, (LPSTR)"Open of file failed.");
- _lclose(hFile);
-
- lstrcpy(szInFile, szFile);
- return TRUE;
- }
-
-
-
-
- //*------------------------------------------------------------------------
- //| PopulateEntries:
- //| Take the entries from the TRNSLCHK list and add them to the
- //| combo box passed in.
- //| Parms:
- //| hDlg - Window handle for the dialog
- //| idval - Control id for combo box
- //| opt - Pointer to options structure
- //*------------------------------------------------------------------------
- void INTFUN PopulateEntries(HWND hDlg, int idval, OPTIONS FAR * opt)
- {
- char entries[_MAXBUFF];
- LPSTR str=entries;
- int dex=0;
-
- if(!GetPrivateProfileString(szTRANSECTION, NULL,
- NULL, entries, sizeof(entries), szTRNSLCHKINI)) {
- GetIniInfo(opt, TRUE); // Let's try this again
- if(!GetPrivateProfileString(szTRANSECTION, NULL,
- NULL, entries, sizeof(entries), szTRNSLCHKINI)) {
- MessageBox(hDlg, "No entries found in TRNSLCHK.INI", "Error", MB_OK);
- //should never happen
- return;
- }
- }
-
- SendDlgItemMessage(hDlg, idval, CB_RESETCONTENT, (WPARAM) 0, (LPARAM) 0);
- while(*str) {
- SendDlgItemMessage(hDlg, idval, CB_ADDSTRING, 0, (LPARAM)(LPSTR)str);
- str += lstrlen(str) + 1;
- ++dex;
- }
- SendDlgItemMessage(hDlg, idval, CB_SETCURSEL,
- (WPARAM)SendDlgItemMessage(hDlg, idval, CB_FINDSTRINGEXACT, 0,
- (LPARAM)(LPSTR)opt->szEntry), 0L);
- }
-
-
-
-
-
- //*------------------------------------------------------------------------
- //| CenterDialog:
- //| Center the dialog over the parent window. It is possible that
- //| their is not a parent window, since the Translate DLL was
- //| never meant to display data. For this reason, we may just
- //| center over the entire screen.
- //*------------------------------------------------------------------------
- void INTFUN CenterDialog(HWND hdlg)
- {
- RECT rcParent; // Parent window client rect
- RECT rcDlg; // Dialog window rect
- int nLeft, nTop; // Top-left coordinates
- int cWidth, cHeight; // Width and height
- HWND hwnd;
-
- // Get frame window client rect in screen coordinates
- if((hwnd = GetParent(hdlg)) == NULL) {
- rcParent.top = rcParent.left = 0;
- rcParent.right = GetSystemMetrics(SM_CXFULLSCREEN);
- rcParent.bottom = GetSystemMetrics(SM_CYFULLSCREEN);
- }
- else
- GetWindowRect(hwnd, &rcParent);
-
- // Determine the top-left point for the dialog to be centered
- GetWindowRect(hdlg, &rcDlg);
- cWidth = rcDlg.right - rcDlg.left;
- cHeight = rcDlg.bottom - rcDlg.top;
- nLeft = rcParent.left +
- (((rcParent.right - rcParent.left) - cWidth ) / 2);
- nTop = rcParent.top +
- (((rcParent.bottom - rcParent.top ) - cHeight) / 2);
- if (nLeft < 0) nLeft = 0;
- if (nTop < 0) nTop = 0;
-
- // Place the dialog
- MoveWindow(hdlg, nLeft, nTop, cWidth, cHeight, TRUE);
- return;
- }
-
-
-
-
- //*------------------------------------------------------------------------
- //| WinAssertReal:
- //| You can use the WinAssert macro to decide if an assertion error
- //| has occurred. If so, simply display a message for the user.
- //*------------------------------------------------------------------------
- void WinAssertReal(int exp, LPSTR msg, LPSTR file, int line)
- {
- char szBuffer[100];
- char szFormat[] = "%s File: %s, line: %d";
-
- if (!exp) {
- wsprintf(szBuffer, szFormat, (LPSTR)msg, (LPSTR)file, (LPSTR)line);
- MessageBox(NULL, szBuffer, "Assertion Error", MB_OK);
- }
- }
-
-
-