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