home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Internet Business Development Kit / PRODUCT_CD.iso / sqlsvr / odbcsdk / samples / trnslchk / options.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-07  |  27.8 KB  |  940 lines

  1. //*---------------------------------------------------------------------------------
  2. //| ODBC Sample Translation DLL and Tool
  3. //|
  4. //|  This code is furnished on an as-is basis as part of the ODBC SDK and is
  5. //|  intended for example purposes only.
  6. //|
  7. //| Title:    OPTIONS.C
  8. //|
  9. //| Purpose:
  10. //|    This module contains the code required to edit TRNSLCHK.INI as well
  11. //|    as to handle any subsequent dialogs (eg: Filter).
  12. //|
  13. //*---------------------------------------------------------------------------------
  14.                
  15. VSZFile;
  16.  
  17. #include "options.h"
  18. #include <string.h>  
  19. #include <commdlg.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #ifndef WIN32
  23. #include "W16MACRO.H"
  24. #else
  25. #include <windowsx.h>
  26. #endif
  27.  
  28. //------------------------------------------------------------------------
  29. //  Declare global variables
  30. //------------------------------------------------------------------------
  31.  
  32. char OutStr[_MAXBUFF];
  33. LPSTR szFileTitleTrace            = "Trace";
  34. LPSTR szFileTitleBrowse            = "Browse";
  35. LPSTR szLogSpec                    = "Log File (*.LOG)\0*.LOG\0All Files (*.*)\0*.*\0";
  36. LPSTR szDLLSpec                    = "Translate DLL (*.DLL)\0*.DLL\0All Files (*.*)\0*.*\0";
  37. LPSTR szNone                        = "None";
  38. LPSTR szInstalled                    = "Installed";
  39. LPSTR szEmpty                        = "\0";
  40. LPSTR szOne                            = "1";
  41. LPSTR szZero                        = "0";
  42. LPSTR szNA                            = "N/A";
  43. LPSTR szTRNSLCHK                    = "TRNSLCHK";
  44. LPSTR szTRANSECTION                = "Translate DLLs";
  45. LPSTR szTRANSLATEDLL                = "TranslateDLL";
  46. LPSTR szTRACEFILE                    = "TraceFile";
  47. LPSTR szTRACEOPTION                = "TraceOption";
  48. LPSTR szCALLOPTION                = "CallOption";
  49. LPSTR szDISPLAYOPTION            = "DisplayOption";
  50. LPSTR szCFILTER                    = "CFilter";
  51. LPSTR szSQLFILTER                    = "SqlFilter";
  52. LPSTR szDEFAULT                    = "Default";
  53. LPSTR szTRNSLCHKOPTIONS            = "TRNSLCHK Options";
  54. LPSTR szWowLog                        = "TRNSLCHK.LOG";
  55. LPSTR szWARNOPT                    = "Warn On Unload";
  56. LPSTR szDeleteEntry                = "Delete entry %s?";
  57. LPSTR szps                            = "%s";
  58. LPSTR szpd                            = "%d";
  59. LPSTR szpu                            = "%u";
  60. LPSTR szplu                            = "%lu";
  61.  
  62. #ifndef WIN32
  63. LPSTR szTRNSLCHKINI                = "TRNSLCHK.INI";
  64. #else
  65. LPSTR szTRNSLCHKINI                = "TRNSLC32.INI";
  66. #endif
  67.  
  68. LPSTR szMustSaveNew                = "Must save new entry or choose existing before exiting.";
  69. LPSTR szSaveChanges                = "Save Translate Entry \"%s\"?";
  70. LPSTR szWinTitle                    = "ODBC Translation DLL Spy";
  71. LPSTR szOutOfMemory                = "Memory is very low.  Please close other applications.";
  72.  
  73. dCSEG(int) SqlMasks[NumSqlMasks] = {
  74. // idval
  75. // -------------------------
  76.     IDX_BIGINT,
  77.     IDX_BINARY,
  78.     IDX_BIT,
  79.     IDX_CHAR,
  80.     IDX_DATE,
  81.     IDX_DECIMAL,
  82.     IDX_DOUBLE,
  83.     IDX_FLOAT,
  84.     IDX_INTEGER,
  85.     IDX_LONGVARBINARY,
  86.     IDX_LONGVARCHAR,
  87.     IDX_NUMERIC,
  88.     IDX_REAL,
  89.     IDX_SMALLINT,
  90.     IDX_TIME,
  91.     IDX_TIMESTAMP,
  92.     IDX_TINYINT,
  93.     IDX_VARBINARY,
  94.     IDX_VARCHAR,
  95.     };
  96.  
  97. dCSEG(int) CMasks[NumCMasks] = {
  98. // idval
  99. // -------------------------
  100.     IDX_C_BINARY,
  101.     IDX_C_BIT,
  102.     IDX_C_CHAR,
  103.     IDX_C_DATE,
  104.     IDX_C_DOUBLE,
  105.     IDX_C_FLOAT,
  106.     IDX_C_LONG,
  107.     IDX_C_SHORT,
  108.     IDX_C_TIME,
  109.     IDX_C_TIMESTAMP,
  110.     IDX_C_TINYINT,
  111.     };
  112.  
  113.  
  114. //*------------------------------------------------------------------------
  115. //| Function Prototypes
  116. //*------------------------------------------------------------------------
  117. BOOL LoadTranslateLib(OPTIONS FAR * opt);
  118. void WINAPI strtoupper(LPSTR str);
  119. void FtoA(SFLOAT flt, LPSTR outstr);
  120. void DtoA(SDOUBLE dbl, LPSTR outstr);
  121.  
  122.  
  123.  
  124.  
  125. //*------------------------------------------------------------------------
  126. //| DisplayAbout:
  127. //|     Display the about box for this app.
  128. //*------------------------------------------------------------------------
  129. void INTFUN DisplayAbout(HWND hwnd, HINSTANCE hInst)
  130. {
  131.     DLGPROC dlgproc;
  132.  
  133.     dlgproc = MakeProcInstance(AboutWndProc, hInst);
  134.     if(-1 == DialogBox(hInst, "ABOUTBOX", hwnd, dlgproc))
  135.         MessageBox(hwnd, "Could not open dialog box.",
  136.             "About", MB_ICONEXCLAMATION);
  137.     FreeProcInstance((FARPROC) dlgproc);
  138. }
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. //*------------------------------------------------------------------------
  146. //| AboutWndProc:
  147. //|     Handle the About messages
  148. //*------------------------------------------------------------------------
  149. BOOL EXTFUN AboutWndProc(HWND        hDlg,
  150.                                         UINT msg,
  151.                                         WPARAM        wParam,
  152.                                         LPARAM        lParam)
  153. {
  154.     switch(msg) {
  155.         case WM_INITDIALOG:
  156.             CenterDialog(hDlg);
  157.             return FALSE;
  158.  
  159.  
  160.         case WM_COMMAND:
  161.             SendMessage(hDlg, WM_CLOSE, 0, 0L);
  162.             return TRUE;
  163.  
  164.  
  165.         case WM_CLOSE:
  166.             EndDialog(hDlg, FALSE);
  167.             return TRUE;
  168.  
  169.  
  170.         default:
  171.             return FALSE;
  172.         }
  173.  
  174.  
  175.  
  176.  
  177.  
  178. //*------------------------------------------------------------------------
  179. //| HandleOptions:
  180. //|   Displays our Options dialog to allow .ini changes and/or current 
  181. //|        session changes.
  182. //*------------------------------------------------------------------------
  183. void INTFUN HandleOptions(HWND hwnd, HINSTANCE hInst, OPTIONS FAR * opt)
  184. {
  185.     DLGPROC dlgproc;
  186.     LPARAMSTRUCT lp;
  187.  
  188.     lp.hInst = hInst;
  189.     lp.val = (void FAR *)opt;
  190.     
  191.     dlgproc = MakeProcInstance(OptionsWndProc, hInst);
  192.     if(-1 == DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_OPTIONS), hwnd, dlgproc, 
  193.                 (LPARAM)(LPARAMSTRUCT FAR *)&lp))
  194.         MessageBox(hwnd, "Could not open dialog box.",
  195.             "Options", MB_ICONEXCLAMATION);
  196.     FreeProcInstance((FARPROC) dlgproc);
  197. }
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. //*------------------------------------------------------------------------
  205. //| OptionsWndProc:
  206. //|     Handle the options messages
  207. //*------------------------------------------------------------------------
  208. BOOL EXTFUN OptionsWndProc(HWND        hDlg,
  209.                                         UINT msg,
  210.                                         WPARAM        wParam,
  211.                                         LPARAM        lParam)
  212. {
  213.     int        dex=0;
  214.     char        tmpbuff[_SMALLBUFF];
  215.     static     BOOL fNeedSave, fEditChange;
  216.     static    HGLOBAL hmem_opt;
  217.     static    OPTIONS FAR * opt;
  218.     static    OPTIONS FAR * savedopt;
  219.     static    HINSTANCE hInst;
  220.     static    LPARAMSTRUCT FAR * lp;
  221.     UDWORD    cf, sf;
  222.     BOOL        flag;
  223.  
  224.     switch(msg) {
  225.         case WM_INITDIALOG:
  226.             lp =  (LPARAMSTRUCT FAR *)lParam;
  227.             savedopt = (OPTIONS FAR *)lp->val;
  228.             hmem_opt = GlobalAlloc(LMEM_FIXED, sizeof(*opt));
  229.             opt = (OPTIONS FAR *) GlobalLock(hmem_opt);    
  230.             memcpy(opt, savedopt, sizeof(*opt));
  231.             hInst = lp->hInst;
  232.             fNeedSave = FALSE;
  233.             fEditChange = FALSE;
  234.             CenterDialog(hDlg);
  235.             PopulateEntries(hDlg, IDC_TRANENTRY, opt);
  236.             SendMessage(hDlg, USER_ENABLEBUTTONS, 0, 0L);
  237.             return TRUE;
  238.  
  239.  
  240.         case WM_COMMAND:
  241.             switch(GET_WM_COMMAND_ID(wParam, lParam)) {
  242.                 //-------------------------------------------------------------
  243.                 // Check for Check box changes
  244.                 //-------------------------------------------------------------
  245.                 case IDX_TRACE:
  246.                     fNeedSave = TRUE;
  247.                     opt->fTrace = IsDlgButtonChecked(hDlg, IDX_TRACE);
  248.                     if(opt->fTrace && (opt->szFile[0] == '\0'))
  249.                         SendMessage(hDlg, WM_COMMAND, IDB_TRACE, 0L);
  250.                     if(opt->fTrace && (opt->szFile[0] == '\0')) {
  251.                         opt->fTrace = FALSE;
  252.                         CheckDlgButton(hDlg, IDX_TRACE, opt->fTrace);
  253.                         }
  254.                     return TRUE;
  255.  
  256.                 case IDX_CALLDLL:
  257.                     fNeedSave = TRUE;
  258.                     opt->fCallDLL = IsDlgButtonChecked(hDlg, IDX_CALLDLL);
  259.                     if(opt->fCallDLL && opt->szDLL[0] == '\0')
  260.                         SendMessage(hDlg, WM_COMMAND, IDB_TRANSLATE, 0L);
  261.                     if(opt->fCallDLL && opt->szDLL[0] == '\0') {
  262.                         opt->fCallDLL = FALSE;
  263.                         CheckDlgButton(hDlg, IDX_CALLDLL, opt->fCallDLL);
  264.                         }
  265.                     return TRUE;
  266.  
  267.                 case IDX_DISPLAY:
  268.                     fNeedSave = TRUE;
  269.                     return TRUE;
  270.  
  271.  
  272.                 //-------------------------------------------------------------
  273.                 // Now check for button clicks
  274.                 //-------------------------------------------------------------
  275.                 case IDB_SETDEFAULT:
  276.                     WritePrivateProfileString(szTRNSLCHKOPTIONS, szDEFAULT,
  277.                                 opt->szEntry, 
  278.                                 szTRNSLCHKINI);
  279.                     SetFocus(GetDlgItem(hDlg, IDB_DONE));
  280.                     return TRUE;
  281.  
  282.                 case IDB_SAVE:
  283.                     opt->fTrace = IsDlgButtonChecked(hDlg, IDX_TRACE);
  284.                     opt->fCallDLL = IsDlgButtonChecked(hDlg, IDX_CALLDLL);
  285.                     opt->fDisplay = IsDlgButtonChecked(hDlg, IDX_DISPLAY);
  286.                     memcpy(savedopt, opt, sizeof(*opt));  //copy info
  287.                     WriteIniInfo(savedopt);
  288.                     SetFocus(GetDlgItem(hDlg, IDB_DONE));
  289.                     fNeedSave = FALSE;
  290.                     if(opt->fNewEntry) 
  291.                         PopulateEntries(hDlg, IDC_TRANENTRY, opt);
  292.                     opt->fNewEntry = FALSE;
  293.                     return TRUE;
  294.  
  295.                 case IDOK:                                // Enter key with no focus
  296.                 case IDCANCEL:                            // Escape keys
  297.                 case IDB_DONE:
  298.                     if(fEditChange) {
  299.                         SendMessage(hDlg, WM_COMMAND, IDC_TRANENTRY,
  300.                                     MAKELPARAM(0, CBN_KILLFOCUS));
  301.                         return TRUE;            // Treat like an OK button
  302.                         }
  303.                     if(!SaveUserChanges(hDlg, &fNeedSave,(LPSTR)opt->szEntry))
  304.                         return TRUE;
  305.                     if(opt->fNewEntry) {
  306.                         MessageBox(hDlg, szMustSaveNew, szWinTitle,
  307.                                 MB_OK);
  308.                         return TRUE;
  309.                         }
  310. #ifndef TRANSPEC_DEFS
  311.                     //  Now load the user's library if there is one.  If the
  312.                     //        load fails, make user fix the entry.
  313.                     if(opt->fCallDLL) 
  314.                         if(!LoadTranslateLib(opt))
  315.                             return TRUE;
  316. #endif
  317.                     SendMessage(hDlg, WM_CLOSE, 0, 0L);
  318.                     return TRUE;
  319.  
  320.                 case IDB_TRACE:
  321.                     if(!GetFileSpec(hDlg, opt->szFile, (LPSTR)szFileTitleTrace, (LPSTR)szLogSpec, OFN_CREATEPROMPT))
  322.                         return TRUE;
  323.                     fNeedSave = TRUE;
  324.                     opt->fTrace = TRUE;
  325.                     SetWindowText(GetDlgItem(hDlg, IDT_TRACEFILE), opt->szFile);
  326.                     CheckDlgButton(hDlg, IDX_TRACE, opt->fTrace);
  327.                     SetFocus(GetDlgItem(hDlg, IDB_DONE));
  328.                     return TRUE;
  329.  
  330.                 case IDB_TRANSLATE:
  331.                     if(!GetFileSpec(hDlg, opt->szDLL, (LPSTR)szFileTitleBrowse, (LPSTR)szDLLSpec,OFN_FILEMUSTEXIST)) //no create prompt
  332.                         return TRUE;
  333.                     fNeedSave = TRUE;
  334.                     opt->fCallDLL = TRUE;
  335.                     SetWindowText(GetDlgItem(hDlg, IDT_TRANSLATEDLL), opt->szDLL);
  336.                     CheckDlgButton(hDlg, IDX_CALLDLL, opt->fCallDLL);
  337.                     SetFocus(GetDlgItem(hDlg, IDB_DONE));
  338.                     return TRUE;
  339.  
  340.                 case IDB_DELETE:
  341.                     wsprintf(OutStr, szDeleteEntry, (LPSTR)opt->szEntry);
  342.                     if(IDYES == MessageBox(hDlg, OutStr, szWinTitle, MB_YESNO)) {
  343.                         DeleteIniInfo(opt);
  344.                         GetIniInfo(opt, TRUE);  // Get default
  345.                         PopulateEntries(hDlg, IDC_TRANENTRY, opt);
  346.                         SendMessage(hDlg, USER_UPDATEENTRY, 0, 0L);
  347.                         }
  348.                     return TRUE;
  349.  
  350.  
  351.                 case IDB_FILTER:
  352.                     cf = opt->CFilter;
  353.                     sf = opt->SqlFilter;
  354.                     DisplayFilter(hDlg, hInst, opt);
  355.                     SetFocus(GetDlgItem(hDlg, IDB_DONE));
  356.                     if(cf != opt->CFilter ||
  357.                         sf != opt->SqlFilter)
  358.                         fNeedSave = TRUE;
  359.                     return TRUE;
  360.  
  361.                 case IDB_ABOUT:
  362.                     DisplayAbout(hDlg, hInst);
  363.                     SetFocus(GetDlgItem(hDlg, IDB_DONE));
  364.                     return TRUE;
  365.  
  366.  
  367.                 default:
  368.                     break;
  369.                 }
  370.  
  371.  
  372.             //-------------------------------------------------------------
  373.             // If it wasn't a button click, check for a CBN_KILLFOCUS
  374.             //        which means that we have lost focus on a combo box.
  375.             //-------------------------------------------------------------
  376.             switch(GET_WM_COMMAND_CMD(wParam, lParam)) {
  377.                 //---------------------------------------------------------------
  378.                 //  Following is received when the user select a different
  379.                 //        entry from the list box.
  380.                 //---------------------------------------------------------------
  381.                 case CBN_SELCHANGE:
  382.                     SendMessage(hDlg, USER_SELCHANGE, 0, 0L);
  383.                     return TRUE;
  384.  
  385.                 //---------------------------------------------------------------
  386.                 //     When the user makes edit changes, we need to know
  387.                 //---------------------------------------------------------------
  388.                 case CBN_EDITCHANGE:
  389.                     fEditChange = TRUE;
  390.                     return FALSE;
  391.  
  392.                 //---------------------------------------------------------------
  393.                 //  Following is received when Translate Entry looses focus.
  394.                 //        If the user has made no edit changes, then we are o.k.
  395.                 //        as is so we just return.  If edit changes have been
  396.                 //        made, however, then we need to see if we have a new entry.
  397.                 //---------------------------------------------------------------
  398.                 case CBN_KILLFOCUS:
  399.                     if(!fEditChange) 
  400.                         return TRUE;
  401.                     GetText(hDlg, IDC_TRANENTRY, (LPSTR)tmpbuff);
  402.                     if(lstrcmpi(tmpbuff, opt->szEntry) == 0)
  403.                         return TRUE;            // Typed in same name
  404.                     if(!SaveUserChanges(hDlg, &fNeedSave,(LPSTR)opt->szEntry)) {
  405.                         return TRUE;
  406.                         }
  407.                     flag = (BOOL) SendDlgItemMessage(hDlg, IDC_TRANENTRY,
  408.                                     CB_FINDSTRINGEXACT, 0, (LPARAM)(LPSTR)tmpbuff);
  409.                     if(flag != CB_ERR) {        // Already in list
  410.                         SendDlgItemMessage(hDlg, IDC_TRANENTRY, CB_SETCURSEL,
  411.                                 (WPARAM)flag, 0L);
  412.                         SendMessage(hDlg, USER_SELCHANGE, 0, 0L);
  413.                         return TRUE;
  414.                         }
  415.                     lstrcpy(opt->szEntry, tmpbuff);
  416.                     SendMessage(hDlg, USER_UPDATEENTRY, 0, 0L);
  417.                     return TRUE;
  418.  
  419.                 default:
  420.                     return FALSE;
  421.                 }
  422.  
  423.             return FALSE;            // End of WM_COMMAND
  424.  
  425.  
  426.         case WM_CLOSE:
  427.             if(!SaveUserChanges(hDlg, &fNeedSave,(LPSTR)opt->szEntry))
  428.                 return TRUE;
  429.             GlobalUnlock(hmem_opt);
  430.             GlobalFree(hmem_opt);
  431.             EndDialog(hDlg, FALSE);
  432.             return TRUE;
  433.  
  434.  
  435.         case USER_ENABLEBUTTONS:
  436.             SetWindowText(GetDlgItem(hDlg, IDT_TRACEFILE), opt->szFile);
  437.             SetWindowText(GetDlgItem(hDlg, IDT_TRANSLATEDLL), opt->szDLL);
  438.             CheckDlgButton(hDlg, IDX_TRACE, opt->fTrace);
  439.             CheckDlgButton(hDlg, IDX_CALLDLL, opt->fCallDLL);
  440.              CheckDlgButton(hDlg, IDX_DISPLAY, opt->fDisplay);
  441.             flag = opt->fIsTranChk ? FALSE : TRUE;
  442.             EnableWindow(GetDlgItem(hDlg, IDB_TRANSLATE), flag);
  443.             EnableWindow(GetDlgItem(hDlg, IDX_CALLDLL), flag);
  444.             EnableWindow(GetDlgItem(hDlg, IDB_DELETE), flag);
  445.             SetFocus(GetDlgItem(hDlg, IDB_DONE));
  446.             return TRUE;
  447.  
  448.  
  449.         case USER_UPDATEENTRY:    
  450.             GetIniInfo(opt, FALSE);
  451.             fNeedSave = opt->fNewEntry;
  452.             fEditChange = FALSE;
  453.             SendMessage(hDlg, USER_ENABLEBUTTONS, 0, 0L);
  454.             return TRUE;
  455.  
  456.         case USER_SELCHANGE:
  457.             if(!SaveUserChanges(hDlg, &fNeedSave,(LPSTR)opt->szEntry))
  458.                 return TRUE;
  459.             opt->fNewEntry = FALSE;
  460.             SendDlgItemMessage(hDlg, IDC_TRANENTRY, CB_GETLBTEXT,
  461.                     (WPARAM)SendDlgItemMessage(hDlg, IDC_TRANENTRY, CB_GETCURSEL, 0, 0L),
  462.                     (LPARAM)(LPSTR)opt->szEntry);
  463.             SendMessage(hDlg, USER_UPDATEENTRY, 0, 0L);
  464.             return TRUE;
  465.  
  466.         default:
  467.             return FALSE;
  468.         }
  469.  
  470.     return FALSE;
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477. //*------------------------------------------------------------------------
  478. //| DisplayFilter:
  479. //|        Display the filter box to allow data types to be stripped out
  480. //*------------------------------------------------------------------------
  481. void INTFUN DisplayFilter(HWND hwnd, HINSTANCE hInst, OPTIONS FAR * opt)
  482. {
  483.     DLGPROC dlgproc;
  484.  
  485.     dlgproc = MakeProcInstance(FilterWndProc, hInst);
  486.     if(-1 == DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_FILTER), hwnd, dlgproc, (LPARAM)opt))
  487.         MessageBox(hwnd, "Could not open dialog box.",
  488.             "Filter", MB_ICONEXCLAMATION);
  489.     FreeProcInstance((FARPROC) dlgproc);
  490. }
  491.  
  492.  
  493.  
  494.  
  495.  
  496. //*------------------------------------------------------------------------
  497. //| FilterWndProc:
  498. //|     Handle the filter messages
  499. //*------------------------------------------------------------------------
  500. BOOL EXTFUN FilterWndProc(HWND        hDlg,
  501.                                     UINT msg,
  502.                                     WPARAM        wParam,
  503.                                     LPARAM        lParam)
  504. {
  505.     UDWORD     dex;
  506.     static     OPTIONS FAR * opt;
  507.  
  508.     switch(msg) {
  509.         case WM_INITDIALOG:
  510.             opt = (OPTIONS FAR *)lParam;
  511.             CenterDialog(hDlg);
  512.             for(dex=0;  dex<NumSqlMasks;  dex++) 
  513.                 CheckDlgButton(hDlg,
  514.                         SqlMasks[dex],
  515.                         BITTEST(opt->SqlFilter, dex));
  516.             for(dex=0;  dex<NumCMasks;  dex++)
  517.                 CheckDlgButton(hDlg,
  518.                         CMasks[dex],
  519.                         BITTEST(opt->CFilter, dex));
  520.             return FALSE;
  521.  
  522.  
  523.         case WM_COMMAND:
  524.             switch(GET_WM_COMMAND_ID(wParam, lParam)) {
  525.                 case IDOK:
  526.                     opt->SqlFilter = 0;
  527.                     opt->CFilter = 0;
  528.                     for(dex=0;  dex<NumSqlMasks;  dex++) 
  529.                         if(IsDlgButtonChecked(hDlg, SqlMasks[dex])) 
  530.                             BITSET(opt->SqlFilter, dex);
  531.                     for(dex=0;  dex<NumCMasks;  dex++)
  532.                         if(IsDlgButtonChecked(hDlg, CMasks[dex]))
  533.                             BITSET(opt->CFilter, dex);
  534.                     SendMessage(hDlg, WM_CLOSE, 0, 0L);
  535.                     return TRUE;
  536.  
  537.                 case IDCANCEL:
  538.                 case IDB_CANCEL:
  539.                     SendMessage(hDlg, WM_CLOSE, 0, 0L);
  540.                     return TRUE;
  541.  
  542.                 default:
  543.                     return FALSE;
  544.                 }
  545.             return TRUE;
  546.  
  547.  
  548.         case WM_CLOSE:
  549.             EndDialog(hDlg, FALSE);
  550.             return TRUE;
  551.  
  552.  
  553.         default:
  554.             return FALSE;
  555.         }
  556.  
  557.  
  558.  
  559.  
  560. //*------------------------------------------------------------------------
  561. //| SaveUserChanges:
  562. //|    If required, asks user if they want to save changes made.
  563. //|
  564. //|    Returns TRUE if the caller can procede, FALSE if they should cancel
  565. //*------------------------------------------------------------------------
  566. BOOL INTFUN SaveUserChanges(HWND hDlg, BOOL FAR * fSave, LPSTR szEntry)
  567. {
  568.     int    flag;
  569.    char    msg[100];
  570.    
  571.     if(!*fSave)
  572.         return TRUE;                // Nothing to save   
  573.     wsprintf(msg,(LPSTR) szSaveChanges, szEntry);
  574.     flag = MessageBox(hDlg, msg,(LPSTR)szWinTitle, MB_YESNOCANCEL);
  575.  
  576.     switch(flag)
  577.     {
  578.         case IDCANCEL:
  579.             return FALSE;
  580.         case IDYES:
  581.             SendMessage(hDlg, WM_COMMAND, IDB_SAVE, 0L);
  582.             *fSave = FALSE;
  583.             return TRUE;
  584.         case IDNO:
  585.             *fSave = FALSE;
  586.             return TRUE;
  587.     }
  588. }
  589.  
  590.  
  591.  
  592.  
  593.  
  594. //*------------------------------------------------------------------------
  595. //| SetIniDefaults:
  596. //|    Set default values for the options info
  597. //*------------------------------------------------------------------------
  598. void INTFUN SetIniDefaults(OPTIONS FAR * opt)
  599. {
  600.     lstrcpy(opt->szFile, szWowLog);
  601.     opt->szDLL[0] = '\0';
  602.     opt->fTrace = FALSE;
  603.     opt->fCallDLL = FALSE;
  604.     opt->fDisplay = TRUE;
  605.     opt->CFilter = (UDWORD) -1;            // Show everything possible
  606.     opt->SqlFilter = (UDWORD) -1;            // Show everything possible
  607. }
  608.  
  609.  
  610.  
  611.  
  612. //*------------------------------------------------------------------------
  613. //| GetIniInfo:
  614. //|    This function reads the default value out of the TRNSLCHK.INI file.
  615. //|        if this file does not exist, one is created.
  616. //*------------------------------------------------------------------------
  617. void INTFUN GetIniInfo(OPTIONS FAR * opt, BOOL fUseDefault)
  618. {
  619.     char tmpbuff[_SMALLBUFF];
  620.     char szFilter[25];
  621.  
  622.     // Retrieve the warn flag
  623.     opt->fWarn = GetPrivateProfileInt(szTRNSLCHKOPTIONS, szWARNOPT,
  624.                             TRUE, szTRNSLCHKINI);
  625.  
  626.     if(fUseDefault) {
  627.         if(!GetPrivateProfileString((LPSTR)szTRNSLCHKOPTIONS, (LPSTR)szDEFAULT,
  628.                 NULL, (LPSTR)opt->szEntry, sizeof(opt->szEntry), (LPSTR)szTRNSLCHKINI)) {
  629.             // File does not exist or entry not found, try to retrieve TRNSLCHK
  630.             //        just in case the user performed a delete operation which
  631.             //        deleted the default value
  632.             if(!GetPrivateProfileString(szTRANSECTION, opt->szEntry,
  633.                     NULL, OutStr, sizeof(OutStr), szTRNSLCHKINI)) {
  634.                 // Default not found and neither was TRNSLCHK, therefore we
  635.                 //        must create TRNSLCHK.INI from scratch
  636.                 lstrcpy(opt->szEntry, szTRNSLCHK);
  637.                 SetIniDefaults(opt);
  638.                 lstrcpy(opt->szDLL, szNA);
  639.                 opt->fNewEntry = FALSE;
  640.                 WritePrivateProfileString((LPSTR)szTRANSECTION, (LPSTR)szTRNSLCHK, (LPSTR)szInstalled, 
  641.                             (LPSTR)szTRNSLCHKINI);
  642.                 WritePrivateProfileString(szTRNSLCHKOPTIONS, szDISPLAYOPTION,
  643.                             szOne, szTRNSLCHKINI);
  644.                 WritePrivateProfileString(szTRNSLCHKOPTIONS, szDEFAULT,
  645.                              szTRNSLCHK, szTRNSLCHKINI);
  646.                 WritePrivateProfileString(szTRNSLCHK, szTRANSLATEDLL,
  647.                             szNA, szTRNSLCHKINI);
  648.                 WritePrivateProfileString(szTRNSLCHK, szTRACEFILE,
  649.                              szWowLog, szTRNSLCHKINI);
  650.                 WritePrivateProfileString(szTRNSLCHK, szTRACEOPTION, 
  651.                             szZero, szTRNSLCHKINI);
  652.                 WritePrivateProfileString(szTRNSLCHK, szCALLOPTION,
  653.                             szNA, szTRNSLCHKINI);
  654.                 WritePrivateProfileString(szTRNSLCHK, szDISPLAYOPTION,
  655.                             szOne, szTRNSLCHKINI);
  656.                 wsprintf(tmpbuff, szplu, opt->CFilter);
  657.                 WritePrivateProfileString(szTRNSLCHK, szCFILTER,
  658.                             tmpbuff, szTRNSLCHKINI);
  659.                 wsprintf(tmpbuff, szplu, opt->SqlFilter);
  660.                 WritePrivateProfileString(szTRNSLCHK, szSQLFILTER,
  661.                             tmpbuff, szTRNSLCHKINI);
  662.                 return;
  663.                 }
  664.             }
  665.         }
  666.     else {                // See if our entry exists.  If not, set defaults
  667.         if(!GetPrivateProfileString(szTRANSECTION, opt->szEntry,
  668.                     NULL, OutStr, sizeof(OutStr), szTRNSLCHKINI)) {
  669.             SetIniDefaults(opt);
  670.             opt->fNewEntry = TRUE;
  671.             opt->fIsTranChk = !lstrcmp(opt->szEntry, szTRNSLCHK);
  672.             return;
  673.             }
  674.         }
  675.  
  676.  
  677.     // See if we are using TRNSLCHK.DLL
  678.     opt->fIsTranChk = !lstrcmp(opt->szEntry, szTRNSLCHK);
  679.  
  680.     
  681.     // Get all but TranslateDLL and CallOption, which may not be loaded
  682.     //        if the default is TRNSLCHK.
  683.     opt->fTrace = GetPrivateProfileInt(opt->szEntry, szTRACEOPTION,
  684.                             FALSE, szTRNSLCHKINI);
  685.     if(!GetPrivateProfileString(opt->szEntry, szTRACEFILE,
  686.             NULL, opt->szFile, _SMALLBUFF, szTRNSLCHKINI)) {
  687.         opt->szFile[0] = '\0';                // No file to trace to
  688.         opt->fTrace = FALSE;                    // Therefore you cannot
  689.         }
  690.  
  691.  
  692.     // Retrieve display options and filters for all sources
  693.     opt->fDisplay = GetPrivateProfileInt(opt->szEntry, szDISPLAYOPTION,
  694.                             FALSE, szTRNSLCHKINI);
  695.  
  696.     if(GetPrivateProfileString(opt->szEntry, szCFILTER,
  697.             NULL, szFilter, sizeof(szFilter), szTRNSLCHKINI)) 
  698.         opt->CFilter = strtoul((LPSTR)szFilter,NULL,10);
  699.     else
  700.         opt->CFilter = (UDWORD) -1;  //sets all bits
  701.  
  702.     if(GetPrivateProfileString(opt->szEntry, szSQLFILTER,
  703.             NULL, szFilter, sizeof(szFilter), szTRNSLCHKINI)) 
  704.         opt->SqlFilter = strtoul((LPSTR)szFilter,NULL,10);
  705.     else
  706.         opt->SqlFilter = (UDWORD) -1; //sets all bits
  707.  
  708.  
  709.     // If the default entry is TRNSLCHK, then we handle differently
  710.     if(opt->fIsTranChk) {
  711.         opt->szDLL[0] = '\0';
  712.         opt->fCallDLL = FALSE;
  713.         return;
  714.         }
  715.  
  716.     opt->fCallDLL = GetPrivateProfileInt(opt->szEntry, szCALLOPTION,
  717.                             FALSE, szTRNSLCHKINI);
  718.     if(!GetPrivateProfileString(opt->szEntry, szTRANSLATEDLL,
  719.             NULL, opt->szDLL, _SMALLBUFF, szTRNSLCHKINI)) {
  720.         opt->szDLL[0] = '\0';                // No dll to call
  721.         opt->fCallDLL = FALSE;                 // Therefore you cannot
  722.         }
  723. }
  724.  
  725.  
  726.  
  727.  
  728.  
  729. //*------------------------------------------------------------------------
  730. //| WriteIniInfo:
  731. //|    This outputs the values for the current entry.
  732. //*------------------------------------------------------------------------
  733. void INTFUN WriteIniInfo(OPTIONS FAR * opt)
  734. {
  735.     char    tmpbuff[25];
  736.  
  737.     WritePrivateProfileString(szTRANSECTION, opt->szEntry, szInstalled, 
  738.                 szTRNSLCHKINI);
  739.     WritePrivateProfileString(opt->szEntry, szTRANSLATEDLL,
  740.                 opt->szDLL, szTRNSLCHKINI);
  741.     WritePrivateProfileString(opt->szEntry, szTRACEFILE,
  742.                 opt->szFile,  szTRNSLCHKINI);
  743.  
  744.     wsprintf(tmpbuff, szpd, opt->fTrace);
  745.     WritePrivateProfileString(opt->szEntry, szTRACEOPTION, 
  746.                 tmpbuff, szTRNSLCHKINI);
  747.  
  748.     wsprintf(tmpbuff, szpd, opt->fCallDLL);
  749.     WritePrivateProfileString(opt->szEntry, szCALLOPTION, 
  750.                 tmpbuff, szTRNSLCHKINI);
  751.  
  752.     wsprintf(tmpbuff, szpd, opt->fDisplay);
  753.     WritePrivateProfileString(opt->szEntry, szDISPLAYOPTION,
  754.                 tmpbuff, szTRNSLCHKINI);
  755.  
  756.     wsprintf(tmpbuff, szplu, opt->CFilter);
  757.     WritePrivateProfileString(opt->szEntry, szCFILTER,
  758.                 tmpbuff, szTRNSLCHKINI);
  759.  
  760.     wsprintf(tmpbuff, szplu, opt->SqlFilter);
  761.     WritePrivateProfileString(opt->szEntry, szSQLFILTER,
  762.                 tmpbuff, szTRNSLCHKINI);
  763.                 
  764.     wsprintf(tmpbuff, szpd, opt->fWarn);
  765.     WritePrivateProfileString(szTRNSLCHKOPTIONS, szWARNOPT,
  766.                 tmpbuff, szTRNSLCHKINI);
  767.  
  768.     return;
  769. }
  770.  
  771.  
  772.  
  773.  
  774.  
  775. //*------------------------------------------------------------------------
  776. //| DeleteIniInfo:
  777. //|    Delete a translate entry from the ini file.
  778. //*------------------------------------------------------------------------
  779. void INTFUN DeleteIniInfo(OPTIONS FAR * opt)
  780. {
  781.     WritePrivateProfileString(szTRANSECTION, opt->szEntry, NULL, szTRNSLCHKINI);
  782.     WritePrivateProfileString(opt->szEntry, NULL, NULL, szTRNSLCHKINI);
  783.  
  784.     return;
  785. }
  786.  
  787.  
  788.  
  789.  
  790.  
  791. //*------------------------------------------------------------------------
  792. //| GetFileSpec:
  793. //|    Uses the commdlg functions to get the spec for a file.
  794. //| Parms:
  795. //|    hwnd            - Window handle of parent
  796. //|    szInFile        - Output for file name
  797. //|    szTitle        - Title for window
  798. //|    szFilter        - Filter for file names
  799. //| Returns:
  800. //|    TRUE if successfull, FALSE otherwise
  801. //*------------------------------------------------------------------------
  802. BOOL INTFUN    GetFileSpec(HWND hwnd, LPSTR szInFile, LPSTR szTitle, LPSTR szFilter, DWORD dwAttrib)
  803. {
  804.     HFILE                    hFile;
  805.     OPENFILENAME        lpofn;
  806.     char                     szFile[_SMALLBUFF];
  807.     char                    szDirName[_SMALLBUFF];
  808.  
  809.     memset(&lpofn, 0, sizeof(OPENFILENAME));
  810.     szFile[0] = '\0';
  811.     GetWindowsDirectory(szDirName, sizeof(szDirName));
  812.     lpofn.lStructSize = sizeof(OPENFILENAME);
  813.     lpofn.hwndOwner = hwnd;
  814.     lpofn.lpstrFilter = szFilter;
  815.     lpofn.nFilterIndex = 1;
  816.     lpofn.lpstrFile = szFile;
  817.     lpofn.nMaxFile = sizeof(szFile);
  818.     lpofn.lpstrFileTitle = szTitle;
  819.     lpofn.nMaxFileTitle = sizeof(szTitle);
  820.     lpofn.lpstrInitialDir = szDirName;
  821.     lpofn.Flags = dwAttrib | OFN_NOREADONLYRETURN | OFN_HIDEREADONLY;
  822.     if(!GetOpenFileName(&lpofn)) 
  823.         return FALSE;
  824.  
  825.     hFile = _lopen(szFile, OF_READ);
  826.     WinAssert(hFile != NULL, (LPSTR)"Open of file failed.");
  827.     _lclose(hFile);
  828.  
  829.     lstrcpy(szInFile, szFile);
  830.     return TRUE;
  831. }
  832.  
  833.  
  834.  
  835.  
  836. //*------------------------------------------------------------------------
  837. //| PopulateEntries:
  838. //|    Take the entries from the TRNSLCHK list and add them to the
  839. //|        combo box passed in.
  840. //| Parms:
  841. //|    hDlg            - Window handle for the dialog
  842. //|    idval            - Control id for combo box
  843. //|    opt            - Pointer to options structure
  844. //*------------------------------------------------------------------------
  845. void INTFUN PopulateEntries(HWND hDlg, int idval, OPTIONS FAR * opt)
  846. {
  847.     char     entries[_MAXBUFF];
  848.     LPSTR    str=entries;
  849.     int    dex=0;
  850.     
  851.     if(!GetPrivateProfileString(szTRANSECTION, NULL,
  852.             NULL, entries, sizeof(entries), szTRNSLCHKINI)) {
  853.         GetIniInfo(opt, TRUE);            // Let's try this again
  854.         if(!GetPrivateProfileString(szTRANSECTION, NULL,
  855.             NULL, entries, sizeof(entries), szTRNSLCHKINI)) {
  856.             MessageBox(hDlg, "No entries found in TRNSLCHK.INI", "Error", MB_OK);
  857.             //should never happen
  858.             return;
  859.             }
  860.         }
  861.  
  862.     SendDlgItemMessage(hDlg, idval, CB_RESETCONTENT, (WPARAM) 0, (LPARAM) 0);
  863.     while(*str) {
  864.         SendDlgItemMessage(hDlg, idval, CB_ADDSTRING, 0, (LPARAM)(LPSTR)str);
  865.         str += lstrlen(str) + 1;
  866.         ++dex;
  867.         }
  868.     SendDlgItemMessage(hDlg, idval, CB_SETCURSEL,
  869.             (WPARAM)SendDlgItemMessage(hDlg, idval, CB_FINDSTRINGEXACT, 0,
  870.                         (LPARAM)(LPSTR)opt->szEntry), 0L);
  871. }
  872.  
  873.  
  874.  
  875.  
  876.  
  877. //*------------------------------------------------------------------------
  878. //| CenterDialog:
  879. //|        Center the dialog over the parent window.  It is possible that
  880. //|            their is not a parent window, since the Translate DLL was
  881. //|            never meant to display data.  For this reason, we may just
  882. //|            center over the entire screen.
  883. //*------------------------------------------------------------------------
  884. void INTFUN CenterDialog(HWND hdlg)
  885. {
  886.     RECT  rcParent;                         // Parent window client rect
  887.     RECT  rcDlg;                            // Dialog window rect
  888.     int   nLeft, nTop;                      // Top-left coordinates
  889.     int   cWidth, cHeight;                  // Width and height
  890.     HWND    hwnd;
  891.  
  892.     // Get frame window client rect in screen coordinates
  893.     if((hwnd = GetParent(hdlg)) == NULL) {
  894.         rcParent.top = rcParent.left = 0;
  895.         rcParent.right = GetSystemMetrics(SM_CXFULLSCREEN);
  896.         rcParent.bottom = GetSystemMetrics(SM_CYFULLSCREEN);
  897.         }
  898.     else 
  899.         GetWindowRect(hwnd, &rcParent);
  900.  
  901.     // Determine the top-left point for the dialog to be centered
  902.     GetWindowRect(hdlg, &rcDlg);
  903.     cWidth  = rcDlg.right  - rcDlg.left;
  904.     cHeight = rcDlg.bottom - rcDlg.top;
  905.     nLeft   = rcParent.left + 
  906.             (((rcParent.right  - rcParent.left) - cWidth ) / 2);
  907.     nTop    = rcParent.top  +
  908.             (((rcParent.bottom - rcParent.top ) - cHeight) / 2);
  909.     if (nLeft < 0) nLeft = 0;
  910.     if (nTop  < 0) nTop  = 0;
  911.  
  912.     // Place the dialog
  913.     MoveWindow(hdlg, nLeft, nTop, cWidth, cHeight, TRUE);
  914.     return;
  915. }
  916.  
  917.  
  918.  
  919.  
  920. //*------------------------------------------------------------------------
  921. //| WinAssertReal:
  922. //|        You can use the WinAssert macro to decide if an assertion error
  923. //|            has occurred. If so, simply display a message for the user.
  924. //*------------------------------------------------------------------------
  925. void WinAssertReal(int exp, LPSTR msg, LPSTR file, int line)
  926. {                                                                                    
  927.     char szBuffer[100];
  928.     char szFormat[] = "%s   File: %s, line:  %d";
  929.  
  930.     if (!exp) {    
  931.         wsprintf(szBuffer, szFormat, (LPSTR)msg, (LPSTR)file, (LPSTR)line);
  932.         MessageBox(NULL, szBuffer, "Assertion Error", MB_OK);
  933.         }
  934. }
  935.  
  936.  
  937.