home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Internet Business Development Kit / PRODUCT_CD.iso / sqlsvr / esqlc / esql / samples.c / genwin.sqc < prev    next >
Encoding:
Text File  |  1995-11-21  |  21.7 KB  |  747 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  FILE: genwin.sqc
  4. //              
  5. //      Generic Embedded SQL for C Win16/Win32 program
  6. //
  7. //  FUNCTIONS:
  8. //
  9. //      WinMain() - Main program and message loop
  10. //      MainWndProc() - Main window procedure
  11. //      ConnectToSQLServer() - Connect to SQL Server using CONNECT TO
  12. //      QuerySQLServer() - Query a table in SQL Server
  13. //      ConnectDlgProc() - Connect box dialog procedure
  14. //      QueryDlgProc() - Query box dialog procedure
  15. //      AboutDlgProc() - About box dialog procedure
  16. //      ErrorHandler() - Embedded SQL for C error handler
  17. //
  18. //  COMMENTS:
  19. //
  20. //      Copyright (C) 1992 - 1994 Microsoft Corporation
  21. //
  22. //////////////////////////////////////////////////////////////////////////////
  23.  
  24. #define STRICT
  25. #define WIN32_LEAN_AND_MEAN  //excludes unused windows.h headers
  26. #include <windows.h>                // standard Windows include file
  27. #include <windowsx.h>               // extended Windows include file
  28. #include "gwutil.h"                 // utility header
  29. #include "genwin.h"                 // specific to this program
  30.  
  31. // GLOBAL VARIABLES
  32. char szAppName[] = "GenWin";        // application name
  33. HINSTANCE hinstMain;                // current instance
  34. HWND hwndMain;                      // main window handle
  35. HWND hwndEdit;                      // edit control handle
  36.  
  37. char szLogin[SQLID_MAX+1] = "";     // SQL Server login ID
  38. char szPassword[SQLID_MAX+1] = "";  // SQL Server password
  39. char szServer[SQLID_MAX+1] = "";    // SQL Server name
  40. char szDatabase[SQLID_MAX+1] = "";  // SQL Server database to use
  41. BOOL bConnected = FALSE;            // are we connected to SQL Server?
  42.  
  43. EXEC SQL BEGIN DECLARE SECTION;
  44. char szLastName[50] = "";           // author's last name
  45. EXEC SQL END DECLARE SECTION;
  46.  
  47. //////////////////////////////////////////////////////////////////////////////
  48. //
  49. //  FUNCTION: WinMain()
  50. //
  51. //      Creates class and window, message processing loop
  52. //
  53. //  PARAMETERS:
  54. //
  55. //      hinst - handle of current instance
  56. //      hinstPrev - handle of previous instance
  57. //      lpstrCmdLine - command line string
  58. //      nCmdShow - show window type
  59. //
  60. //  RETURNS: the value from PostQuitMessage()
  61. //
  62. //  COMMENTS:
  63. //
  64. //////////////////////////////////////////////////////////////////////////////
  65.  
  66. int WINAPI WinMain (
  67.     HINSTANCE hinst,
  68.     HINSTANCE hinstPrev,
  69.     LPSTR lpstrCmdLine,
  70.     int nCmdShow)
  71. {
  72.     MSG msg;                    // message
  73.     WNDCLASS wcMain;            // windows class
  74.     HFONT hfontFixed;           // fixed font
  75.     char chOpt;                 // gotten option character
  76.     char* pszParam;             // gotten parameter
  77.     char szScratch[200] = "";   // scratch area for wsprintf()
  78.  
  79.     BOOL bLogin = FALSE,        // bools for tracking options
  80.         bPassword = FALSE,
  81.         bServer = FALSE,
  82.         bDatabase = FALSE;
  83.  
  84.     // install Embedded SQL for C error handler
  85.     EXEC SQL WHENEVER SQLERROR CALL ErrorHandler();
  86.     // set Embedded SQL for C options
  87.     EXEC SQL SET OPTION LOGINTIME 10;
  88.     EXEC SQL SET OPTION QUERYTIME 100;
  89.     
  90.     // Save the instance handle in global variable
  91.     hinstMain = hinst;
  92.  
  93.     if (!hinstPrev)
  94.     {
  95.         // Fill in window class structure
  96.         wcMain.style = 0;                       // class style(s)
  97.         wcMain.lpfnWndProc = (WNDPROC) MainWndProc;             // window procedure
  98.         wcMain.cbClsExtra = 0;                  // no per-class extra data
  99.         wcMain.cbWndExtra = 0;                  // no per-window extra data
  100.         wcMain.hInstance = hinst;               // app that owns this class
  101.         wcMain.hIcon = LoadIcon(hinst, "AppIcon");             // icon from .RC file
  102.         wcMain.hCursor = LoadCursor(NULL, IDC_ARROW);          // arrow cursor
  103.         wcMain.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);    // white background
  104.         wcMain.lpszMenuName = "AppMenu";        // menu from .RC file
  105.         wcMain.lpszClassName = szAppName;       // name used in call to CreateWindow
  106.  
  107.         // Register the window class
  108.         if (!RegisterClass(&wcMain))
  109.             return (FALSE);
  110.     }
  111.  
  112.     // Create a main window for this application instance
  113.     hwndMain = CreateWindow(szAppName,  // class name
  114.         "GenWin",                       // window name
  115.         WS_OVERLAPPEDWINDOW,            // window style(s)
  116.         CW_USEDEFAULT,                  // init horizontal position
  117.         CW_USEDEFAULT,                  // init vertical position
  118.         CW_USEDEFAULT,                  // init width
  119.         CW_USEDEFAULT,                  // init height
  120.         NULL,                           // parent window handle
  121.         NULL,                           // menu or child window ID
  122.         hinst,                          // instance
  123.         NULL);                          // used for MDI windows only
  124.  
  125.     // If main window could not be created, return failure
  126.     if (!hwndMain)
  127.         return (FALSE);
  128.  
  129.     // Create edit window
  130.     hwndEdit = CreateWindow("edit",
  131.         NULL,
  132.         WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
  133.             ES_LEFT | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
  134.         0, 0, 0, 0,         // initial dimensions all 0
  135.         hwndMain,           // parent handle
  136.         (HMENU)IDE_EDIT,    // unique child-window identifier
  137.         hinst,              // instance  handle
  138.         NULL);
  139.  
  140.     // If edit window could not be created, return failure
  141.     if (!hwndEdit)
  142.         return (FALSE);
  143.         
  144.     // get fixed font for edit control
  145.     hfontFixed = GetStockObject(ANSI_FIXED_FONT);
  146.     SendMessage(hwndEdit,
  147.         WM_SETFONT,
  148.         (WPARAM)hfontFixed,
  149.         FALSE);
  150.  
  151.     SetWindowText(hwndEdit, "");
  152.     
  153.     // display logo
  154.     PrintLine(hwndEdit,"Generic Embedded SQL for C Win16/Win32 application");
  155.     
  156.     // get options and parameters
  157.     while (TRUE)
  158.     {
  159.         // all these command-line options are valid
  160.         //     {/s|/S} [sql_server]
  161.         //     {/u|/U} login_id
  162.         //     {/p|/P} [password]
  163.         //     {/d|/D} [database]
  164.  
  165.         chOpt = GetOption(__argc, __argv, "u:U:p:P:s:S:d:D:", &pszParam);
  166.         if (chOpt > 1)
  167.         {
  168.             // chOpt is valid argument
  169.             switch (chOpt)
  170.             {
  171.             case 'u':   // login ID
  172.             case 'U':
  173.                 bLogin = TRUE;
  174.                 if (pszParam != NULL)
  175.                 {
  176.                     lstrcpy(szLogin, pszParam);
  177.                 }
  178.                 break;
  179.             case 'p':   // password
  180.             case 'P':
  181.                 bPassword = TRUE;
  182.                 if (pszParam != NULL)
  183.                 {
  184.                     lstrcpy(szPassword, pszParam);
  185.                 }
  186.                 break;
  187.             case 's':   // SQL Server
  188.             case 'S':
  189.                 bServer = TRUE;
  190.                 if (pszParam != NULL)
  191.                 {
  192.                     lstrcpy(szServer, pszParam);
  193.                 }
  194.                 break;
  195.             case 'd':   // database
  196.             case 'D':
  197.                 bDatabase = TRUE;
  198.                 if (pszParam != NULL)
  199.                 {
  200.                     lstrcpy(szDatabase, pszParam);
  201.                 }
  202.                 break;
  203.             }
  204.  
  205.         }
  206.         if (chOpt == 0)
  207.         {
  208.             // end of argument list
  209.             break;
  210.         }
  211.         if ((chOpt == 1) || (chOpt == -1))
  212.         {
  213.             // standalone param or error
  214.             wsprintf(szScratch, "ERROR: Argument '%s' not recognized", (LPSTR)pszParam);
  215.             PrintLine(hwndEdit, szScratch);
  216.             break;
  217.         }
  218.     }
  219.  
  220.     if ((chOpt == 1) || (chOpt == -1))
  221.     {
  222.         // error
  223.     }
  224.  
  225.     ShowWindow(hwndMain, nCmdShow);     // Show the window
  226.     UpdateWindow(hwndMain);             // Sends WM_PAINT message
  227.  
  228.     if (bServer && bLogin && bPassword && bDatabase)
  229.     {
  230.         // all command-line options specified, so attempt connection
  231.         PostMessage(hwndMain, WM_CONNECTTOSQLSERVER, 0, 0);
  232.     }
  233.     else
  234.     {
  235.         // prompt for unspecified options
  236.         Post_WM_COMMAND(hwndMain,
  237.             IDM_FILE_CONNECT,
  238.             0,
  239.             0);
  240.     }
  241.  
  242.     // Acquire and dispatch messages until a WM_QUIT message is received
  243.     while (GetMessage(&msg,         // message structure
  244.         NULL,                       // handle of window receiving the message
  245.         0,                          // lowest message to examine
  246.         0))                         // highest message to examine
  247.     {
  248.         TranslateMessage(&msg);     // translate virtual key codes
  249.         DispatchMessage(&msg);      // dispatch message to window
  250.     }
  251.     return (msg.wParam);        // Returns the value from PostQuitMessage
  252. }
  253.  
  254. //////////////////////////////////////////////////////////////////////////////
  255. //
  256. //  FUNCTION: MainWndProc()
  257. //
  258. //      Main window procedure, processes messages
  259. //
  260. //  MESSAGES:
  261. //
  262. //      WM_COMMAND              application menu command
  263. //      WM_CREATE               create window
  264. //      WM_DESTROY              destroy window
  265. //      WM_SETFOCUS             window got focus
  266. //      WM_SIZE                 window has been resized
  267. //      WM_DESTROY              window is being destroyed
  268. //      WM_CONNECTTOSQLSERVER   connect to SQL Server
  269. //      WM_QUERYSQLSERVER       query a table in SQL Server
  270. //
  271. //  COMMENTS:
  272. //
  273. //////////////////////////////////////////////////////////////////////////////
  274.  
  275. LRESULT CALLBACK MainWndProc (
  276.     HWND hwnd,
  277.     UINT msg,
  278.     WPARAM wParam,
  279.     LPARAM lParam)
  280. {
  281.     WORD cmdNotify, idItem;
  282.     HWND hwndControl;
  283.     DLGPROC lpDlgProc;
  284.     int nWidth, nHeight;    
  285.  
  286.     switch (msg)
  287.     {
  288.     case WM_COMMAND:    // message: command from application menu
  289.         
  290.         cmdNotify = GET_WM_COMMAND_NOTIFY(wParam, lParam);
  291.         idItem = GET_WM_COMMAND_ID(wParam, lParam);
  292.         hwndControl = GET_WM_COMMAND_HWND(wParam, lParam);
  293.  
  294.         switch (idItem)
  295.         {
  296.         case IDM_FILE_CONNECT:
  297.             lpDlgProc = (DLGPROC) MakeProcInstance((FARPROC)ConnectDlgProc, hinstMain);
  298.  
  299.             DialogBox(hinstMain,
  300.                 "ConnectBox",
  301.                 hwnd,
  302.                 lpDlgProc);
  303.  
  304.             FreeProcInstance((FARPROC)lpDlgProc);
  305.             break;
  306.  
  307.         case IDM_FILE_QUERY:
  308.             if (bConnected)
  309.             {
  310.                 lpDlgProc = (DLGPROC) MakeProcInstance((FARPROC)QueryDlgProc, hinstMain);
  311.  
  312.                 DialogBox(hinstMain,
  313.                     "QueryBox",
  314.                     hwnd,
  315.                     lpDlgProc);
  316.  
  317.                 FreeProcInstance((FARPROC)lpDlgProc);
  318.             }
  319.             else
  320.             {
  321.                 PrintLine(hwndEdit, "ERROR: Not connected to SQL Server");
  322.             }
  323.             break;
  324.  
  325.         case IDM_FILE_EXIT:
  326.             DestroyWindow(hwnd);
  327.             break;
  328.  
  329.         case IDM_HELP_ABOUT:
  330.             lpDlgProc = (DLGPROC) MakeProcInstance((FARPROC)AboutDlgProc, hinstMain);
  331.  
  332.             DialogBox(hinstMain,
  333.                 "AboutBox",
  334.                 hwnd,
  335.                 lpDlgProc);
  336.  
  337.             FreeProcInstance((FARPROC)lpDlgProc);
  338.             break;
  339.  
  340.         default:
  341.             // pass it on if unproccessed
  342.             return (DefWindowProc(hwnd, msg, wParam, lParam));
  343.             break;
  344.  
  345.         }
  346.         break; // case WM_COMMAND
  347.  
  348.     case WM_SETFOCUS:   // message: window focus
  349.         SetFocus(hwndEdit);
  350.         break; // case WM_SETFOCUS
  351.  
  352.     case WM_SIZE:       // message: window focus
  353.         nWidth = LOWORD(lParam);
  354.         nHeight = HIWORD(lParam);
  355.         MoveWindow(hwndEdit,    // window to move
  356.             0,                  // x coord
  357.             0,                  // y coord
  358.             nWidth,             // width
  359.             nHeight,            // height
  360.             TRUE);              // repaint
  361.         break; // case WM_SIZE
  362.  
  363.     case WM_DESTROY:    // message: window being destroyed
  364.         EXEC SQL DISCONNECT ALL;
  365.         PostQuitMessage (0);
  366.         break; // case WM_DESTORY
  367.  
  368.     case WM_CONNECTTOSQLSERVER:     // private message: connect to SQL Server
  369.         ConnectToSQLServer(szServer,
  370.             szLogin,
  371.             szPassword,
  372.             szDatabase);
  373.         break; // case WM_CONNECTTOSQLSERVER
  374.  
  375.     case WM_QUERYSQLSERVER:     // private message: query SQL Server
  376.         QuerySQLServer();
  377.         break; // case WM_CONNECTTOSQLSERVER
  378.  
  379.     default:
  380.         // pass it on if unproccessed
  381.         return (DefWindowProc(hwnd, msg, wParam, lParam));
  382.         break;
  383.     }
  384.     return (0);
  385. }
  386.  
  387. ///////////////////////////////////////////////////////////////////////////////
  388. //
  389. //  FUNCTION: ConnectToSQLServer()
  390. //
  391. //      Establish connection to SQL Server
  392. //
  393. //  PARAMETERS:
  394. //
  395. //      szServer - connect to this SQL Server 
  396. //      szLogin - login ID
  397. //      szPassword - password
  398. //      szDatabase - database to use
  399. //
  400. //  RETURNS: 0
  401. //
  402. //  COMMENTS:
  403. //
  404. ///////////////////////////////////////////////////////////////////////////////
  405.  
  406. BOOL ConnectToSQLServer (
  407.     LPSTR szServer,
  408.     LPSTR szLogin,
  409.     LPSTR szPassword,
  410.     LPSTR szDatabase)
  411. {
  412.     EXEC SQL BEGIN DECLARE SECTION;
  413.     // for CONNECT TO statement
  414.     char szConnectToServerDatabase[(SQLID_MAX * 2)+2] = "";
  415.     char szConnectToLoginPassword[(SQLID_MAX * 2)+2] = "";
  416.     EXEC SQL END DECLARE SECTION;
  417.  
  418.     // set defaults
  419.     if (lstrlen(szDatabase) == 0)
  420.     {
  421.         lstrcpy(szDatabase, "pubs");
  422.     }
  423.     
  424.     PrintLine(hwndEdit, "Using:");
  425.     PrintStr(hwndEdit, "    SQL Server: ");
  426.     PrintLine(hwndEdit, szServer);
  427.     PrintStr(hwndEdit, "    Database: ");
  428.     PrintLine(hwndEdit, szDatabase);
  429.     PrintStr(hwndEdit, "    Login ID: ");
  430.     PrintLine(hwndEdit, szLogin);
  431.     PrintStr(hwndEdit, "    Password: ");
  432.     PrintLine(hwndEdit, szPassword);
  433.  
  434.     // build host variables for CONNECT TO
  435.     if (lstrlen(szServer) != 0)
  436.     {
  437.         lstrcat(szConnectToServerDatabase, szServer);
  438.         lstrcat(szConnectToServerDatabase, ".");
  439.     }
  440.     if (lstrlen(szDatabase) != 0)
  441.     {
  442.         lstrcat(szConnectToServerDatabase, szDatabase);
  443.     }
  444.  
  445.     if (lstrlen(szLogin) != 0)
  446.     {
  447.         lstrcat(szConnectToLoginPassword, szLogin);
  448.     }
  449.     if (lstrlen(szPassword) != 0)
  450.     {
  451.         lstrcat(szConnectToLoginPassword, ".");
  452.         lstrcat(szConnectToLoginPassword, szPassword);
  453.     }
  454.  
  455.     // attempt connection to SQL Server
  456.     EXEC SQL CONNECT TO :szConnectToServerDatabase
  457.         USER :szConnectToLoginPassword;
  458.  
  459.     PrintStr(hwndEdit, "Connection to SQL Server '");
  460.     PrintStr(hwndEdit, szServer);
  461.     if (SQLCODE == 0)
  462.     {
  463.         bConnected = TRUE;
  464.         PrintLine(hwndEdit, "' established");
  465.         PrintLine(hwndEdit, "From the File menu choose Query to execute a query");
  466.         return (TRUE);
  467.     }
  468.     else
  469.     {
  470.         // problem connecting to SQL Server
  471.         bConnected = FALSE;
  472.         PrintLine(hwndEdit, "' failed");
  473.         return (FALSE);
  474.     }
  475. }
  476.  
  477. ///////////////////////////////////////////////////////////////////////////////
  478. //
  479. //  FUNCTION: QuerySQLServer()
  480. //
  481. //      Query SQL Server
  482. //
  483. //  PARAMETERS: none
  484. //
  485. //  RETURNS: 0
  486. //
  487. //  COMMENTS:
  488. //
  489. ///////////////////////////////////////////////////////////////////////////////
  490.  
  491. BOOL QuerySQLServer ()
  492. {
  493.     EXEC SQL BEGIN DECLARE SECTION;
  494.     char szFirstName[50] = "";
  495.     EXEC SQL END DECLARE SECTION;
  496.  
  497.     // display what user specified
  498.     PrintStr(hwndEdit, "Author's last name: ");
  499.     PrintLine(hwndEdit, szLastName);
  500.  
  501.     // query the authors table
  502.     EXEC SQL SELECT au_fname INTO :szFirstName
  503.         from authors where au_lname = :szLastName;
  504.  
  505.     if (SQLCODE == 0)
  506.     {
  507.         PrintStr(hwndEdit, "That author's first name is: ");
  508.         PrintLine(hwndEdit, szFirstName);
  509.         return (TRUE);
  510.     }
  511.     else
  512.     {
  513.         if (SQLCODE == 100)
  514.         {
  515.             // no rows match the given criteria
  516.             PrintLine(hwndEdit, "That author was not found");
  517.         }
  518.         else
  519.         {
  520.             // problem executing query
  521.             PrintLine(hwndEdit, "ERROR: Executing SELECT query");
  522.             return (FALSE);
  523.         }
  524.     }
  525. }
  526.  
  527. //////////////////////////////////////////////////////////////////////////////
  528. //
  529. //  FUNCTION: ConnectDlgProc()
  530. //
  531. //      Connect box dialog procedure
  532. //
  533. //  MESSAGES:
  534. //
  535. //      WM_INITDIALOG   init dialog
  536. //      WM_COMMAND      button command
  537. //
  538. //  COMMENTS:
  539. //
  540. //////////////////////////////////////////////////////////////////////////////
  541.  
  542. BOOL CALLBACK ConnectDlgProc (
  543.     HWND hwndDlg,
  544.     UINT msg,
  545.     WPARAM wParam,
  546.     LPARAM lParam)
  547. {
  548.     WORD cmdNotify, idItem;
  549.     HWND hwndControl;
  550.  
  551.     switch (msg)
  552.     {
  553.     case WM_INITDIALOG:     // message: initialize dialog box
  554.         SetDlgItemText(hwndDlg,
  555.             IDC_SERVER,
  556.             szServer);
  557.         SetDlgItemText(hwndDlg,
  558.             IDC_LOGIN,
  559.             szLogin);
  560.         SetDlgItemText(hwndDlg,
  561.             IDC_PASSWORD,
  562.             szPassword);
  563.         SetDlgItemText(hwndDlg,
  564.             IDC_DATABASE,
  565.             szDatabase);
  566.         return (TRUE);
  567.         break;
  568.  
  569.     case WM_COMMAND:        // message: received a command
  570.         
  571.         cmdNotify = GET_WM_COMMAND_NOTIFY(wParam, lParam);
  572.         idItem = GET_WM_COMMAND_ID(wParam, lParam);
  573.         hwndControl = GET_WM_COMMAND_HWND(wParam, lParam);
  574.  
  575.         switch (idItem)
  576.         {
  577.         case IDOK:
  578.             // get server name, login, and password
  579.             GetDlgItemText(hwndDlg,
  580.                 IDC_SERVER,
  581.                 szServer,
  582.                 SQLID_MAX);
  583.             GetDlgItemText(hwndDlg,
  584.                 IDC_LOGIN,
  585.                 szLogin,
  586.                 SQLID_MAX);
  587.             GetDlgItemText(hwndDlg,
  588.                 IDC_PASSWORD,
  589.                 szPassword,
  590.                 SQLID_MAX);
  591.             GetDlgItemText(hwndDlg,
  592.                 IDC_DATABASE,
  593.                 szDatabase,
  594.                 SQLID_MAX);
  595.  
  596.             PostMessage(hwndMain, WM_CONNECTTOSQLSERVER, 0, 0);            
  597.  
  598.             EndDialog(hwndDlg, TRUE);
  599.             return (TRUE);
  600.             break;
  601.         case IDCANCEL:
  602.             EndDialog(hwndDlg, TRUE);
  603.             return (TRUE);
  604.             break;
  605.         }
  606.         break;
  607.     }
  608.     return (FALSE);               // didn't process a message
  609. }
  610.  
  611. //////////////////////////////////////////////////////////////////////////////
  612. //
  613. //  FUNCTION: QueryDlgProc()
  614. //
  615. //      Query box dialog procedure
  616. //
  617. //  MESSAGES:
  618. //
  619. //      WM_INITDIALOG   init dialog
  620. //      WM_COMMAND      button command
  621. //
  622. //  COMMENTS:
  623. //
  624. //////////////////////////////////////////////////////////////////////////////
  625.  
  626. BOOL CALLBACK QueryDlgProc (
  627.     HWND hwndDlg,
  628.     UINT msg,
  629.     WPARAM wParam,
  630.     LPARAM lParam)
  631. {
  632.     WORD cmdNotify, idItem;
  633.     HWND hwndControl;
  634.  
  635.     switch (msg)
  636.     {
  637.     case WM_INITDIALOG:     // message: initialize dialog box
  638.         return (TRUE);
  639.         break;
  640.  
  641.     case WM_COMMAND:        // message: received a command
  642.         
  643.         cmdNotify = GET_WM_COMMAND_NOTIFY(wParam, lParam);
  644.         idItem = GET_WM_COMMAND_ID(wParam, lParam);
  645.         hwndControl = GET_WM_COMMAND_HWND(wParam, lParam);
  646.  
  647.         switch (idItem)
  648.         {
  649.         case IDOK:
  650.             // get author's last name for query
  651.             GetDlgItemText(hwndDlg,
  652.                 IDC_LASTNAME,
  653.                 szLastName,
  654.                 49);
  655.  
  656.             PostMessage(hwndMain, WM_QUERYSQLSERVER, 0, 0);            
  657.  
  658.             EndDialog(hwndDlg, TRUE);
  659.             return (TRUE);
  660.             break;
  661.         case IDCANCEL:
  662.             EndDialog(hwndDlg, TRUE);
  663.             return (TRUE);
  664.             break;
  665.         }
  666.         break;
  667.     }
  668.     return (FALSE);               // didn't process a message
  669. }
  670.  
  671. //////////////////////////////////////////////////////////////////////////////
  672. //
  673. //  FUNCTION: AboutDlgProc()
  674. //
  675. //      About box dialog procedure
  676. //
  677. //  MESSAGES:
  678. //
  679. //      WM_INITDIALOG   init dialog
  680. //      WM_COMMAND      button command
  681. //
  682. //  COMMENTS:
  683. //
  684. //////////////////////////////////////////////////////////////////////////////
  685.  
  686. BOOL CALLBACK AboutDlgProc (
  687.     HWND hwndDlg,
  688.     UINT msg,
  689.     WPARAM wParam,
  690.     LPARAM lParam)
  691. {
  692.     WORD cmdNotify, idItem;
  693.     HWND hwndControl;
  694.  
  695.     switch (msg)
  696.     {
  697.     case WM_INITDIALOG:     // message: initialize dialog box
  698.         SetDlgItemText(hwndDlg,
  699.             IDC_PLATFORM,
  700.             OS_STRING);
  701.         return (TRUE);
  702.         break;
  703.  
  704.     case WM_COMMAND:        // message: received a command
  705.         
  706.         cmdNotify = GET_WM_COMMAND_NOTIFY(wParam, lParam);
  707.         idItem = GET_WM_COMMAND_ID(wParam, lParam);
  708.         hwndControl = GET_WM_COMMAND_HWND(wParam, lParam);
  709.  
  710.         switch (idItem)
  711.         {
  712.         case IDOK:
  713.         case IDCANCEL:
  714.             EndDialog(hwndDlg, TRUE);
  715.             return (TRUE);
  716.             break;
  717.         }
  718.         break;
  719.     }
  720.     return (FALSE);               // didn't process a message
  721. }
  722.  
  723. ///////////////////////////////////////////////////////////////////////////////
  724. //
  725. //  FUNCTION: ErrorHandler()
  726. //
  727. //      Called on Embedded SQL for C error, displays fields from SQLCA
  728. //
  729. //  PARAMETERS: none
  730. //
  731. //  RETURNS: none
  732. //
  733. //  COMMENTS:
  734. //
  735. ///////////////////////////////////////////////////////////////////////////////
  736.  
  737. void ErrorHandler (void)
  738. {
  739.     char szScratch[200] = "";
  740.  
  741.     PrintLine(hwndEdit, "Error Handler called:");
  742.     wsprintf(szScratch, "    SQL Code = %li", SQLCODE);
  743.     PrintLine(hwndEdit, szScratch);
  744.     wsprintf(szScratch, "    SQL Server Message %li: '%s'", SQLERRD1, (LPSTR)SQLERRMC);
  745.     PrintLine(hwndEdit, szScratch);
  746. }
  747.