home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a025 / 11.ddi / SQLPM.C@ / SQLPM.bin
Encoding:
Text File  |  1992-09-15  |  22.2 KB  |  655 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: SqlPM.c
  4.          Copyright (C) 1988-1990 Microsoft Corp.
  5.  
  6.     PURPOSE: SqlPM sample Presentation Manager application
  7.  
  8.     FUNCTIONS:
  9.  
  10.     SqlPMInit() - initializes window data and registers window
  11.     SqlPMWndProc() - processes messages
  12.     AboutSQL() - processes messages for "About" dialog box
  13.     SelectSQL() - processes input of author name
  14.     ConnectSQL() - processes input of server name and connects to server
  15.  
  16.     COMMENTS:
  17.  
  18.     Windows can have several copies of your application running at the
  19.     same time.  The variable hInst keeps track of which instance this
  20.     application is so that processing will be to the correct window.
  21.  
  22.     You only need to initialize the application once.  After it is
  23.     initialized, all other copies of the application will use the same
  24.     window class, and do not need to be separately initialized.
  25.  
  26. ****************************************************************************/
  27. #define INCL_PM
  28. #include "os2.h"            /* required for all Windows applications*/
  29. #define DBMSOS2
  30. #include "sqlfront.h"
  31. #include "sqldb.h"
  32. #include "sqlpm.h"
  33.  
  34. DBPROCESS *dbproc = (DBPROCESS *)NULL;
  35.                     /* dbprocess pointer for dblib connection*/
  36. HWND errhWnd;                /* global window handle for current error*/
  37. HAB hab;
  38.  
  39. /****************************************************************************
  40.  
  41.     FUNCTION: main()
  42.  
  43.     PURPOSE: calls initialization function, processes message loop
  44.  
  45.     COMMENTS:
  46.  
  47.     This will initialize the window class if it is the first time this
  48.     application is run.  It then creates the window, and processes the
  49.     message loop until a WinPostQuitMessage is received.  It exits the
  50.     application by returning the value passed by the WinPostQuitMessage.
  51.  
  52. ****************************************************************************/
  53.  
  54. int main(void)
  55. {
  56.     HWND hWndFrame,hWnd;             /* window handle             */
  57.     HMQ hmq;
  58.     QMSG qmsg;
  59.     static CHAR *ClientClass = "SQLPM";
  60.     static ULONG flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
  61.                     FCF_SIZEBORDER | FCF_MINMAX |
  62.                                 FCF_SHELLPOSITION | FCF_TASKLIST |
  63.                                 FCF_MENU | FCF_ICON ;
  64.     hab = WinInitialize(0);
  65.     hmq = WinCreateMsgQueue(hab,0);
  66.     WinRegisterClass(hab,
  67.                  ClientClass,
  68.                      SqlPMWndProc,
  69.                      0L,
  70.                      0);
  71.  
  72.     hWndFrame = WinCreateStdWindow(
  73.         HWND_DESKTOP,
  74.     WS_VISIBLE,
  75.     &flFrameFlags,
  76.     ClientClass,
  77.     "SQLPM Test Program",
  78.     0L,
  79.     NULL,
  80.         ID_RESOURCE,
  81.     &hWnd);
  82.  
  83.     if (!hWnd)                      /* Was the window created? */
  84.     return (0);
  85.  
  86.     WinSetWindowText(hWndFrame,"SQL PM Test Program");
  87.  
  88.     errhWnd = hWnd;
  89.     while(WinGetMsg(hab, &qmsg, NULL,0,0))
  90.        WinDispatchMsg(hab,&qmsg);
  91.  
  92.     WinDestroyWindow(hWndFrame);                  /* Sends WM_PAINT message  */
  93.     WinDestroyMsgQueue(hmq);
  94.     WinTerminate(hab);
  95.     return 0;
  96. }
  97.  
  98.  
  99. /****************************************************************************
  100.  
  101.     FUNCTION: SqlPMWndProc(HWND, unsigned, WORD, LONG)
  102.  
  103.     PURPOSE:  Processes messages
  104.  
  105.     MESSAGES:
  106.  
  107.     WM_SYSCOMMAND - system menu (About dialog box)
  108.     WM_CREATE     - create window
  109.     WM_DESTROY    - destroy window
  110.     WM_COMMAND    - application menus (Connect and Select dialog boxes
  111.  
  112.     COMMENTS:
  113.  
  114.     To process the ID_ABOUTSQL message Call WinDlgBox
  115.     which will create the box according to the information in your
  116.     Sqlpm.rc file and turn control over to the AboutSQL() function.
  117.     This same action will take place for the two menu items Connect and
  118.     Select.
  119.  
  120.  
  121. ****************************************************************************/
  122.  
  123. MRESULT EXPENTRY SqlPMWndProc(hWnd, message, wParam, lParam)
  124. HWND hWnd;                  /* window handle             */
  125. USHORT message;                  /* type of message             */
  126. MPARAM wParam;                  /* additional information         */
  127. MPARAM lParam;                  /* additional information         */
  128. {
  129.     extern SHORT FAR dbPMMessageHandler();
  130.     extern SHORT FAR dbPMErrorHandler();
  131.  
  132.     switch (message) {
  133.     case WM_CREATE:                /* message: window being created */
  134.  
  135.                         /* Now make the message and error    */
  136.                     /* handler instances             */
  137.              dberrhandle(dbPMErrorHandler);
  138.              dbmsghandle(dbPMMessageHandler);
  139.                 WinSendMsg(hWnd,WM_ERASEBACKGROUND, (MPARAM)NULL,(MPARAM)NULL);
  140.         break;
  141.     
  142.         case WM_ERASEBACKGROUND :
  143.             return TRUE;
  144.     case WM_COMMAND :            /* menu selections generate */
  145.            switch(COMMANDMSG(&message)->cmd)
  146.        {
  147.                 case IDM_ABOUTSQL :
  148.                     WinDlgBox(HWND_DESKTOP,    /* current instance         */
  149.             hWnd,             /* resource to use         */
  150.             AboutSQL,        /* parent handle         */
  151.             NULL,
  152.                        ID_ABOUTSQLDLG,
  153.                        NULL);         /* ConnectSQL() instance address */
  154.                    break;
  155.  
  156.         case IDM_CONNECT :        /* connect to server */
  157.                     WinDlgBox(HWND_DESKTOP,     /* current instance  */
  158.                          hWnd,              /* resource to use  */
  159.                          ConnectSQL,            /* parent handle    */
  160.                          NULL,
  161.                         ID_CONNECTDLG,
  162.                        NULL);         /* ConnectSQL() instance address */
  163.             break;
  164.                case IDM_SELECT :        /* select an author         */
  165.             WinDlgBox(HWND_DESKTOP,    /* current instance         */
  166.             hWnd,             /* resource to use         */
  167.             SelectSQL,        /* parent handle         */
  168.             NULL,
  169.                            ID_SELECTDLG,
  170.                            (MPARAM)&hWnd);         /* ConnectSQL() instance address */
  171.  
  172.             break;
  173.                         /* the WM_COMMAND message   */
  174.            }
  175.            break;
  176.         case WM_DBRESULTS :            /* a select has been issued */
  177.         SqlPMProcessResults(hWnd);    /* process results        */
  178.         break;
  179.     
  180.     case WM_DESTROY:          /* message: window being destroyed */
  181.             if(dbproc != (DBPROCESS *)NULL)
  182.                dbclose(dbproc);
  183.         break;
  184.  
  185.     default:              /* Passes it on if unproccessed    */
  186.           return WinDefWindowProc(hWnd,message,wParam,lParam);
  187.     }
  188.     return (0);
  189. }
  190. /****************************************************************************
  191.  
  192.     FUNCTION: AboutSQL(HWND, unsigned, WORD, LONG)
  193.  
  194.     PURPOSE:  Processes messages for "AboutSQL" dialog box
  195.  
  196.     MESSAGES:
  197.  
  198.     WM_INITDLG - initialize dialog box
  199.     WM_COMMAND    - Input received
  200.  
  201.     COMMENTS:
  202.  
  203.     No initialization is needed for this particular dialog box, but TRUE
  204.     must be returned to Windows.
  205.  
  206.     Wait for user to click on "Ok" button, then close the dialog box.
  207.  
  208. ****************************************************************************/
  209.  
  210. MRESULT FAR PASCAL AboutSQL(hDlg, message, wParam, lParam)
  211. HWND hDlg;
  212. USHORT message;
  213. MPARAM wParam;
  214. MPARAM lParam;
  215. {
  216.     switch (message) {
  217.     case WM_INITDLG :
  218.      WinSetFocus(HWND_DESKTOP,       /* set focus to edit control */
  219.              WinWindowFromID(hDlg,DID_OK));
  220.        break;
  221.  
  222.     case WM_COMMAND:              /* message: received a command */
  223.         if(SHORT1FROMMP(wParam)==DID_OK) {
  224.         WinDismissDlg(hDlg, NULL);          /* Exits the dialog box         */
  225.         return (0L);
  226.         }
  227.         break;
  228.     }
  229.     return (WinDefDlgProc(hDlg, message, wParam, lParam));
  230. }
  231.  
  232.  
  233. /****************************************************************************
  234.  
  235.     FUNCTION: SelectSQL(HWND, unsigned, WORD, LONG)
  236.  
  237.     PURPOSE:  Processes messages for "SelectSQL" dialog box
  238.  
  239.     MESSAGES:
  240.  
  241.     WM_INITDLG - initialize dialog box
  242.     WM_COMMAND    - Input received
  243.  
  244.     COMMENTS:
  245.  
  246.     No initialization is needed for this particular dialog box, but TRUE
  247.     must be returned to Windows.
  248.     
  249.     Let user input into edit control the name of an author (the select
  250.     IS case sensitive).  When user presses OK, format the select statement
  251.     then send it to the server and execute it via dbsqlexec(). If the
  252.     dbsqlexec() SUCCEED's post a WM_DBRESULTS message so the results
  253.     may be retrieved and processed.
  254.  
  255.     Wait for user to click on "Ok" button, then close the dialog box.
  256.  
  257. ****************************************************************************/
  258. MRESULT FAR PASCAL SelectSQL(hDlg, message, wParam, lParam)
  259. HWND hDlg;
  260. USHORT message;
  261. MPARAM wParam;
  262. MPARAM lParam;
  263. {
  264.     char szSelectAuthor[41];          /* string for authors name        */
  265.     char szServerMess[45];          /* string for server response        */
  266.     char szAName[40];              /* format string for author        */
  267.     static HWND parhWnd;
  268.     switch (message) {
  269.     case WM_INITDLG:           /* message: initialize dialog box */
  270.         WinSendDlgItemMsg(hDlg,       /* limit input to 40 characters   */
  271.         AUTHORNAME,EM_SETTEXTLIMIT,(MPARAM)40,(MPARAM)0);
  272.             parhWnd = *((PHWND)(PVOIDFROMMP(lParam)));
  273.         WinSetFocus(HWND_DESKTOP,       /* set focus to edit control */
  274.         WinWindowFromID(hDlg,AUTHORNAME));
  275.         return (TRUE);
  276.     case WM_COMMAND:              /* message: received a command */
  277.         switch(SHORT1FROMMP(wParam))
  278.         {
  279.         case DID_OK :              /* "OK" box selected?         */
  280.             *szSelectAuthor = NULL;   /* Null author             */
  281.                 
  282.             WinQueryDlgItemText(hDlg,AUTHORNAME, /* get input name         */
  283.             MAX_ANAME,(CHAR FAR *)szSelectAuthor);
  284.  
  285.             if(dbproc == (DBPROCESS *)NULL) /* if not a valid process*/
  286.             {
  287.                     /* No server to query        */
  288.             WinMessageBox(HWND_DESKTOP,hDlg,
  289.                 "No SQL Server Connected to Query",
  290.                 "SQL Test",0, MB_ICONHAND | MB_OK);
  291.             }
  292.             else if(*szSelectAuthor != NULL) /* if a name exists */
  293.             {
  294.             dbcmd(dbproc,
  295.                 (CHAR FAR *)"select au_id, au_lname,"
  296.                 "au_fname, phone, address, city, state, zip");
  297.             dbcmd(dbproc, (CHAR FAR *)" from pubs..authors");
  298.             dbcmd(dbproc, (CHAR FAR *)" where au_lname = ");
  299.             sprintf(szAName,"'%s' ",szSelectAuthor);
  300.             dbcmd(dbproc,(CHAR FAR *)szAName);
  301.             if(dbsqlexec(dbproc) == FAIL)
  302.             {
  303.                 sprintf(szServerMess,    /* error, not in db */
  304.                 "%s not found in database pubs",
  305.                     szSelectAuthor);
  306.                 WinMessageBox(HWND_DESKTOP,hDlg,
  307.                     (CHAR FAR *)szServerMess,(CHAR FAR *)"SQL Test",
  308.                     0,MB_ICONHAND | MB_OK);
  309.             }
  310.             else    /* query SUCCEEDed so             */
  311.             {    /* post message to process results    */
  312.                 WinPostMsg(parhWnd,WM_DBRESULTS,(MPARAM)0,(MPARAM)0);
  313.             }
  314.             }
  315.             WinDismissDlg(hDlg, NULL);          /* Exits the dialog box         */
  316.             return (0L);
  317.             break;
  318.         case DID_CANCEL :
  319.             WinDismissDlg(hDlg, NULL);          /* cancelled select */
  320.             return(0L);
  321.             break;
  322.         }
  323.         break;
  324.     }
  325.     return (WinDefDlgProc(hDlg, message, wParam, lParam));
  326. }
  327. /****************************************************************************
  328.  
  329.     FUNCTION: ConnectSQL(HWND, unsigned, WORD, LONG)
  330.  
  331.     PURPOSE:  Processes messages for "Connect" dialog box
  332.  
  333.     MESSAGES:
  334.  
  335.     WM_INITDLG - initialize dialog box
  336.     WM_COMMAND    - Input received
  337.  
  338.     COMMENTS:
  339.  
  340.     No initialization is needed for this particular dialog box.
  341.  
  342.     Wait for user to click on "Ok" button, then close the dialog box.
  343.  
  344. ****************************************************************************/
  345.  
  346. MRESULT FAR PASCAL ConnectSQL(hDlg, message, wParam, lParam)
  347. HWND hDlg;
  348. USHORT message;
  349. MPARAM wParam;
  350. MPARAM lParam;
  351. {
  352.     char szSQLServer[31];
  353.     LOGINREC *LoginRec;
  354.     SHORT len;
  355.  
  356.     *szSQLServer = NULL;
  357.     switch (message) {
  358.     case WM_INITDLG:           /* message: initialize dialog box*/
  359.         WinSendDlgItemMsg(hDlg,       /* limit input to 30 characters  */
  360.         SQL_SERVER,EM_SETTEXTLIMIT,(MPARAM)30,(MPARAM)0);
  361.         WinSetFocus(HWND_DESKTOP,       /* set focus to edit control */
  362.         WinWindowFromID(hDlg,SQL_SERVER));
  363.         return (TRUE);
  364.  
  365.     case WM_COMMAND:              /* message: received a command*/
  366.         switch(SHORT1FROMMP(wParam))
  367.         {
  368.         case DID_OK :              /* "OK" box selected?        */
  369.             len = WinQueryDlgItemText(hDlg,SQL_SERVER,
  370.             MAX_SERVERNAME, (CHAR FAR *)szSQLServer); /* get Server name */
  371.                         szSQLServer[len] = NULL;
  372.                     if(dbproc != (DBPROCESS *)NULL) /* if an active     */
  373.                        dbclose(dbproc);            /* proc, close it   */
  374.             if(*szSQLServer != NULL) /* was something input        */
  375.             {
  376.             if((LoginRec = dblogin()) != (LOGINREC *)NULL) /* get loginrec */
  377.             {
  378.                 DBSETLUSER(LoginRec,"sa"); /* set user  */
  379.                     /* now open the connection to server */
  380.                 if((dbproc = dbopen(LoginRec,szSQLServer))
  381.                      == (DBPROCESS *)NULL)
  382.                 {
  383.                     /* if NULL couldn't connect    */
  384.                 dbfreelogin(LoginRec);
  385.                 }
  386.                 else /* got connect so use the pubs database */
  387.                 {
  388.                 dbuse(dbproc,"pubs");
  389.                 dbfreelogin(LoginRec);
  390.                 }
  391.             }
  392.             else /* memory allocation problem */
  393.                    WinMessageBox(HWND_DESKTOP,errhWnd,
  394.                                "Could not allocate Login Record","DBLIB Error",
  395.                                    0, MB_ICONHAND | MB_OK);
  396.             }
  397.             WinDismissDlg(hDlg, NULL);          /* Exits the dialog box         */
  398.             return (0L);
  399.         case DID_CANCEL :
  400.             WinDismissDlg(hDlg, NULL);
  401.             return(0L);
  402.         }
  403.         break;
  404.     }
  405.     return (WinDefDlgProc(hDlg, message, wParam, lParam));
  406. }
  407.  
  408. /****************************************************************************
  409.  
  410.  
  411.  
  412. /****************************************************************************
  413.  
  414.     FUNCTION: CheckForScroll(HWND, int, int, int)
  415.  
  416.     PURPOSE:  Check if next output line will be out of client area
  417.  
  418.     PARAMETERS: hWnd - Handle to the window.
  419.         CurrentPosition - Current y coordinate for the line of
  420.             text just written to the client area.
  421.         Spacing - The height of the line (including the space
  422.             separating lines) of the text just written.
  423.         Length - The length of the line just written in device
  424.             units.
  425.  
  426.     RETURN:    Returns the Y coordinate for the next line of text.
  427.  
  428.     COMMENTS:
  429.  
  430.     Will determine if the next line of text will be out of the client
  431.     area.  If so will scroll the window for the next line.  Also validates
  432.     the current line of text so that a WM_PAINT will not clear it.
  433.  
  434. ****************************************************************************/
  435. SHORT CheckForScroll(hWnd,CurrentPosition,Spacing, Length)
  436. HWND hWnd;
  437. LONG CurrentPosition;
  438. LONG Spacing;
  439. LONG Length;
  440. {
  441.     RECTL rect;            /* RECT structure for validation */
  442.     rect.yTop = CurrentPosition;     /* top of last line of text     */
  443.     rect.yBottom = CurrentPosition-Spacing-1; /* bottom of last line     */
  444.     rect.xLeft = 1;            /* left most column of line     */
  445.     rect.xRight = Length+1;        /* right most column of line     */
  446.     WinValidateRect(hWnd,(PRECTL)&rect,FALSE);   /* validate line so that it is   */
  447.                     /* not blanked on next paint     */
  448.         
  449.     WinQueryWindowRect(hWnd,(PRECTL)&rect);    /* get rect for current client   */
  450.     if(CurrentPosition - (Spacing*2) < rect.yBottom) /* will line fit     */
  451.     {
  452.                     /* if not scroll window and      */
  453.                     /* update client window         */
  454.     WinScrollWindow(hWnd,0,+(Spacing+1),NULL,NULL,NULL,NULL,0);
  455.     WinUpdateWindow(hWnd);
  456.     return(CurrentPosition);
  457.     }
  458.     return(CurrentPosition-Spacing);
  459. }
  460.  
  461. /****************************************************************************
  462.  
  463.     FUNCTION: SqlPMProcessResults(HWND)
  464.  
  465.     PURPOSE:  If a valid dbprocess is present process all results from pending
  466.           select statement, output each field to client area.  Whenever
  467.           a new line is written to client area it is checked to see if
  468.           the client area needs to be scrolled.
  469.  
  470.     PARAMETERS: hWnd - Handle to the window.
  471.  
  472.     RETURN:    Nothing
  473.  
  474.     COMMENTS:
  475.         This function will bind the fields in the select statement
  476.             to local variables, format an output string then
  477.             write that string to the client area via GpiCharStringAt.
  478.         It is called by the main message processing loop
  479.         SqlPMWndProc via the message WM_DBRESULTS.
  480.  
  481. ****************************************************************************/
  482. void SqlPMProcessResults(hWnd)
  483. HWND hWnd;
  484. {
  485.     HPS hPS;                /* display context         */
  486.     FONTMETRICS tm;            /* text metric structure     */
  487.     char szId[12];            /* Author ID for binding     */
  488.     char szLastName[41];        /* Author last name for binding     */
  489.     char szFirstName[21];        /* Author first name for binding */
  490.     char szPhone[13];            /* Author phone for binding     */
  491.     char szAddress[41];            /* Author address for binding     */
  492.     char szCity[21];            /* Author city for binding     */
  493.     char szState[3];            /* Author state for binding     */
  494.     char szZip[6];            /* Author zipcode for binding     */
  495.     char szOutputString[81];        /* general output string     */
  496.     RETCODE result_code;        /* results code from dbresults     */
  497.     LONG Y;                /* Y coordinate for text output  */
  498.     LONG Spacing;            /* Spacing between lines     */
  499.     POINTL pointl;
  500.     RECTL rect;
  501.  
  502.     errhWnd = hWnd;
  503.     WinQueryWindowRect(hWnd,(PRECTL)&rect);    /* get rect for current client   */
  504.     hPS = WinGetPS(hWnd);
  505.     GpiQueryFontMetrics(hPS, (LONG)sizeof(FONTMETRICS), (PFONTMETRICS)&tm);
  506.     Spacing = tm.lExternalLeading+tm.lMaxAscender;
  507.     pointl.x = 1;
  508.     Y = pointl.y = rect.yTop - (1 + Spacing);
  509.     if(dbproc == (DBPROCESS *)NULL)    /* if process null, no results     */
  510.     {
  511.     WinReleasePS(hPS);        /* free resources and return     */
  512.     return;
  513.     }
  514.     WinCls(hWnd);
  515.     while(((result_code = dbresults(dbproc)) != NO_MORE_RESULTS) && result_code != FAIL)
  516.     {
  517.     if(result_code == SUCCEED)    /* if results ready         */
  518.     {
  519.                     /* Bind all data of interest     */
  520.         dbbind(dbproc,1,NTBSTRINGBIND, 12L, szId);
  521.         dbbind(dbproc,2,NTBSTRINGBIND, 41L, szLastName);
  522.         dbbind(dbproc,3,NTBSTRINGBIND, 21L, szFirstName);
  523.         dbbind(dbproc,4,NTBSTRINGBIND, 13L, szPhone);
  524.         dbbind(dbproc,5,NTBSTRINGBIND, 41L, szAddress);
  525.         dbbind(dbproc,6,NTBSTRINGBIND, 21L, szCity);
  526.         dbbind(dbproc,7,NTBSTRINGBIND, 3L,  szState);
  527.         dbbind(dbproc,8,NTBSTRINGBIND, 6L,  szZip);
  528.         while(dbnextrow(dbproc) != NO_MORE_ROWS) /* get all rows     */
  529.         {
  530.             /* here we format each field and write it to client */
  531.             /* area checking to see if the client area needs to */
  532.             /* be scrolled after each line is written        */
  533.  
  534.                 sprintf(szOutputString,"Author ID: %s",szId);
  535.                 GpiCharStringAt(hPS,(PPOINTL)&pointl,(LONG)strlen(szOutputString),szOutputString);
  536.                 Y = CheckForScroll(hWnd,Y,Spacing,(LONG)strlen(szOutputString) * tm.lEmInc);
  537.                 pointl.y = Y;
  538.  
  539.         sprintf(szOutputString,"Last Name: %s",szLastName);
  540.                 GpiCharStringAt(hPS,(PPOINTL)&pointl,(LONG)strlen(szOutputString),szOutputString);
  541.                 Y = CheckForScroll(hWnd,Y,Spacing,(LONG)strlen(szOutputString) * tm.lEmInc);
  542.                 pointl.y = Y;
  543.  
  544.  
  545.         sprintf(szOutputString,"First Name: %s",szFirstName);
  546.                 GpiCharStringAt(hPS,(PPOINTL)&pointl,(LONG)strlen(szOutputString),szOutputString);
  547.                 Y = CheckForScroll(hWnd,Y,Spacing,(LONG)strlen(szOutputString) * tm.lEmInc);
  548.                 pointl.y = Y;
  549.  
  550.         sprintf(szOutputString,"Address:   %s",szAddress);
  551.                 GpiCharStringAt(hPS,(PPOINTL)&pointl,(LONG)strlen(szOutputString),szOutputString);
  552.                 Y = CheckForScroll(hWnd,Y,Spacing,(LONG)strlen(szOutputString) * tm.lEmInc);
  553.                 pointl.y = Y;
  554.  
  555.         sprintf(szOutputString,"City:      %s",szCity);
  556.                 GpiCharStringAt(hPS,(PPOINTL)&pointl,(LONG)strlen(szOutputString),szOutputString);
  557.                 Y = CheckForScroll(hWnd,Y,Spacing,(LONG)strlen(szOutputString) * tm.lEmInc);
  558.                 pointl.y = Y;
  559.  
  560.         sprintf(szOutputString,"State:     %s",szState);
  561.                 GpiCharStringAt(hPS,(PPOINTL)&pointl,(LONG)strlen(szOutputString),szOutputString);
  562.                 Y = CheckForScroll(hWnd,Y,Spacing,(LONG)strlen(szOutputString) * tm.lEmInc);
  563.                 pointl.y = Y;
  564.  
  565.         sprintf(szOutputString,"ZipCode:   %s",szZip);
  566.                 GpiCharStringAt(hPS,(PPOINTL)&pointl,(LONG)strlen(szOutputString),szOutputString);
  567.                 Y = CheckForScroll(hWnd,Y,Spacing,(LONG)strlen(szOutputString) * tm.lEmInc);
  568.                 pointl.y = Y;
  569.  
  570.         sprintf(szOutputString,"Telephone: %s",szPhone);
  571.                 GpiCharStringAt(hPS,(PPOINTL)&pointl,(LONG)strlen(szOutputString),szOutputString);
  572.                 Y = CheckForScroll(hWnd,Y,Spacing,(LONG)strlen(szOutputString) * tm.lEmInc);
  573.                 pointl.y = Y;
  574.  
  575.                 Y = CheckForScroll(hWnd,Y,Spacing,0L);   /* insert blank line */
  576.                 pointl.y = Y;
  577.         }
  578.     }
  579.     }
  580.     WinReleasePS(hPS);            /* free resource       */
  581.     return;
  582. }
  583. /* WinCls() - clears the displayed screen */
  584. void WinCls(hWnd)
  585. HWND hWnd;
  586. {
  587.    HPS hPS;
  588.  
  589.    hPS = WinGetPS(hWnd);
  590.    GpiErase(hPS);
  591.    WinReleasePS(hPS);
  592. }
  593.  
  594. /****************************************************************************
  595.  
  596.     FUNCTION: dbPMMessageHandler(DBPROCESS *, DBINT, DBSMALLINT, DBSMALLINT,
  597.             CHAR *)
  598.  
  599.     PURPOSE:  When the Data Server returns a message to dblib this function
  600.           will be called to process that message. You must return 0 to
  601.               dblib.
  602.  
  603.     RETURN:    Return 0
  604.  
  605.     COMMENTS:
  606.  
  607. ****************************************************************************/
  608.  
  609. SHORT FAR dbPMMessageHandler(dbproc, msgno, msgstate, severity, msgtext)
  610. DBPROCESS        *dbproc;
  611. DBINT            msgno;
  612. DBSMALLINT       msgstate;
  613. DBSMALLINT       severity;
  614. CHAR             *msgtext;
  615. {
  616.     WinMessageBox(HWND_DESKTOP,errhWnd,
  617.         msgtext,"SQL DataServer Message",0,MB_OK);
  618.     return(0);
  619. }
  620.  
  621. /****************************************************************************
  622.  
  623.     FUNCTION: dbPMErrorHandler(DBPROCESS *, int, int, int, CHAR *, CHAR *)
  624.  
  625.     PURPOSE:  When dblib returns an error message to the application this
  626.           function will be called to process that error.  You must return
  627.               either INT_CANCEL, INT_CONTINUE, or INT_EXIT to dblib.
  628.  
  629.     RETURN:    Return continuation code.
  630.  
  631.     COMMENTS:
  632.  
  633. ****************************************************************************/
  634.  
  635. SHORT FAR dbPMErrorHandler(dbproc, severity, errno, oserr, dberrstr, oserrstr)
  636. DBPROCESS *dbproc;
  637. int severity;
  638. int errno;
  639. int oserr;
  640. CHAR *dberrstr;
  641. CHAR *oserrstr;
  642. {
  643.     WinMessageBox(HWND_DESKTOP,errhWnd,
  644.          dberrstr,"DB-LIBRARY error",0, MB_ICONHAND | MB_OK);
  645.  
  646.     if (oserr != -1)    /* os error    */
  647.     {
  648.         WinMessageBox(HWND_DESKTOP,errhWnd,
  649.     oserrstr,"Operating-System error",0,MB_ICONHAND | MB_OK);
  650.     }
  651.  
  652.     return(INT_CANCEL);    /* cancel command */
  653. }
  654.  
  655.