home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
-
- PROGRAM: SqlCursw.c
- Copyright (C) 1991 Microsoft Corp.
-
- PURPOSE: Sql Server sample Windows applications
-
- COMMENTS:
-
- Windows can have several copies of your application running at the
- same time. The variable hInst keeps track of which instance this
- application is so that processing will be to the correct window.
-
- You only need to initialize the application once. After it is
- initialized, all other copies of the application will use the same
- window class, and do not need to be separately initialized.
-
- ****************************************************************************/
-
- #include "windows.h" /* required for all Windows applications*/
- #define DBMSWIN /* needed to define environment */
- #include "sqlfront.h" /* standard dblib include file */
- #include "sqldb.h" /* standard dblib include file */
- #include "sqlcursw.h" /* specific to this program */
-
- DBPROCESS *dbproc = (DBPROCESS *)NULL;
- DBCURSOR *hdbcursor = (DBCURSOR *)NULL;
-
- char stmt[] = "select au_lname, au_fname, city, state from authors where contract = 1 ";
-
- /* Status array, and results set */
-
- DBINT pstat[NROWS];
- DBINT plen[NROWS];
- char au_lname[NROWS][41];
- char au_fname[NROWS][21];
- char au_city[NROWS][21];
- char au_state[NROWS][3];
- char szRowNum[5];
- USHORT rownum = 0;
- char szValues[251];
- char szTable[31];
-
- HANDLE hInst; /* current instance */
- HWND ghWnd; /* global window handle for handlers */
- HWND errhWnd; /* global window handle for current error*/
- /****************************************************************************
-
- FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
-
- PURPOSE: calls initialization function, processes message loop
-
- COMMENTS:
-
- This will initialize the window class if it is the first time this
- application is run. It then creates the window, and processes the
- message loop until a PostQuitMessage is received. It exits the
- application by returning the value passed by the PostQuitMessage.
-
- ****************************************************************************/
-
- int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
- HANDLE hInstance; /* current instance */
- HANDLE hPrevInstance; /* previous instance */
- LPSTR lpCmdLine; /* command line */
- int nCmdShow; /* show-window type (open/icon) */
- {
- HWND hWnd; /* window handle */
- MSG msg; /* message */
-
-
- if (!hPrevInstance) /* Has application been initialized? */
- if (!SqlTestInit(hInstance))
- return (NULL); /* Exits if unable to initialize */
-
- hInst = hInstance; /* Saves the current instance */
-
- hWnd = CreateWindow("SQL Test", /* window class */
- "SQL Server Sample Windows Application", /* window name */
- WS_OVERLAPPEDWINDOW, /* window style */
- CW_USEDEFAULT, /* x position */
- CW_USEDEFAULT, /* y position */
- CW_USEDEFAULT, /* width */
- CW_USEDEFAULT, /* height */
- NULL, /* parent handle */
- NULL, /* menu or child ID */
- hInstance, /* instance */
- NULL); /* additional info */
-
- if (!hWnd) /* Was the window created? */
- return (NULL);
-
- ghWnd = hWnd; /* set global handle */
- errhWnd = hWnd;
-
- ShowWindow(hWnd, nCmdShow); /* Shows the window */
- UpdateWindow(hWnd); /* Sends WM_PAINT message */
-
- while (GetMessage(&msg, /* message structure */
- NULL, /* handle of window receiving the message */
- NULL, /* lowest message to examine */
- NULL)) /* highest message to examine */
- {
- TranslateMessage(&msg); /* Translates virtual key codes */
- DispatchMessage(&msg); /* Dispatches message to window */
- }
- return (msg.wParam); /* Returns the value from PostQuitMessage */
- }
-
-
- /****************************************************************************
-
- FUNCTION: SqlTestInit(HANDLE)
-
- PURPOSE: Initializes window data and registers window class
-
- COMMENTS:
-
- Sets up a structure to register the window class. Structure includes
- such information as what function will process messages, what cursor
- and icon to use, etc.
-
-
- ****************************************************************************/
-
- BOOL SqlTestInit(hInstance)
- HANDLE hInstance; /* current instance */
- {
- HANDLE hMemory; /* handle to allocated memory */
- PWNDCLASS pWndClass; /* structure pointer */
- BOOL bSuccess; /* RegisterClass() result */
-
- hMemory = LocalAlloc(LPTR, sizeof(WNDCLASS));
- pWndClass = (PWNDCLASS) LocalLock(hMemory);
-
- pWndClass->style = NULL; /*CS_HREDRAW | CS_VREDRAW; */
- pWndClass->lpfnWndProc = SqlTestWndProc;
- pWndClass->hInstance = hInstance;
- pWndClass->hIcon = LoadIcon(hInstance, "SQLITEST");
- pWndClass->hCursor = LoadCursor(NULL, IDC_ARROW);
- pWndClass->hbrBackground = GetStockObject(WHITE_BRUSH);
- pWndClass->lpszMenuName = (LPSTR)"SQLTest";
- pWndClass->lpszClassName = (LPSTR)"SQL Test";
-
- bSuccess = RegisterClass(pWndClass);
-
-
- LocalUnlock(hMemory); /* Unlocks the memory */
- LocalFree(hMemory); /* Returns it to Windows */
- return (bSuccess); /* Returns result of registering the window */
- }
-
- /****************************************************************************
-
- FUNCTION: SqlTestWndProc(HWND, unsigned, WORD, LONG)
-
- PURPOSE: Processes messages
-
- MESSAGES:
-
- WM_SYSCOMMAND - system menu (About dialog box)
- WM_CREATE - create window
- WM_DESTROY - destroy window
- WM_COMMAND - application menus (Connect and Select dialog boxes
-
- COMMENTS:
-
- To process the ID_ABOUTSQL message, call MakeProcInstance() to get the
- current instance address of the About() function. Then call Dialog
- box which will create the box according to the information in your
- SqlTest.rc file and turn control over to the About() function. When
- it returns, free the intance address.
- This same action will take place for the two menu items Connect and
- Select.
-
-
- ****************************************************************************/
-
- long FAR PASCAL SqlTestWndProc(hWnd, message, wParam, lParam)
- HWND hWnd; /* window handle */
- unsigned message; /* type of message */
- WORD wParam; /* additional information */
- LONG lParam; /* additional information */
- {
- FARPROC lpProcAbout; /* pointer to the "About" function */
- FARPROC lpProcRowNum; /* pointer to the "GetRowNum" function */
- FARPROC lpProcModify; /* pointer to the "ModifyRow" function */
- FARPROC lpProcSQL; /* pointer to the "ConnectSQL" function*/
-
- HMENU hMenu; /* handle to the System menu */
- static FARPROC lpdbwinMessageHandler; /* pointer to message handler */
- static FARPROC lpdbwinErrorHandler; /* pointer to error handler */
- RETCODE rc; /* return code */
-
- switch (message) {
- case WM_SYSCOMMAND: /* message: command from system menu */
- if (wParam == ID_ABOUTSQL) {
- lpProcAbout = MakeProcInstance(AboutSQL, hInst);
-
- DialogBox(hInst, /* current instance */
- "ABOUTSQL", /* resource to use */
- hWnd, /* parent handle */
- lpProcAbout); /* About() instance address */
-
- FreeProcInstance(lpProcAbout);
- break;
- }
-
- else /* Lets Windows process it */
- return (DefWindowProc(hWnd, message, wParam, lParam));
-
- case WM_CREATE: /* message: window being created */
-
- /* Get the handle of the System menu */
-
- hMenu = GetSystemMenu(hWnd, FALSE);
-
- /* Add a separator to the menu */
-
- ChangeMenu(hMenu, /* menu handle */
- NULL, /* menu item to change */
- NULL, /* new menu item */
- NULL, /* menu identifier */
- MF_APPEND | MF_SEPARATOR); /* type of change */
-
- /* Add new menu item to the System menu */
-
- ChangeMenu(hMenu, /* menu handle */
- NULL, /* menu item to change */
- "A&bout SQL Test...", /* new menu item */
- ID_ABOUTSQL, /* menu identifier */
- MF_APPEND | MF_STRING); /* type of change */
-
- /* Now make the message and error */
- /* handler instances */
- dbinit();
- lpdbwinMessageHandler =
- MakeProcInstance((FARPROC)dbwinMessageHandler, hInst);
- lpdbwinErrorHandler =
- MakeProcInstance((FARPROC)dbwinErrorHandler, hInst);
- /* Install the instances into dblib */
- dbmsghandle(lpdbwinMessageHandler);
- dberrhandle(lpdbwinErrorHandler);
- MessageBox(hWnd,
- (LPSTR)"None of the data modifications will be committed",
- (LPSTR)"SQLCURSW", MB_OK);
- break;
-
- case WM_COMMAND : /* menu selections generate */
- /* the WM_COMMAND message */
- switch(wParam) /* menu in WORD parameter */
- {
- case IDM_CONNECT : /* connect to server */
- lpProcSQL = MakeProcInstance(ConnectSQL, hInst);
-
- DialogBox(hInst, /* current instance */
- "CONNECT", /* resource to use */
- hWnd, /* parent handle */
- lpProcSQL); /* ConnectSQL() instance address */
-
- FreeProcInstance(lpProcSQL);
- break;
- case IDM_RAND :
- case IDM_RELT :
- case IDM_REFRESH :
- /* Obtain the row number */
- lpProcRowNum = MakeProcInstance(GetRowNum, hInst);
- DialogBox(hInst, "ROWNUM", hWnd, lpProcRowNum);
- FreeProcInstance(lpProcRowNum);
-
- /* FALL THROUGH */
-
- case IDM_FIRST :
- case IDM_NEXT :
- case IDM_PREV :
- case IDM_LAST :
- DBLOCKLIB();
- if (wParam == IDM_REFRESH)
- rc = dbcursor(hdbcursor, wParam - UPD_CONST, rownum,
- NULL, NULL);
- else
- /* Do the fetch and display of rows */
- rc = dbcursorfetch(hdbcursor, wParam - FETCH_CONST,
- rownum);
- if (rc == SUCCEED)
- SQLTestProcessResults(hWnd);
- DBUNLOCKLIB();
- rownum = 0; /* Reset for next fetch */
- break;
- case IDM_DELETE :
- case IDM_LOCK :
- case IDM_UPDATE :
- case IDM_INSERT :
- szValues[0] = '\0';
- szTable[0] = '\0';
- /* Obtain the row number */
- if (wParam == IDM_DELETE || wParam == IDM_LOCK)
- {
- lpProcModify = MakeProcInstance(DelLockRow, hInst);
- DialogBox(hInst, "DELLOCK", hWnd, lpProcModify);
- }
- else
- {
- lpProcModify = MakeProcInstance(ModifyRow, hInst);
- DialogBox(hInst, "MODIFY", hWnd, lpProcModify);
- }
- FreeProcInstance(lpProcModify);
- DBLOCKLIB();
- /* Do the dbcursor call */
- dbcursor(hdbcursor, wParam - UPD_CONST, rownum,
- szTable, szValues);
- DBUNLOCKLIB();
- rownum = 0; /* Reset for next command */
- break;
-
- }
- break;
-
- case WM_DESTROY: /* message: window being destroyed */
- dbexit(); /* free any active dbprocesses */
- FreeProcInstance(lpdbwinMessageHandler); /* release handlers */
- FreeProcInstance(lpdbwinErrorHandler);
- dbwinexit();
- PostQuitMessage(0);
- break;
-
- default: /* Passes it on if unproccessed */
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- return (NULL);
- }
-
-
- /****************************************************************************
-
- FUNCTION: AboutSQL(HWND, unsigned, WORD, LONG)
-
- PURPOSE: Processes messages for "AboutSQL" dialog box
-
- MESSAGES:
-
- WM_INITDIALOG - initialize dialog box
- WM_COMMAND - Input received
-
- COMMENTS:
-
- No initialization is needed for this particular dialog box, but TRUE
- must be returned to Windows.
-
- Wait for user to click on "Ok" button, then close the dialog box.
-
- ****************************************************************************/
-
- BOOL FAR PASCAL AboutSQL(hDlg, message, wParam, lParam)
- HWND hDlg;
- unsigned message;
- WORD wParam;
- LONG lParam;
- {
- switch (message) {
- case WM_INITDIALOG: /* message: initialize dialog box */
- return (TRUE);
-
- case WM_COMMAND: /* message: received a command */
- if (wParam == IDOK) { /* "OK" box selected? */
- EndDialog(hDlg, NULL); /* Exits the dialog box */
- return (TRUE);
- }
- break;
- }
- return (FALSE); /* Didn't process a message */
- }
- /****************************************************************************
-
- FUNCTION: GetRowNum(HWND, unsigned, WORD, LONG)
-
- PURPOSE: Processes messages for "ROWNUM" dialog box
-
- MESSAGES:
-
- WM_INITDIALOG - initialize dialog box
- WM_COMMAND - Input received
-
- COMMENTS:
-
- No initialization is needed for this particular dialog box, but TRUE
- must be returned to Windows.
-
- Wait for user to click on "Ok" button, then close the dialog box.
-
- ****************************************************************************/
-
- BOOL FAR PASCAL GetRowNum(hDlg, message, wParam, lParam)
- HWND hDlg;
- unsigned message;
- WORD wParam;
- LONG lParam;
- {
- switch (message) {
- case WM_INITDIALOG: /* message: initialize dialog box */
- SendDlgItemMessage(hDlg, /* limit input to 4 characters */
- ID_ROWNUM,EM_LIMITTEXT,4,0L);
- return (TRUE);
-
- case WM_COMMAND: /* message: received a command */
- if (wParam == IDOK) { /* "OK" box selected? */
- GetDlgItemText(hDlg,ID_ROWNUM,
- (LPSTR)szRowNum,4); /* Get row number */
- szRowNum[4] = '\0';
- rownum = atoi(szRowNum);
- EndDialog(hDlg, NULL); /* Exits the dialog box */
- return (TRUE);
- }
- break;
- }
- return (FALSE); /* Didn't process a message */
- }
- /****************************************************************************
-
- FUNCTION: DelLockRow(HWND, unsigned, WORD, LONG)
-
- PURPOSE: Processes messages for "DELLOCK" dialog box
-
- MESSAGES:
-
- WM_INITDIALOG - initialize dialog box
- WM_COMMAND - Input received
-
- COMMENTS:
-
- No initialization is needed for this particular dialog box, but TRUE
- must be returned to Windows.
-
- Wait for user to click on "Ok" button, then close the dialog box.
-
- ****************************************************************************/
-
- BOOL FAR PASCAL DelLockRow(hDlg, message, wParam, lParam)
- HWND hDlg;
- unsigned message;
- WORD wParam;
- LONG lParam;
- {
- switch (message) {
- case WM_INITDIALOG: /* message: initialize dialog box */
- SendDlgItemMessage(hDlg, /* limit row# input to 4 characters*/
- ID_DROWNUM,EM_LIMITTEXT,4,0L);
- SendDlgItemMessage(hDlg, /* limit table input to 30 characters*/
- ID_DTABLE,EM_LIMITTEXT,30,0L);
- return (TRUE);
-
- case WM_COMMAND: /* message: received a command */
- if (wParam == IDOK) { /* "OK" box selected? */
- GetDlgItemText(hDlg,ID_DROWNUM,
- (LPSTR)szRowNum,4); /* Get row number */
- szRowNum[4] = '\0';
- rownum = atoi(szRowNum);
- GetDlgItemText(hDlg,ID_DTABLE,
- (LPSTR)szTable,30); /* Get table name */
- EndDialog(hDlg, NULL); /* Exits the dialog box */
- return (TRUE);
- }
- else if (wParam == IDCANCEL)
- {
- EndDialog(hDlg, NULL); /* Exits the dialog box */
- return (TRUE);
- }
- break;
- }
- return (FALSE); /* Didn't process a message */
- }
- /****************************************************************************
-
- FUNCTION: ModifyRow(HWND, unsigned, WORD, LONG)
-
- PURPOSE: Processes messages for "MODIFY" dialog box
-
- MESSAGES:
-
- WM_INITDIALOG - initialize dialog box
- WM_COMMAND - Input received
-
- COMMENTS:
-
- No initialization is needed for this particular dialog box, but TRUE
- must be returned to Windows.
-
- Wait for user to click on "Ok" button, then close the dialog box.
-
- ****************************************************************************/
-
- BOOL FAR PASCAL ModifyRow(hDlg, message, wParam, lParam)
- HWND hDlg;
- unsigned message;
- WORD wParam;
- LONG lParam;
- {
- switch (message) {
- case WM_INITDIALOG: /* message: initialize dialog box */
- SendDlgItemMessage(hDlg, /* limit row# input to 4 characters*/
- ID_MROWNUM,EM_LIMITTEXT,4,0L);
- SendDlgItemMessage(hDlg, /* limit table input to 30 characters*/
- ID_MTABLE,EM_LIMITTEXT,30,0L);
- SendDlgItemMessage(hDlg, /* limit values input to 250 characters*/
- ID_MVALUES,EM_LIMITTEXT,250,0L);
- return (TRUE);
-
- case WM_COMMAND: /* message: received a command */
- if (wParam == IDOK) { /* "OK" box selected? */
- GetDlgItemText(hDlg,ID_MROWNUM,
- (LPSTR)szRowNum,4); /* Get row number */
- szRowNum[4] = '\0';
- rownum = atoi(szRowNum);
- GetDlgItemText(hDlg,ID_MTABLE,
- (LPSTR)szTable,30); /* Get table name */
- GetDlgItemText(hDlg,ID_MVALUES,
- (LPSTR)szValues,250); /* Get values string */
- EndDialog(hDlg, NULL); /* Exits the dialog box */
- return (TRUE);
- }
- else if (wParam == IDCANCEL)
- {
- EndDialog(hDlg, NULL); /* Exits the dialog box */
- return (TRUE);
- }
- break;
- }
- return (FALSE); /* Didn't process a message */
- }
- /****************************************************************************
-
- FUNCTION: ConnectSQL(HWND, unsigned, WORD, LONG)
-
- PURPOSE: Processes messages for "Connect" dialog box
-
- MESSAGES:
-
- WM_INITDIALOG - initialize dialog box
- WM_COMMAND - Input received
-
- COMMENTS:
-
- No initialization is needed for this particular dialog box, but TRUE
- must be returned to Windows.
-
- Wait for user to click on "Ok" button, then close the dialog box.
-
- ****************************************************************************/
-
- BOOL FAR PASCAL ConnectSQL(hDlg, message, wParam, lParam)
- HWND hDlg;
- unsigned message;
- WORD wParam;
- LONG lParam;
- {
- char szSQLServer[31];
- char szServerMess[81];
- static LOGINREC *LoginRec;
- RETCODE rc;
-
- *szSQLServer = NULL;
- switch (message) {
- case WM_INITDIALOG: /* message: initialize dialog box*/
- SendDlgItemMessage(hDlg, /* limit input to 30 characters */
- ID_SQLSERVER,EM_LIMITTEXT,30,0L);
- return (TRUE);
-
- case WM_COMMAND: /* message: received a command*/
- errhWnd = hDlg;
- switch(wParam)
- {
- case IDOK : /* "OK" box selected? */
- GetDlgItemText(hDlg,ID_SQLSERVER,
- (LPSTR)szSQLServer,
- MAX_SERVERNAME); /* get Server name */
- if(*szSQLServer != NULL) /* was something input */
- {
- DBLOCKLIB(); /* lock down library */
- if(dbproc != (DBPROCESS *)NULL) /* if an active */
- /* process close it */
- {
- dbclose(dbproc);
- dbproc = (DBPROCESS *)NULL;
- }
- if((LoginRec = dblogin()) != (LOGINREC *)NULL) /* get loginrec */
- {
- DBSETLUSER(LoginRec,(char far *)"sa"); /* set user */
- /* now open the connection to server */
- if((dbproc = dbopen(LoginRec,(LPSTR)szSQLServer))
- == (DBPROCESS *)NULL)
- {
- /* if NULL couldn't connect */
- dbfreelogin(LoginRec);
- }
- else /* got connect so use the pubs database */
- {
- dbuse(dbproc,(LPSTR)"pubs");
- dbfreelogin(LoginRec);
- LoginRec = (LOGINREC *)NULL;
- }
- }
- else /* memory allocation problem */
- MessageBox(hDlg, "Could not allocate Login Record",
- "System Error", MB_ICONHAND | MB_OK);
-
- /* Open the cursor, bind variables */
- if (SQLInitCursor() == FALSE)
- MessageBox(hDlg, "Cursor open failed",
- "System Error", MB_ICONHAND | MB_OK);
- DBUNLOCKLIB(); /* done unlock library */
- }
- EndDialog(hDlg, NULL); /* Exits the dialog box */
- return (TRUE);
- break;
- case IDCANCEL :
- EndDialog(hDlg, NULL);
- return(TRUE);
- break;
-
- }
- break;
- }
- return (FALSE); /* Didn't process a message */
- }
-
- /****************************************************************************
-
- FUNCTION: SQLInitCursor(void)
-
- PURPOSE: Initialize cursor, bind variables
-
- PARAMETERS: NONE
-
- RETURNS: NONE
-
- COMMENTS:
-
- ****************************************************************************/
- BOOL PASCAL SQLInitCursor()
- {
- int i, j= 0;
- RETCODE rc;
-
- /* Open the cursor */
- hdbcursor = dbcursoropen(dbproc, stmt,
- KEYSET, CONCUROPT, NROWS, pstat);
- if (hdbcursor == (DBCURSOR *)NULL)
- {
- return FALSE;
- }
-
- /* Start a transaction block. We will exit without
- ** committing, so the pubs database will
- ** not be altered.
- */
- if ((dbcmd(dbproc, "begin tran") != SUCCEED) ||
- (dbsqlexec(dbproc) != SUCCEED))
- {
- /* Error! Close the connection and exit */
- dbclose(dbproc);
- dbproc = (DBPROCESS *)NULL;
- return FALSE;
- }
- while ((rc=dbresults(dbproc)) != NO_MORE_RESULTS)
- {
- if (rc == FAIL)
- {
- /* Error! Close the connection and exit */
- dbclose(dbproc);
- dbproc = (DBPROCESS *)NULL;
- return FALSE;
- }
- }
- /* Bind variables */
- rc = dbcursorbind(hdbcursor, 1, NTBSTRINGBIND, 41, NULL,
- (char far *)au_lname);
- if (rc == FAIL)
- {
- return FALSE;
- }
- rc = dbcursorbind(hdbcursor, 2, NTBSTRINGBIND, 21, NULL,
- (char far *)au_fname);
- if (rc == FAIL)
- {
- return FALSE;
- }
- rc = dbcursorbind(hdbcursor, 3, NTBSTRINGBIND, 21, NULL,
- (char far *)au_city);
- if (rc == FAIL)
- {
- return FALSE;
- }
- rc = dbcursorbind(hdbcursor, 4, NTBSTRINGBIND, 3, NULL,
- (char far *)au_state);
- if (rc == FAIL)
- {
- return FALSE;
- }
- return (TRUE);
- }
-
-
- /****************************************************************************
-
- FUNCTION: CheckForScroll(HWND, int, int, int)
-
- PURPOSE: Check if next output line will be out of client area
-
- PARAMETERS: hWnd - Handle to the window.
- CurrentPosition - Current y coordinate for the line of
- text just written to the client area.
- Spacing - The height of the line (including the space
- separating lines) of the text just written.
- Length - The length of the line just written in device
- units.
-
- RETURN: Returns the Y coordinate for the next line of text.
-
- COMMENTS:
-
- Will determine if the next line of text will be out of the client
- area. If so will scroll the window for the next line. Also validates
- the current line of text so that a WM_PAINT will not clear it.
-
- ****************************************************************************/
- int CheckForScroll(hWnd,CurrentPosition,Spacing, Length)
- HWND hWnd;
- int CurrentPosition;
- int Spacing;
- int Length;
- {
- RECT rect; /* RECT structure for validation */
- rect.top = CurrentPosition; /* top of last line of text */
- rect.bottom = CurrentPosition+Spacing+1; /* bottom of last line */
- rect.left = 1; /* left most column of line */
- rect.right = Length+1; /* right most column of line */
- ValidateRect(hWnd,(LPRECT)&rect); /* validate line so that it is */
- /* not blanked on next paint */
-
- GetClientRect(hWnd,(LPRECT)&rect); /* get rect for current client */
- if(CurrentPosition + (Spacing*2) > rect.bottom) /* will line fit */
- {
- /* if not scroll window and */
- /* update client window */
- ScrollWindow(hWnd,0,-(Spacing+1),NULL,NULL);
- UpdateWindow(hWnd);
- return(CurrentPosition);
- }
- return(CurrentPosition+Spacing);
- }
-
- /****************************************************************************
-
- FUNCTION: SQLTestProcessResults(HWND)
-
- PURPOSE: If a valid dbprocess is present process all results from pending
- select statement, output each field to client area. Whenever
- a new line is written to client area it is checked to see if
- the client area needs to be scrolled.
-
- PARAMETERS: hWnd - Handle to the window.
-
- RETURN: Returns the Y coordinate for the next line of text.
-
- COMMENTS:
- This function will bind the fields in the select statement
- to local variables, format an output string then
- write that string to the client area via TextOut.
-
- ****************************************************************************/
- BOOL SqlTestProcessResults(hWnd)
- HWND hWnd;
- {
- HDC hDC; /* display context */
- TEXTMETRIC tm; /* text metric structure */
- char szOutputString[81]; /* general output string */
- int Y; /* Y coordinate for text output */
- int Spacing; /* Spacing between lines */
- unsigned short i;
-
- errhWnd = hWnd;
- hDC = GetDC(hWnd); /* get display context */
- GetTextMetrics(hDC, (LPTEXTMETRIC)(&tm)); /* get font info */
- Spacing = tm.tmExternalLeading + tm.tmHeight; /* set up spacing */
- Y = 1; /* start at line 1 */
- if(dbproc == (DBPROCESS *)NULL) /* if process null, no results */
- {
- ReleaseDC(hWnd,hDC); /* free resources and return */
- return(TRUE);
- }
- SendMessage(hWnd,WM_ERASEBKGND,hDC,0L); /* always erase background */
- UpdateWindow(hWnd); /* force painting of window */
- DBLOCKLIB(); /* lock down library */
-
- /* Convert from OEM to ansi*/
- for (i=0 ; i < NROWS ; i++)
- {
- if (pstat[i] & FTC_SUCCEED)
- { /* Print only if fetch succeeded */
- OemToAnsi((LPSTR)(au_lname[i]), (LPSTR)(au_lname[i]));
- OemToAnsi((LPSTR)(au_fname[i]), (LPSTR)(au_fname[i]));
- OemToAnsi((LPSTR)(au_city[i]), (LPSTR)(au_city[i]));
- OemToAnsi((LPSTR)(au_state[i]), (LPSTR)(au_state[i]));
-
- /* here we format each field and write it to client */
- /* area checking to see if the client area needs to */
- /* be scrolled after each line is written */
- sprintf(szOutputString,"Last Name: %s",au_lname[i]);
- TextOut(hDC,1,Y,szOutputString,strlen(szOutputString));
- Y = CheckForScroll(hWnd,Y,Spacing,strlen(szOutputString) * tm.tmMaxCharWidth);
-
- sprintf(szOutputString,"First Name: %s",au_fname[i]);
- TextOut(hDC,1,Y,szOutputString,strlen(szOutputString));
- Y = CheckForScroll(hWnd,Y,Spacing,strlen(szOutputString) * tm.tmMaxCharWidth);
-
- sprintf(szOutputString,"City: %s, State: %s",au_city[i], au_state[i]);
- TextOut(hDC,1,Y,szOutputString,strlen(szOutputString));
- Y = CheckForScroll(hWnd,Y,Spacing,strlen(szOutputString) * tm.tmMaxCharWidth);
-
- Y = CheckForScroll(hWnd,Y,Spacing,0); /* add extra line */
- /* after each results */
- }
- else if (pstat[i] & FTC_MISSING)
- {
- sprintf(szOutputString,"Row %d is missing.", i+1);
- TextOut(hDC,1,Y,szOutputString,strlen(szOutputString));
- Y = CheckForScroll(hWnd,Y,Spacing,strlen(szOutputString) * tm.tmMaxCharWidth);
-
- Y = CheckForScroll(hWnd,Y,Spacing,0); /* add extra line */
- }
- }
-
- DBUNLOCKLIB(); /* unlock library */
- ReleaseDC(hWnd,hDC); /* free resource */
- return(TRUE);
- }
- /****************************************************************************
-
- FUNCTION: dbwinMessageHandler(DBPROCESS *, DBINT, DBSMALLINT, DBSMALLINT,
- LPSTR)
-
- PURPOSE: When the Data Server returns a message to dblib this function
- will be called to process that message. This function is
- installed into dblib via MakeProcInstance. It must be declared
- as a FAR cdecl function, not as a FAR PASCAL function, unlike
- other call back routines, as dblib conducts all of it's calls
- in the cdecl fashion. You must return 0 to dblib.
-
- RETURN: Return 0
-
- COMMENTS:
-
- ****************************************************************************/
-
- int FAR dbwinMessageHandler(dbproc, msgno, msgstate, severity, msgtext)
- DBPROCESS *dbproc;
- DBINT msgno;
- DBSMALLINT msgstate;
- DBSMALLINT severity;
- LPSTR msgtext;
- {
- MessageBox(errhWnd,msgtext,(LPSTR)"SQL DataServer Message",MB_OK);
- return(0);
- }
-
- /****************************************************************************
-
- FUNCTION: dbwinErrorHandler(DBPROCESS *, int, int, int, LPSTR, LPSTR)
-
- PURPOSE: When dblib returns an error message to the application this
- function will be called to process that error. This function is
- installed into dblib via MakeProcInstance. It must be declared
- as a FAR cdecl function, not as a FAR PASCAL function, unlike
- other call back routines, as dblib conducts all of it's calls
- in the cdecl fashion. You must return either INT_CANCEL,
- INT_CONTINUE, or INT_EXIT to dblib.
-
- RETURN: Return continuation code.
-
- COMMENTS:
-
- ****************************************************************************/
-
- int FAR dbwinErrorHandler(dbproc, severity, errno, oserr, dberrstr, oserrstr)
- DBPROCESS *dbproc;
- int severity;
- int errno;
- int oserr;
- LPSTR dberrstr;
- LPSTR oserrstr;
- {
- MessageBox(errhWnd,dberrstr,(LPSTR)"DB-LIBRARY error",MB_ICONHAND | MB_OK);
-
- if (oserr != DBNOERR) /* os error */
- {
- MessageBox(errhWnd,oserrstr,(LPSTR)"Operating-System error",MB_ICONHAND | MB_OK);
- }
-
- return(INT_CANCEL); /* cancel command */
- }
-