home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / odbc / crsrdemo / dialogs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-05  |  39.7 KB  |  1,328 lines

  1. /*--------------------------------------------------------------------------
  2.   Dialogs.c -- Cursors dialogs
  3.  
  4.   Description:
  5.       This sample is spread across four files, each named for the role
  6.       the contained functions play.  Each file header contains a brief
  7.       description of its purpose and the routines it contains.
  8.  
  9.       DIALOGS.C contains those routines used to display and manage
  10.       dialogs.  Those functions are:
  11.  
  12.          AddEditControls - Dynamically create edit controls for UPDATE
  13.                         dialog
  14.          AddDlgProc      - Manage add row dialog
  15.          CenterDialog    - Center a dialog over its parent window
  16.          DoDialog        - Display a dialog
  17.          MyCreateDialog - Create a modeless dialog
  18.          GetEditControls - Retrieve values from dynamically created
  19.                         edit controls
  20.          IsMsgWaiting    - Check for waiting messages
  21.  
  22.          AboutDlgProc    - Manage about box
  23.          AbsDlgProc      - Manage absolute row number dialog
  24.          DataDlgProc     - Manage large data display dialog
  25.          FindDlgProc    - Manager dialog to get text string to find in result set
  26.          RelDlgProc      - Manage relative row number dialog
  27.          StmtDlgProc     - Manage SQL statement dialog
  28.          UpdateDlgProc   - Manage update row dialog
  29.          SqlTablesDlgProc- handle SQLTables-type request
  30.          ClassOnCommand - handle a command message
  31.  
  32.  
  33.   This code is furnished on an as-is basis as part of the ODBC SDK and is
  34.   intended for example purposes only.
  35.  
  36. --------------------------------------------------------------------------*/
  37.  
  38. // Includes ----------------------------------------------------------------
  39. #include "headers.h"
  40.  
  41. #include    "resource.h"
  42. #include "crsrdemo.h"
  43.  
  44.  
  45.  
  46. const char szCREATE[] = "CREATE TABLE %s (id int NOT NULL, name char(31) NOT NULL, C3 int)";
  47. const char szDROP[]   = "DROP TABLE %s";
  48. const char szINSERT[] = "INSERT INTO %s VALUES (?, '-FakeTable-FakeTable-FakeTable-', NULL)";
  49.  
  50. const int   xFIRST = 10;
  51. const int   cxSEP  = 6;
  52. const int   cySEP  = 3;
  53. const int   cxNAME = 35;
  54. const int   cyNAME = 8;
  55. const int   cxEDIT = 180;
  56. const int   cyEDIT = 10;
  57.  
  58. const DWORD dwDLGSTYLE    = DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU;
  59. const DWORD dwSTATICSTYLE = WS_CHILD | WS_VISIBLE | SS_RIGHT;
  60. const DWORD dwEDITSTYLE   = WS_BORDER | WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL | ES_LEFT;
  61.  
  62. #define STMTError(x) ODBCError(SQL_NULL_HENV, SQL_NULL_HDBC, lpmtbl->hstmt, (x))
  63.  
  64. #define  USERDATA GWL_USERDATA
  65.  
  66.  
  67. // Types -------------------------------------------------------------------
  68. typedef struct tagMTBL {                  // Make table structure
  69.    SQLHSTMT hstmt;                        //   HSTMT in use
  70.    SDWORD   i;                            //   Rows inserted
  71. } MTBL, FAR *LPMTBL;
  72.  
  73.  
  74. // Prototypes --------------------------------------------------------------
  75. void INTFUNC AddEditControls(HWND, LPCHILD);
  76. void INTFUNC CenterDialog(HWND);
  77. BOOL INTFUNC GetEditControls(HWND, LPCHILD);
  78. BOOL INTFUNC IsMsgWaiting(HWND);
  79. BOOL INTFUNC DlgProcFilter(HWND, UINT, WPARAM, LPARAM);
  80.  
  81.  
  82. /* AddEditControls ---------------------------------------------------------
  83.    Description: Add one edit control for each updateable bound column to
  84.                 the dialog box
  85.                 --------------------------------------------------------------------------*/
  86. void INTFUNC AddEditControls(HWND hDlg, LPCHILD lpChild)
  87. {
  88. #define DLGX(x)   (((x) * LOWORD(dwBaseUnits)) / 4)
  89. #define DLGY(y)   (((y) * HIWORD(dwBaseUnits)) / 8)
  90.  
  91.    HWND  hWnd;
  92.    HFONT hfont;
  93.    RECT  rc;
  94.    LPCOL lpcol;
  95.    char  sz[cbMAXSQL];
  96.    char  szFmt[cbSTRLEN];
  97.    DWORD dwBaseUnits;
  98.    UINT  idName, idEdit;
  99.    int      xName, yName;
  100.    int      cxName, cyName;
  101.    int      xEdit, yEdit;
  102.    int      cxEdit, cyEdit;
  103.    int      i;
  104.    HDC   hdc;
  105.    SIZE  size;
  106.  
  107.    // Determine basic characteristics and start position in dialog
  108.    hfont = (HFONT)SendDlgItemMessage(hDlg, IDC_STATIC1,
  109.                                      WM_GETFONT, 0, 0L);
  110.  
  111.    dwBaseUnits = GetDialogBaseUnits();
  112.  
  113.    cxName = DLGX(cxNAME);
  114.    cyName = DLGY(cyNAME);
  115.    cxEdit = DLGX(cxEDIT);
  116.    cyEdit = DLGY(cyEDIT);
  117.  
  118.    LoadString(g_hinst, IDS_COLNAME, szFmt, sizeof(szFmt));
  119.  
  120.    // Calculate the size of the largest name label
  121.  
  122.    hdc = GetDC(NULL);
  123.  
  124.    if( hdc ) {
  125.       for( i = 0, lpcol = lpChild->lpcol; i < lpChild->ccol; i++, lpcol++ )
  126.          if( IsUpdateable(lpcol->fSqlType) ) {
  127.             wsprintf(sz, szFmt, lpcol->szName);
  128.             GetTextExtentPoint(hdc, sz, lstrlen(sz), &size);
  129.             if( size.cx > cxName )
  130.                cxName = size.cx;
  131.          }
  132.       ReleaseDC(NULL, hdc);
  133.    }
  134.  
  135.    GetWindowRect(GetDlgItem(hDlg, IDOK), &rc);
  136.  
  137.    xName = DLGX(xFIRST);
  138.    yName = (4 * DLGY(cySEP)) + (DLGY(cySEP) / 2) + (2 * (rc.bottom - rc.top));
  139.  
  140.    xEdit = xName + cxName + DLGX(cxSEP);
  141.  
  142.    idName = stc1;
  143.    idEdit = edt1;
  144.  
  145.    // For each bound, updateable column, create and add an edit control
  146.    for (i=0, lpcol=lpChild->lpcol; i < lpChild->ccol; i++, lpcol++) {
  147.       if (IsUpdateable(lpcol->fSqlType)) {
  148.  
  149.          // Create control label
  150.          wsprintf(sz, szFmt, lpcol->szName);
  151.  
  152.          hWnd = CreateWindow(szSTATICCLASS, sz, dwSTATICSTYLE,
  153.                              xName, yName, cxName, cyName, hDlg,
  154.                              (HMENU)idName, g_hinst, NULL);
  155.  
  156.          FORWARD_WM_SETFONT(hWnd, hfont, 0, SendMessage);
  157.  
  158.          // Create (and intialize) edit control
  159.          yEdit = yName - ((cyEDIT - cyNAME) / 2);
  160.  
  161.          GetCurrentValue(sz, lpcol, lpChild);
  162.  
  163.          hWnd = CreateWindow(szEDITCLASS, sz, dwEDITSTYLE,
  164.                              xEdit, yEdit, cxEdit, cyEdit, hDlg,
  165.                              (HMENU)idEdit, g_hinst, NULL);
  166.  
  167.          FORWARD_WM_SETFONT(hWnd, hfont, 0, SendMessage);
  168.  
  169.          // Limit number of characters user can type to column display size
  170.          Edit_LimitText(hWnd, lpcol->cbc-1);
  171.  
  172.          yName += cyEdit + DLGY(cySEP);
  173.  
  174.          idName++;
  175.          idEdit++;
  176.       }
  177.    }
  178.  
  179.    // Grow dialog so that all controls are visible
  180.    GetClientRect(hDlg, &rc);
  181.  
  182.    rc.top    = 0;
  183.    rc.bottom = yName + DLGY(cySEP);
  184.  
  185.    rc.left   = 0;
  186.    rc.right  = (2 * DLGX(xFIRST)) + DLGX(cxNAME) + DLGX(cxEDIT) + DLGX(cxSEP);
  187.  
  188.    AdjustWindowRect(&rc, dwDLGSTYLE, FALSE);
  189.    MoveWindow(hDlg, 0, 0, rc.right - rc.left, rc.bottom - rc.top, TRUE);
  190.  
  191.    // Place OK and Cancel buttons appropriately
  192.    GetClientRect(hDlg, &rc);
  193.    {  RECT  rcButton;
  194.       int      x, y;
  195.  
  196.       GetWindowRect(GetDlgItem(hDlg, IDOK), &rcButton);
  197.  
  198.       x = rc.right - DLGX(cxSEP) - (rcButton.right - rcButton.left);
  199.       y = DLGY(cySEP);
  200.  
  201.       MoveWindow(GetDlgItem(hDlg, IDOK),
  202.                  x, y,
  203.                  rcButton.right - rcButton.left,
  204.                  rcButton.bottom - rcButton.top,
  205.                  TRUE);
  206.  
  207.       y += rcButton.bottom - rcButton.top + (DLGY(cySEP) / 2);
  208.  
  209.       GetWindowRect(GetDlgItem(hDlg, IDCANCEL), &rcButton);
  210.       MoveWindow(GetDlgItem(hDlg, IDCANCEL),
  211.                  x, y,
  212.                  rcButton.right - rcButton.left,
  213.                  rcButton.bottom - rcButton.top,
  214.                  TRUE);
  215.    }
  216.  
  217.    return;
  218. }
  219.  
  220.  
  221. /* CenterDialog ------------------------------------------------------------
  222.    Description: Center dialog over its owning parent window
  223.                 If the entire dialog does not fit on the desktop,
  224.                 ensure upper left corner is always visible
  225.                 --------------------------------------------------------------------------*/
  226. void INTFUNC CenterDialog(HWND hDlg)
  227. {
  228.    RECT  rcDlg, rcScr, rcParent;
  229.    int      cx, cy;
  230.  
  231.    GetWindowRect(hDlg, &rcDlg);
  232.    cx = rcDlg.right  - rcDlg.left;
  233.    cy = rcDlg.bottom - rcDlg.top;
  234.  
  235.    GetWindowRect(GetParent(hDlg), &rcParent);
  236.    rcDlg.top    = rcParent.top +
  237.       (((rcParent.bottom - rcParent.top) - cy) >> 1);
  238.    rcDlg.left   = rcParent.left +
  239.       (((rcParent.right - rcParent.left) - cx) >> 1);
  240.    rcDlg.bottom = rcDlg.top  + cy;
  241.    rcDlg.right  = rcDlg.left + cx;
  242.  
  243.    GetWindowRect(GetDesktopWindow(), &rcScr);
  244.    if (rcDlg.bottom > rcScr.bottom) {
  245.       rcDlg.bottom = rcScr.bottom;
  246.       rcDlg.top    = rcDlg.bottom - cy;
  247.    }
  248.    if (rcDlg.right  > rcScr.right) {
  249.       rcDlg.right = rcScr.right;
  250.       rcDlg.left  = rcDlg.right - cx;
  251.    }
  252.  
  253.    if (rcDlg.left < 0) rcDlg.left = 0;
  254.    if (rcDlg.top  < 0) rcDlg.top  = 0;
  255.  
  256.    MoveWindow(hDlg, rcDlg.left, rcDlg.top, cx, cy, FALSE);
  257.    return;
  258. }
  259.  
  260.  
  261. /* DoDialog ----------------------------------------------------------------
  262.    Description: Launch a dialog passing child window variables
  263.    --------------------------------------------------------------------------*/
  264. int INTFUNC DoDialog(HWND    hWndParent,
  265.                      int     nDlgResNum,
  266.                      DLGPROC lpDlgProc)
  267. {
  268.    HWND  hWnd;
  269.    LPCHILD  lpChild;
  270.    int      nRC;
  271.  
  272.    hWnd    = FORWARD_WM_MDIGETACTIVE(g_hwndClient, SendMessage);
  273.    lpChild = (hWnd
  274.               ? (LPCHILD)GetWindowLong(hWnd, 0)
  275.               : NULL);
  276.  
  277.    nRC = DialogBoxParam(g_hinst,
  278.                         MAKEINTRESOURCE(nDlgResNum),
  279.                         hWndParent,
  280.                         lpDlgProc,
  281.                         (LONG)lpChild);
  282.    return nRC;
  283. }
  284.  
  285. /* MyCreateDialog ------------------------------------------------------------
  286.    Description: Launch a  modeless dialog passing child window variables
  287. --------------------------------------------------------------------------*/
  288.  
  289. HWND INTFUNC MyCreateDialog(HWND    hWndParent,
  290.                             int     nDlgResNum,
  291.                             DLGPROC lpDlgProc)
  292. {
  293.    HWND  hWnd, hWndRet;
  294.    LPCHILD  lpChild;
  295.  
  296.    hWnd    = FORWARD_WM_MDIGETACTIVE(g_hwndClient, SendMessage);
  297.    lpChild = (hWnd
  298.               ? (LPCHILD)GetWindowLong(hWnd, 0)
  299.               : NULL);
  300.  
  301.    hWndRet = CreateDialogParam(g_hinst,
  302.                                MAKEINTRESOURCE(nDlgResNum),
  303.                                hWndParent,
  304.                                lpDlgProc,
  305.                                (LPARAM)lpChild);
  306.    return hWndRet;
  307. }
  308.  
  309. /* GetEditControls ---------------------------------------------------------
  310.    Description: Get values from edit controls and move to row-set buffers
  311.    --------------------------------------------------------------------------*/
  312. BOOL INTFUNC GetEditControls(HWND hDlg, LPCHILD lpChild)
  313. {
  314.    LPCOL lpcol;
  315.    char  sz[cbMAXSQL];
  316.    UINT  idEdit;
  317.    BOOL  fChangeMade;
  318.    int      i;
  319.  
  320.    fChangeMade = FALSE;
  321.    idEdit      = edt1;
  322.  
  323.    // For each bound, updateable column, retrieve the value
  324.    for (i=0, lpcol=lpChild->lpcol; i < lpChild->ccol; i++, lpcol++) {
  325.       if (IsUpdateable(lpcol->fSqlType)) {
  326.  
  327.          // Get the control value
  328.          SendDlgItemMessage(hDlg, idEdit, WM_GETTEXT,
  329.                             (WPARAM)sizeof(sz), (LPARAM)((LPSTR)sz));
  330.  
  331.          // Move into row-set buffer
  332.          if (SetCurrentValue(sz, lpcol, lpChild) && !fChangeMade)
  333.             fChangeMade = TRUE;
  334.  
  335.          idEdit++;
  336.       }
  337.    }
  338.  
  339.    return fChangeMade;
  340. }
  341.  
  342.  
  343. /* IsMsgWaiting ------------------------------------------------------------
  344.    Description: Return TRUE if the Cancel button has been pressed
  345.    --------------------------------------------------------------------------*/
  346. BOOL INTFUNC IsMsgWaiting(HWND hWnd)
  347. {
  348.    MSG   msg;
  349.  
  350.    UNREF_PARAM (hWnd);
  351.  
  352.    // Check all waiting messages
  353.    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
  354.  
  355.       // Process message
  356.       TranslateMessage(&msg);
  357.       DispatchMessage(&msg);
  358.  
  359.       // Return TRUE if the Cancel button was pressed
  360.       if ((msg.message == WM_COMMAND
  361.            && GET_WM_COMMAND_ID(msg.wParam, msg.lParam) == IDCANCEL)
  362.           || msg.message == WMU_CANCEL)
  363.          return TRUE;
  364.    }
  365.    return FALSE;
  366. }
  367.  
  368. /* OptionsDlgProc ----------------------------------------------------------
  369.    Description: handle options dialog
  370. ----------------------------------------------------------------------------*/
  371.  
  372. BOOL EXPFUNC OptionsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  373. {
  374.  
  375.  
  376.    switch (msg) {
  377.  
  378.      case WM_INITDIALOG:
  379.       CenterDialog(hDlg);
  380.  
  381.       SetWindowLong(hDlg, USERDATA, (LONG)lParam);
  382.       InitializeDialogControls(hDlg, (LPCHILD) lParam);
  383.  
  384.       return TRUE;
  385.  
  386.      case WM_COMMAND:
  387.       (void) HANDLE_WM_COMMAND(hDlg,wParam,lParam,ClassOnCommand);
  388.       break;
  389.  
  390.       // New option dialog selected
  391.  
  392.      case WMU_NEWOPTION:
  393.       {
  394.          LPCHILD  lpChild = (LPCHILD) GetWindowLong(hDlg, USERDATA);
  395.  
  396.          if (g_hwndChildDialog)
  397.             DestroyWindow(g_hwndChildDialog);
  398.  
  399.          g_hwndChildDialog = MyCreateDialog(hDlg,
  400.                                             (int) lParam,
  401.                                             ChildOptDlgProc);
  402.  
  403.          SetFocus(GetDlgItem(hDlg, IDC_OPTIONLIST));
  404.  
  405.          break;
  406.       }
  407.  
  408.  
  409.       // Set title of option area
  410.  
  411.  
  412.      case WMU_SETSUBTEXT:
  413.       {
  414.          char  szBuffer[1000];
  415.  
  416.          ListBox_GetText(GetDlgItem(hDlg, wParam),
  417.                          ListBox_GetCurSel(GetDlgItem(hDlg,wParam)),
  418.                          szBuffer);
  419.  
  420.          Static_SetText( GetDlgItem(hDlg, IDC_OPTIONAREA_TITLE),
  421.                         szBuffer);
  422.          break;
  423.  
  424.       }
  425.  
  426.    }
  427.  
  428.    return DlgProcFilter(hDlg, msg, wParam, lParam);
  429. }
  430.  
  431. /* ChildOptDlgProc --------------------------------------------------------
  432.    Description: handle generic dialog
  433. ----------------------------------------------------------------------------*/
  434.  
  435. BOOL EXPFUNC ChildOptDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  436. {
  437.  
  438.    switch (msg) {
  439.  
  440.  
  441.      case WM_INITDIALOG:
  442.       SetWindowLong(hDlg, USERDATA, (LONG)lParam);
  443.       InitializeDialogControls(hDlg, (LPCHILD) lParam);
  444.  
  445.       // Align the window to a hidden static in the parent
  446.  
  447.       (void) AlignToControl(hDlg, GetParent(hDlg), IDC_OPTION_WINPOS);
  448.  
  449.       return TRUE;
  450.  
  451.      case WM_COMMAND:
  452.       return (BOOL)HANDLE_WM_COMMAND(hDlg,wParam,lParam,ClassOnCommand);
  453.  
  454.    }
  455.  
  456.    return DlgProcFilter(hDlg, msg, wParam, lParam);
  457. }
  458.  
  459.  
  460. /* AboutDlgProc ------------------------------------------------------------
  461.    Description: Display about box
  462.    --------------------------------------------------------------------------*/
  463. BOOL EXPFUNC AboutDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  464. {
  465.    UNREF_PARAM (lParam);
  466.  
  467.    switch (msg) {
  468.      case WM_INITDIALOG:
  469.       CenterDialog(hDlg);
  470.       return TRUE;
  471.  
  472.      case WM_COMMAND:
  473.       if (GET_WM_COMMAND_ID(wParam, lParam) == IDOK
  474.           || GET_WM_COMMAND_ID(wParam, lParam) == IDCANCEL) {
  475.          EndDialog(hDlg, GET_WM_COMMAND_ID(wParam, lParam));
  476.          return TRUE;
  477.       }
  478.       break;
  479.    }
  480.  
  481.    return DlgProcFilter(hDlg, msg, wParam, lParam);
  482. }
  483.  
  484.  
  485. /* AbsDlgProc --------------------------------------------------------------
  486.    Description: Get absolute row number to fetch
  487.    --------------------------------------------------------------------------*/
  488. BOOL EXPFUNC AbsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  489. {
  490.    LPCHILD  lpChild;
  491.    char  sz[11];
  492.    char  *EndPtr;
  493.    SDWORD   arow;
  494.  
  495.    lpChild = (LPCHILD)GetWindowLong(hDlg, USERDATA);
  496.  
  497.    switch (msg) {
  498.      case WM_INITDIALOG:
  499.       CenterDialog(hDlg);
  500.  
  501.       lpChild = (LPCHILD)lParam;
  502.  
  503.       SetWindowLong(hDlg, USERDATA, (LONG)lpChild);
  504.       wsprintf(sz, "%ld", lpChild->arow);
  505.       SetWindowText(GetDlgItem(hDlg, IDC_EDIT1), sz);
  506.       SendDlgItemMessage(hDlg, IDC_EDIT1,
  507.                          EM_LIMITTEXT, sizeof(sz)-1, 0L);
  508.       return TRUE;
  509.  
  510.      case WM_COMMAND:
  511.       switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  512.         case IDOK:
  513.          GetWindowText(GetDlgItem(hDlg, IDC_EDIT1), sz, sizeof(sz));
  514.          arow = strtol((char*) sz, &EndPtr, 10);
  515.          for (; *EndPtr &&
  516.               ISWHITE(*EndPtr); EndPtr = AnsiNext(EndPtr));
  517.          // the number inputed is within '0' to '9' or + or -
  518.          if (*EndPtr != '\0') {
  519.             MessageBox(hDlg,
  520.                        "Invalid absolute row number",
  521.                        NULL,
  522.                        MB_ICONSTOP);
  523.             return TRUE;
  524.          }
  525.          lpChild->arow = arow;
  526.  
  527.         case IDCANCEL:
  528.          EndDialog(hDlg, GET_WM_COMMAND_ID(wParam, lParam));
  529.          return TRUE;
  530.       }
  531.       break;
  532.    }
  533.  
  534.    return DlgProcFilter(hDlg, msg, wParam, lParam);
  535. }
  536.  
  537.  
  538. /* DataDlgProc -------------------------------------------------------------
  539.    Description: Display large data value (retrieved via SQLGetData)
  540.    --------------------------------------------------------------------------*/
  541. BOOL EXPFUNC DataDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  542. {
  543.    switch (msg) {
  544.      case WM_INITDIALOG: {
  545.         LPBIGCOL  lpbc;
  546.         char      sz[cbSTRLEN];
  547.         char      szNum[cbSTRLEN];
  548.         char      szFmt[cbSTRLEN];
  549.  
  550.         CenterDialog(hDlg);
  551.  
  552.         lpbc = (LPBIGCOL)lParam;
  553.  
  554.         if (lpbc->cb == SQL_NULL_DATA) {
  555.            lstrcpy(lpbc->lpsz, g_szNull);
  556.            lpbc->cb = 0;
  557.            _ltoa(0, szNum, 10);
  558.         }
  559.         else if (lpbc->cb == SQL_NO_TOTAL)
  560.            lstrcpy(szNum, g_szUnknown);
  561.         else
  562.            _ltoa(lpbc->cb, szNum, 10);
  563.  
  564.         LoadString(g_hinst, IDS_DATADLG, szFmt, sizeof(szFmt));
  565.         wsprintf(sz, szFmt, lpbc->szName, szNum);
  566.         SetWindowText(GetDlgItem(hDlg, IDC_TEXT1), sz);
  567.  
  568.         SetWindowText(GetDlgItem(hDlg, IDC_EDIT1), lpbc->lpsz);
  569.         return TRUE;
  570.      }
  571.  
  572.      case WM_COMMAND:
  573.       switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  574.         case IDOK:
  575.         case IDCANCEL:
  576.          EndDialog(hDlg, GET_WM_COMMAND_ID(wParam, lParam));
  577.          return TRUE;
  578.       }
  579.       break;
  580.    }
  581.  
  582.    return DlgProcFilter(hDlg, msg, wParam, lParam);
  583. }
  584.  
  585.  
  586. /* RelDlgProc --------------------------------------------------------------
  587.    Description: Get relative row offset to fetch
  588.    --------------------------------------------------------------------------*/
  589. BOOL EXPFUNC RelDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  590. {
  591.    LPCHILD  lpChild;
  592.    char  sz[7];
  593.  
  594.    lpChild = (LPCHILD)GetWindowLong(hDlg, USERDATA);
  595.  
  596.    switch (msg) {
  597.      case WM_INITDIALOG:
  598.       CenterDialog(hDlg);
  599.  
  600.       lpChild = (LPCHILD)lParam;
  601.       SetWindowLong(hDlg, USERDATA, (LONG)lpChild);
  602.  
  603.       wsprintf(sz, "%ld", lpChild->rrow);
  604.       SetWindowText(GetDlgItem(hDlg, IDC_EDIT1), sz);
  605.       SendDlgItemMessage(hDlg, IDC_EDIT1,
  606.                          EM_LIMITTEXT, sizeof(sz)-1, 0L);
  607.       return TRUE;
  608.  
  609.      case WM_COMMAND:
  610.       switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  611.         case IDOK: {
  612.            SDWORD rrow;
  613.            char   *EndPtr;
  614.  
  615.            GetWindowText(GetDlgItem(hDlg, IDC_EDIT1), sz, sizeof(sz));
  616.            rrow = strtol((char*) sz, &EndPtr, 10);
  617.            for (; *EndPtr &&
  618.                 ISWHITE(*EndPtr); EndPtr = AnsiNext(EndPtr));
  619.            // the number inputed is within '0' to '9' or + or -
  620.            if (*EndPtr != '\0' || rrow < -100000 || rrow > 100000) {
  621.               MessageBox(hDlg,
  622.                          "Step amount must be between -100,000 and 100,000",
  623.                          NULL,
  624.                          MB_ICONSTOP);
  625.               return TRUE;
  626.            }
  627.            lpChild->rrow = rrow;
  628.         }
  629.  
  630.         case IDCANCEL:
  631.          EndDialog(hDlg, GET_WM_COMMAND_ID(wParam, lParam));
  632.          return TRUE;
  633.       }
  634.       break;
  635.    }
  636.  
  637.    return DlgProcFilter(hDlg, msg, wParam, lParam);
  638. }
  639.  
  640.  
  641. /* StmtDlgProc -------------------------------------------------------------
  642.    Description: Get SQL statement to execute
  643.    --------------------------------------------------------------------------*/
  644. BOOL EXPFUNC StmtDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  645. {
  646.    LPCHILD  lpChild;
  647.  
  648.    lpChild = (LPCHILD)GetWindowLong(hDlg, USERDATA);
  649.  
  650.    switch (msg) {
  651.      case WM_INITDIALOG:
  652.       CenterDialog(hDlg);
  653.  
  654.       lpChild = (LPCHILD)lParam;
  655.       SetWindowLong(hDlg, USERDATA, (LONG)lpChild);
  656.  
  657.       SetWindowText(GetDlgItem(hDlg, IDC_EDIT1), lpChild->sql);
  658.       SendDlgItemMessage(hDlg, IDC_EDIT1, EM_LIMITTEXT, cbMAXSQL-1, 0L);
  659.       return TRUE;
  660.  
  661.      case WM_COMMAND:
  662.       switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  663.         case IDOK:
  664.          GetWindowText(GetDlgItem(hDlg, IDC_EDIT1),
  665.                        lpChild->sql, cbMAXSQL);
  666.  
  667.          lpChild->dwOperation = OPER_SELECT;
  668.  
  669.  
  670.         case IDCANCEL:
  671.          EndDialog(hDlg, wParam);
  672.          return TRUE;
  673.       }
  674.       break;
  675.    }
  676.  
  677.    return DlgProcFilter(hDlg, msg, wParam, lParam);
  678. }
  679.  
  680.  
  681. /* UpdateDlgProc -----------------------------------------------------------
  682.    Description: Get new values with which to update the current row
  683.    --------------------------------------------------------------------------*/
  684. BOOL EXPFUNC UpdateDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  685. {
  686.    LPCHILD  lpChild;
  687.  
  688.    lpChild = (LPCHILD)GetWindowLong(hDlg, USERDATA);
  689.  
  690.    switch (msg) {
  691.  
  692.       // Build dialog dynamically, adding appropriate edit controls
  693.      case WM_INITDIALOG:
  694.       lpChild = (LPCHILD)lParam;
  695.  
  696.       SetWindowLong(hDlg, USERDATA, (LONG)lpChild);
  697.       AddEditControls(hDlg, lpChild);
  698.       SendDlgItemMessage(hDlg,edt1,EM_SETSEL,GET_EM_SETSEL_MPS(0, -1));
  699.  
  700.       CenterDialog(hDlg);
  701.       SetFocus(GetDlgItem(hDlg, edt1));
  702.       return FALSE;
  703.  
  704.       // Close dialog updating row-set buffer (if OK) with new values
  705.      case WM_COMMAND:
  706.       switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  707.         case IDOK:
  708.          if (!GetEditControls(hDlg, lpChild))
  709.             GET_WM_COMMAND_ID(wParam, lParam) = IDCANCEL;
  710.  
  711.         case IDCANCEL:
  712.          EndDialog(hDlg, GET_WM_COMMAND_ID(wParam, lParam));
  713.          return TRUE;
  714.       }
  715.       break;
  716.    }
  717.  
  718.    return DlgProcFilter(hDlg, msg, wParam, lParam);
  719. }
  720.  
  721.  
  722. /* FindDlgProc -------------------------------------------------------------
  723.    Description: Get text string to find in result set
  724.    --------------------------------------------------------------------------*/
  725. BOOL EXPFUNC FindDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  726. {
  727.    LPCHILD  lpChild;
  728.  
  729.    lpChild = (LPCHILD)GetWindowLong(hDlg, USERDATA);
  730.  
  731.    switch (msg) {
  732.      case WM_INITDIALOG:
  733.       CenterDialog(hDlg);
  734.  
  735.       lpChild = (LPCHILD)lParam;
  736.       SetWindowLong(hDlg, USERDATA, (LONG)lpChild);
  737.  
  738.       SetWindowText(GetDlgItem(hDlg, IDC_EDIT1), lpChild->sql);
  739.       SendDlgItemMessage(hDlg, IDC_EDIT1, EM_LIMITTEXT, cbMAXSQL-1, 0L);
  740.       return TRUE;
  741.  
  742.      case WM_COMMAND:
  743.       switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  744.         case IDOK:
  745.          GetWindowText(GetDlgItem(hDlg, IDC_EDIT1),
  746.                        lpChild->sql, cbMAXSQL);
  747.  
  748.         case IDCANCEL:
  749.          EndDialog(hDlg, wParam);
  750.          return TRUE;
  751.       }
  752.       break;
  753.    }
  754.  
  755.    return DlgProcFilter(hDlg, msg, wParam, lParam);
  756. }
  757.  
  758. /*---------------------------------------------------------------------------
  759. ** SQLTablesDlgProc -- get information for SQLTables and similar functions
  760. ----------------------------------------------------------------------------*/
  761. BOOL EXPFUNC SQLTablesDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  762. {
  763.    LPCHILD  lpChild;
  764.  
  765.    lpChild = (LPCHILD)GetWindowLong(hDlg, USERDATA);
  766.  
  767.    switch (msg) {
  768.      case WM_INITDIALOG:
  769.       CenterDialog(hDlg);
  770.  
  771.       lpChild = (LPCHILD)lParam;
  772.       SetWindowLong(hDlg, USERDATA, (LONG)lpChild);
  773.  
  774.       // Set the default button
  775.       if (!(lpChild->dwGuiFlags & GUIF_TABLES_RADIO)) {
  776.          lpChild->dwOperation = IDC_TABLE_RAD_TABLE;
  777.          lpChild->dwRadioButton = IDC_TABLE_RAD_TABLE;
  778.       }
  779.  
  780.       // Set the dialog up
  781.  
  782.       ControlValue(  lpChild,
  783.                    hDlg,
  784.                    GetDlgItem(hDlg,lpChild->dwRadioButton),
  785.                    lpChild->dwRadioButton,
  786.                    ACT_INIT);
  787.  
  788.       ControlValue(  lpChild,
  789.                    hDlg,
  790.                    GetDlgItem(hDlg,lpChild->dwRadioButton),
  791.                    lpChild->dwRadioButton,
  792.                    ACT_TRIGGER);
  793.  
  794.       ControlValue(  lpChild,
  795.                    hDlg,
  796.                    GetDlgItem(hDlg,IDC_TABLEINFO_QUALIFIER),
  797.                    IDC_TABLEINFO_QUALIFIER,
  798.                    ACT_INIT);
  799.  
  800.       ControlValue(  lpChild,
  801.                    hDlg,
  802.                    GetDlgItem(hDlg,IDC_TABLEINFO_NAME),
  803.                    IDC_TABLEINFO_NAME,
  804.                    ACT_INIT);
  805.  
  806.       ControlValue(  lpChild,
  807.                    hDlg,
  808.                    GetDlgItem(hDlg,IDC_TABLEINFO_OWNER),
  809.                    IDC_TABLEINFO_OWNER,
  810.                    ACT_INIT);
  811.  
  812.       ControlValue(  lpChild,
  813.                    hDlg,
  814.                    GetDlgItem(hDlg,IDC_TABLEINFO_TYPE),
  815.                    IDC_TABLEINFO_TYPE,
  816.                    ACT_INIT);
  817.  
  818.       ControlValue(  lpChild,
  819.                    hDlg,
  820.                    GetDlgItem(hDlg,IDC_TABLEINFO_COLNAME),
  821.                    IDC_TABLEINFO_COLNAME,
  822.                    ACT_INIT);
  823.       return TRUE;
  824.  
  825.      case WM_COMMAND:
  826.       return (BOOL)HANDLE_WM_COMMAND(hDlg, wParam, lParam, ClassOnCommand);
  827.       break;
  828.  
  829.    }
  830.  
  831.    return DlgProcFilter(hDlg, msg, wParam, lParam);
  832.  
  833. }
  834.  
  835. /*---ClassCommand---------------------------------------------------------
  836.    Filters commands for dialogs.   Forwards those messages that we think
  837.    are interesting to a handler that processes the events.
  838. ---------------------------------------------------------------------------*/
  839.  
  840. VOID INTFUNC ClassOnCommand(HWND hWnd, int iId, HWND hWndCtl, UINT uNotify)
  841. {
  842.    LPCHILD  lpChild;
  843.  
  844.    lpChild = (LPCHILD)GetWindowLong(hWnd,USERDATA);
  845.  
  846.    if (!(lpChild))
  847.       return;
  848.  
  849.    switch (uNotify) {
  850.  
  851.      case   BN_CLICKED:       // button control selected
  852.      case   EN_UPDATE:        // edit box has been updated
  853.      case   LBN_SELCHANGE:       // listbox has gotten a message
  854.       ControlValue(lpChild, hWnd, hWndCtl, iId, ACT_TRIGGER);
  855.       break;
  856.  
  857.    }
  858. }
  859.  
  860.  
  861. /*
  862.  ** ControlValue -- Initialize a control's value from the child's state, or
  863.  **               set the child's state from the control.   All control-
  864.  **               specific logic should go here.
  865.  **
  866.  ** Parameters:
  867.  **      lpChild  -- child state
  868.  **      hDlg  --  id of the active dialog
  869.  **      hCtl  --  control's window
  870.  **      iId      --  control's id
  871.  **      iAction  -- Action to take -- ACT_INIT or ACT_TRIGGER
  872.  **
  873.  ** No return value
  874.  */
  875.  
  876. VOID INTFUNC ControlValue (LPCHILD     lpChild,
  877.                            HWND     hDlg,
  878.                            HWND     hCtl,
  879.                            int         iId,
  880.                            int         iAction)
  881. {
  882.    int      iLbSelection;
  883.    DWORD dwListData;
  884.    BOOL  fTemp;
  885.    UCHAR szBuffer[MAXNAME];
  886.  
  887.    const DIALOG_PAIR dpOptList[] = {
  888.       {"Binding",          IDD_BIND_OPTIONS},
  889.       {"General options",     IDD_GENERAL_OPTIONS},
  890.       {"Scrolling Options",   IDD_SCROLLING_OPTIONS},
  891.       {"Concurrency Options", IDD_CONCURRENCY_OPTIONS}};
  892.  
  893.    switch (iId) {
  894.  
  895.      case   IDOK:                   // generic OK
  896.      case   IDCANCEL:                  // generic CANCEL
  897.       if (iAction == ACT_TRIGGER) {
  898.          if (g_hwndChildDialog) {
  899.             g_hwndChildDialog = NULL;
  900.          }
  901.          EndDialog(hDlg, iId);
  902.       }
  903.       break;
  904.  
  905.      case IDC_RADIO_BINDROW:
  906.      case IDC_RADIO_BINDCOL:
  907.       if (SetOrGetCheck(hCtl, iAction, (iId == lpChild->fBindByRow))) {
  908.          lpChild->fBindByRow = iId;
  909.       }
  910.       break;
  911.  
  912.      case IDC_RADIO_READONLY:
  913.       if (SetOrGetCheck(hCtl, iAction,
  914.                         (lpChild->fConcurrency == SQL_CONCUR_READ_ONLY))) {
  915.          lpChild->fConcurrency = SQL_CONCUR_READ_ONLY;
  916.       }
  917.       break;
  918.      case IDC_RADIO_LOCKING:
  919.       if (SetOrGetCheck(hCtl, iAction,
  920.                         (lpChild->fConcurrency == SQL_CONCUR_LOCK))) {
  921.          lpChild->fConcurrency = SQL_CONCUR_LOCK;
  922.       }
  923.       break;
  924.      case IDC_RADIO_OPTIMISTIC:
  925.       if (SetOrGetCheck(hCtl, iAction,
  926.                         (lpChild->fConcurrency == SQL_CONCUR_ROWVER))) {
  927.          lpChild->fConcurrency = SQL_CONCUR_ROWVER;
  928.       }
  929.       break;
  930.      case IDC_RADIO_OPTIMVALUE:
  931.       if (SetOrGetCheck(hCtl, iAction,
  932.                         (lpChild->fConcurrency == SQL_CONCUR_VALUES))) {
  933.          lpChild->fConcurrency = SQL_CONCUR_VALUES;
  934.       }
  935.       break;
  936.  
  937.      case IDC_RADIO_FORWARD:
  938.       if (SetOrGetCheck(hCtl, iAction,
  939.                         (lpChild->crowKeyset == SQL_CURSOR_FORWARD_ONLY))) {
  940.          lpChild->crowKeyset = SQL_CURSOR_FORWARD_ONLY;
  941.       }
  942.       break;
  943.      case IDC_RADIO_SNAPSHOT:
  944.       if (SetOrGetCheck(hCtl, iAction,
  945.                         (lpChild->crowKeyset == SQL_CURSOR_STATIC))) {
  946.          lpChild->crowKeyset = SQL_CURSOR_STATIC;
  947.       }
  948.       break;
  949.      case IDC_RADIO_KEYSET:
  950.       if (SetOrGetCheck(hCtl, iAction,
  951.                         (lpChild->crowKeyset == SQL_CURSOR_KEYSET_DRIVEN))) {
  952.          lpChild->crowKeyset = SQL_CURSOR_KEYSET_DRIVEN;
  953.       }
  954.       break;
  955.      case IDC_RADIO_DYNAMIC:
  956.       if (SetOrGetCheck(hCtl, iAction,
  957.                         (lpChild->crowKeyset == SQL_CURSOR_DYNAMIC))) {
  958.          lpChild->crowKeyset = SQL_CURSOR_DYNAMIC;
  959.       }
  960.       break;
  961.  
  962.      case IDC_CHECK_BINDALL:
  963.       fTemp = SetOrGetCheck(hCtl,iAction, (lpChild->fBindAll));
  964.       lpChild->fBindAll = fTemp;
  965.       Edit_Enable(GetDlgItem(hDlg,IDC_EDIT_BIND), !(fTemp));
  966.       Static_Enable(GetDlgItem(hDlg, IDC_STATIC_NBIND), !(fTemp));
  967.       break;
  968.  
  969.      case IDC_EDIT_BIND:
  970.       if (lpChild->fBind)
  971.          wsprintf((LPSTR)szBuffer,"%s", lpChild->szBind);
  972.       else  wsprintf((LPSTR)szBuffer,"%u", lpChild->cBind);
  973.       SetOrGetEditArray(hCtl, szBuffer, iAction);
  974.       if (iAction == ACT_TRIGGER) {
  975.          lpChild->fBind = TRUE;
  976.          strncpy(lpChild->szBind, szBuffer, cbINTLEN);
  977.          lpChild->szBind[cbINTLEN-1] = '\0';
  978.       }
  979.       break;
  980.  
  981.      case IDC_EDIT_ROWSETSIZE:
  982.       if (lpChild->fRowset)
  983.          wsprintf((LPSTR)szBuffer,"%s", lpChild->szRowset);
  984.       else wsprintf((LPSTR)szBuffer,"%u", lpChild->crowRowset);
  985.       SetOrGetEditArray(hCtl, szBuffer, iAction);
  986.       if (iAction == ACT_TRIGGER) {
  987.          lpChild->fRowset = TRUE;
  988.          strncpy(lpChild->szRowset, szBuffer, cbINTLEN);
  989.          lpChild->szRowset[cbINTLEN-1] = '\0';
  990.       }
  991.       break;
  992.  
  993.      case IDC_MAXCOL:
  994.       if (lpChild->fMaxBind)
  995.          wsprintf((LPSTR)szBuffer, "%s", lpChild->szMaxBind);
  996.       else wsprintf((LPSTR)szBuffer, "%ld", lpChild->crowMaxBind);
  997.       SetOrGetEditArray(hCtl, szBuffer, iAction);
  998.       if (iAction == ACT_TRIGGER) {
  999.          lpChild->fMaxBind = TRUE;
  1000.          strncpy(lpChild->szMaxBind, szBuffer, cbINTLEN);
  1001.          lpChild->szMaxBind[cbINTLEN-1] = '\0';
  1002.       }
  1003.       break;
  1004.  
  1005.      case IDC_TABLE_RAD_STATISTICS:       // TABLEINFO->STATSTICS
  1006.      case IDC_TABLE_RAD_COLUMN:           // TABLEINFO->COLUMNS
  1007.      case IDC_TABLE_RAD_PRIV:          // TABLEINFO->PRIVILEGES
  1008.      case IDC_TABLE_RAD_PROC:          // TABLEINFO->PROCEDURES
  1009.      case IDC_TABLE_RAD_TABLE:            // TABLEINFO->TABLES
  1010.  
  1011.       // Initialize the button, or set iAction to its value
  1012.       // Hide any fields not related to the button, show fields related
  1013.  
  1014.       if( SetOrGetCheck(hCtl, iAction,
  1015.                         (iId == (int)lpChild->dwRadioButton)) )
  1016.          lpChild->dwOperation = (UWORD) iId;
  1017.  
  1018.       if (iAction == ACT_TRIGGER) {
  1019.          lpChild->dwGuiFlags |= GUIF_TABLES_RADIO;
  1020.          lpChild->dwRadioButton = iId;
  1021.          (void) SetHiddenFields(hDlg, iId);
  1022.       }
  1023.       break;
  1024.  
  1025.      case IDC_CHECK_FETCH:
  1026.       if (SetOrGetCheck(hCtl, iAction, (int)IS_ALLWFETCH(lpChild)))
  1027.          lpChild->dwGuiFlags |= GUIF_ALWAYSFETCH;
  1028.       else
  1029.          lpChild->dwGuiFlags &= ~GUIF_ALWAYSFETCH;
  1030.  
  1031.       break;
  1032.  
  1033.      case IDC_CHECK_ASYNC:
  1034.       lpChild->fAsync = SetOrGetCheck(hCtl,iAction,lpChild->fAsync);
  1035.       break;
  1036.  
  1037.      case IDC_TABLEINFO_QUALIFIER:        // TABLEINFO->QUALIFIER
  1038.       SetOrGetEditArray(hCtl, lpChild->szQualifier, iAction);
  1039.       break;
  1040.  
  1041.      case IDC_TABLEINFO_NAME:          // TABLEINFO->NAME
  1042.       SetOrGetEditArray(hCtl, lpChild->szTable, iAction);
  1043.       break;
  1044.  
  1045.      case IDC_TABLEINFO_OWNER:            // TABLEINFO->OWNER
  1046.       SetOrGetEditArray(hCtl, lpChild->szUser, iAction);
  1047.       break;
  1048.  
  1049.      case IDC_TABLEINFO_TYPE:          // TABLEINFO->TYPE
  1050.       SetOrGetEditArray(hCtl, lpChild->szType, iAction);
  1051.       break;
  1052.  
  1053.      case IDC_TABLEINFO_COLNAME:          // TABLEINFO->COLUMN NAME
  1054.       SetOrGetEditArray(hCtl, lpChild->szColName, iAction);
  1055.       break;
  1056.  
  1057.      case IDC_OPTIONLIST:              // OPTIONS->options
  1058.       {
  1059.  
  1060.          if (iAction == ACT_INIT) {
  1061.             InitializeListBox(hDlg,
  1062.                               IDC_OPTIONLIST,
  1063.                               &dpOptList[0],
  1064.                               sizeof(dpOptList) / sizeof(DIALOG_PAIR),
  1065.                               IDD_GENERAL_OPTIONS);
  1066.          }
  1067.  
  1068.          // Get the title and data for the currently-selected list box
  1069.  
  1070.          iLbSelection = ListBox_GetCurSel(hCtl);
  1071.          dwListData   = ListBox_GetItemData(hCtl, iLbSelection);
  1072.  
  1073.          SendMessage(hDlg,WMU_NEWOPTION, iLbSelection,(LPARAM)dwListData);
  1074.          SendMessage(hDlg,WMU_SETSUBTEXT,iId, 0);
  1075.  
  1076.          break;
  1077.       }
  1078.  
  1079.    }
  1080. }
  1081.  
  1082. /*
  1083. ** SetOrGetCheck      -- set a value based upon a button action, or set a
  1084. **                 check button if the action is equal to a value
  1085. **                 Also used for radios
  1086. **
  1087. ** Parameters:
  1088. **    hCtl     -- control handle
  1089. **    iAction     -- ACT_INIT or ACT_TRIGGER
  1090. **    bEqual      -- Initialization -- should value be set?
  1091. **
  1092. ** Returns:
  1093. **    TRUE if checkbox is now set
  1094. */
  1095. INLINE BOOL SetOrGetCheck(
  1096.                           HWND   hCtl,
  1097.                           int    iAction,
  1098.                           BOOL   bEqual)
  1099. {
  1100.    if (iAction == ACT_INIT) {
  1101.       Button_SetCheck(hCtl, bEqual);
  1102.       return bEqual;
  1103.    }
  1104.  
  1105.    if (iAction == ACT_TRIGGER) {
  1106.       Button_SetCheck(hCtl, Button_GetCheck(hCtl));
  1107.       return Button_GetCheck(hCtl);
  1108.    }
  1109.  
  1110.    return FALSE;
  1111. }
  1112.  
  1113.  
  1114. /*
  1115. ** SetOrGetEditArray -- set the value of an array from an edit control, or
  1116. **                set the edit control from the array  (inline)
  1117. **
  1118. ** Parameters:
  1119. **    hCtl  -- control
  1120. **    lpStr -- string
  1121. **    iAction  -- ACT_INIT or ACT_TRIGGER
  1122. **
  1123. ** Notes:   Assumes lpStr is MAXNAME bytes long
  1124. */
  1125. INLINE VOID SetOrGetEditArray(
  1126.                               HWND  hCtl,
  1127.                               UCHAR FAR *lpStr,
  1128.                               int      iAction)
  1129. {
  1130.    if (iAction == ACT_INIT)
  1131.       Edit_SetText(hCtl, (LPSTR)lpStr);
  1132.    else
  1133.       if (iAction == ACT_TRIGGER)
  1134.          Edit_GetText(hCtl, (LPSTR)lpStr, MAXNAME - 1);
  1135. }
  1136.  
  1137. /*
  1138. ** SetHiddenFields -- show or hide hidden fields in a dialog box, depending
  1139. **               upon the action taken.
  1140. **
  1141. ** Parameters:
  1142. **    hDlg  -- dialog we are dealing with
  1143. **    iAct  -- action
  1144. **
  1145. */
  1146. BOOL    INTFUNC SetHiddenFields(
  1147.                                 HWND   hWnd,
  1148.                                 int    iAct)
  1149. {
  1150.    HWND  hTTag, hCol;
  1151.    HWND  hType, hCTag;
  1152.  
  1153.    // Get handles for all of the windows we want to deal with
  1154.  
  1155.    hTTag = GetDlgItem(hWnd, IDC_TYPETAG);
  1156.    hCol  = GetDlgItem(hWnd, IDC_COLTAG);
  1157.  
  1158.    hType = GetDlgItem(hWnd, IDC_TABLEINFO_TYPE);
  1159.    hCTag = GetDlgItem(hWnd, IDC_TABLEINFO_COLNAME);
  1160.  
  1161.    if (hType) {
  1162.       Edit_Enable(hType, (iAct == IDC_TABLE_RAD_TABLE)  ? 1 : 0);
  1163.       ShowWindow(hType,  (iAct == IDC_TABLE_RAD_TABLE)  ? SW_SHOW : SW_HIDE);
  1164.       ShowWindow(hTTag,  (iAct == IDC_TABLE_RAD_TABLE)  ? SW_SHOW : SW_HIDE);
  1165.  
  1166.       Edit_Enable(hCTag, (iAct == IDC_TABLE_RAD_COLUMN) ? 1 : 0);
  1167.       ShowWindow(hCol,   (iAct == IDC_TABLE_RAD_COLUMN) ? SW_SHOW : SW_HIDE);
  1168.       ShowWindow(hCTag,  (iAct == IDC_TABLE_RAD_COLUMN) ? SW_SHOW : SW_HIDE);
  1169.  
  1170.       return TRUE;
  1171.    }
  1172.  
  1173.    return FALSE;
  1174. }
  1175.  
  1176. /*
  1177.  **   InitializeListBox -- initialize a listbox from a DIALOG_PAIR
  1178.  **                     structure.
  1179.  **
  1180.  **  Parameters:
  1181.  **      hWnd     --  window the list box lives in
  1182.  **      lbId     --  resource id of the list box
  1183.  **      dpOptList   --  pointer to option list structure
  1184.  **      iEntries --  number of entries in the list box
  1185.  **      iDefId      --  default to select
  1186.  **
  1187.  **
  1188.  **  Returns:  FALSE
  1189.  **
  1190.  */
  1191.  
  1192. BOOL INTFUNC InitializeListBox(
  1193.    HWND                    hWnd,
  1194.    int                     lbId,
  1195.    const DIALOG_PAIR FAR   *dpOptList  ,
  1196.    int                     iEntries,
  1197.    int                     iDefId)
  1198. {
  1199.  
  1200.    int            iDlg, iIndex;
  1201.    HWND        hOptionBox;
  1202.    LPSTR       szDefaultTitle;
  1203.    hOptionBox  =  GetDlgItem(hWnd, lbId);
  1204.  
  1205.  
  1206.    for (iDlg = 0; iDlg < iEntries; iDlg++) {
  1207.       iIndex = ListBox_AddString(hOptionBox,
  1208.                                  dpOptList[iDlg].szDlgPairTitle);
  1209.  
  1210.       ListBox_SetItemData(hOptionBox,
  1211.                           iIndex,
  1212.                           dpOptList[iDlg].iDlgPairDlgId);
  1213.  
  1214.  
  1215.       if (iDefId == dpOptList[iDlg].iDlgPairDlgId) {
  1216.          szDefaultTitle = dpOptList[iDlg].szDlgPairTitle;
  1217.       }
  1218.  
  1219.    }
  1220.  
  1221.    ListBox_SetCurSel(hOptionBox,
  1222.                      ListBox_FindStringExact(hOptionBox, 0, szDefaultTitle));
  1223.  
  1224.    return FALSE;
  1225. }
  1226.  
  1227. /*
  1228. ** InitializeDialogControls   -- Initialize all of the controls in a dialog
  1229. **                      from the lpchild structure.   Callback function.
  1230. **
  1231. ** Parameters:
  1232. **    hDlg     -- dialog handle
  1233. **    lpChild     -- state structure
  1234. **
  1235. */
  1236.  
  1237. VOID INTFUNC InitializeDialogControls(
  1238.                                       HWND   hDlg,
  1239.                                       LPCHILD   lpChild)
  1240. {
  1241.    FARPROC     ControlInstance = MakeProcInstance((FARPROC)InitControlCallback,
  1242.                                                   g_hinst);
  1243.  
  1244.    EnumChildWindows(hDlg, (WNDENUMPROC)ControlInstance, (LPARAM)lpChild);
  1245.    FreeProcInstance(ControlInstance);
  1246.  
  1247. }
  1248.  
  1249.  
  1250.  
  1251. /*
  1252. ** InitControlCallback  -- callback function for initializing controls
  1253. **
  1254. ** Parameters:
  1255. **    hwndChild   -- child window handle
  1256. **    lParam      -- lparam (lpChild from EnumChildProc
  1257. */
  1258.  
  1259. BOOL CALLBACK InitControlCallback(
  1260.                                   HWND hwndChild,
  1261.                                   LPARAM  lParam)
  1262. {
  1263.    int      iControl= GetDlgCtrlID(hwndChild);
  1264.  
  1265.    if (iControl) {
  1266.       ControlValue((LPCHILD) lParam,
  1267.                    GetParent(hwndChild),
  1268.                    hwndChild,
  1269.                    iControl,
  1270.                    ACT_INIT);
  1271.  
  1272.    }
  1273.    return TRUE;
  1274. }
  1275.  
  1276.  
  1277.  
  1278. BOOL INTFUNC DlgProcFilter(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  1279. {
  1280.  
  1281.    switch (msg) {
  1282.      case WM_SETTEXT:
  1283.      case WM_NCPAINT:
  1284.      case WM_NCACTIVATE:
  1285.       SetWindowLong(hDlg, DWL_MSGRESULT,0L);
  1286.       return TRUE;
  1287.    }
  1288.    return FALSE;
  1289. }
  1290.  
  1291. /*
  1292. ** AlignToControl -- align a window to a control in a dialog
  1293. **
  1294. ** Parameters:
  1295. **    hWnd  -- window to align
  1296. **    hParent -- parent dialog
  1297. **    iCtlId   -- control Id
  1298. **
  1299. ** Returns: BOOL that moveWindow returns
  1300. */
  1301.  
  1302. BOOL INTFUNC AlignToControl(
  1303.                             HWND hWnd,
  1304.                             HWND hParent,
  1305.                             int     iCtlId)
  1306. {
  1307.    HWND  hwndDrawArea;
  1308.    RECT  rcDrawArea, rcChildWnd;
  1309.    POINT ptPoint;
  1310.  
  1311.  
  1312.    hwndDrawArea = GetDlgItem(hParent, iCtlId);
  1313.    GetWindowRect(hwndDrawArea, &rcDrawArea);
  1314.    GetWindowRect(hWnd, &rcChildWnd);
  1315.  
  1316.    ptPoint.x = rcDrawArea.left;
  1317.    ptPoint.y = rcDrawArea.top;
  1318.  
  1319.    ScreenToClient(hWnd, &ptPoint);
  1320.  
  1321.    return (MoveWindow(  hWnd,
  1322.                       ptPoint.x,
  1323.                       ptPoint.y,
  1324.                       rcChildWnd.right- rcChildWnd.left,
  1325.                       rcChildWnd.bottom - rcChildWnd.top,
  1326.                       FALSE));
  1327. }
  1328.