home *** CD-ROM | disk | FTP | other *** search
- /* Example3.c -- demonstration */
-
- #include <windows.h>
- #include <dos.h>
- #include <time.h>
- #include "pv.h"
- #include "exampl3a.h"
- #include "exampl3b.h"
- #include "exampl3c.h"
- #include "string.h"
- #include "stdlib.h"
-
- HANDLE key;
- HDC hDC;
- VIEWPROC lpfnMainWndProc;
- LONG FAR PASCAL MainWndProc(HWND, WORD, WORD, LONG);
-
- TEXTMETRIC tmFontInfo; // Font information for signon screen
- LOGFONT lfNewFont;
- HANDLE hTitleFont, hOldFont, hTitleTextFont;
- RECT rect;
- int xWidth, yHeight;
-
- VIEW DeskTop; // Background window
- VIEW Insure1; // Signon screen
- VIEW insure2; // Address information screen
- VIEW insure3; // Policy information screen
- HWND hWndDeskTop; // Window handles
- HWND hWndInsure1;
- HWND hWndinsure2;
- HWND hWndinsure3;
- HANDLE hInst; // Global module instance handle
-
- struct tm *pTime; // tm structure for date comparisons
- long ltime;
- int Okay = FALSE; // Signifies when WM_SIZE and WM_MOVE messages
- // should move the two data input screens.
- // Only after signon is completed. Okay = TRUE.
-
- RECT Rect; // Used for resizing data input screens
- POINT Point;
-
- int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
- HANDLE hInstance, hPrevInstance;
- LPSTR lpszCmdLine;
- int nCmdShow;
- {
- static char szAppName[] = "insure1";
- MSG msg;
-
- hInst = hInstance;
- time(<ime);
- pTime = gmtime(<ime);
- v3StartDate = *pTime;
- v3EndDate = *pTime;
- v3EndDate.tm_year++;
-
- /* Prepare View Proc for UserId and Password Screen */
- lpfnInsure1ViewProc = (VIEWPROC)MakeProcInstance((FARPROC)Insure1ViewProc, hInstance);
- lpfnMainWndProc = (VIEWPROC)MakeProcInstance((FARPROC)MainWndProc, hInstance);
-
- /* Prepare Field Procs */
- lpfnLastNameFieldProc = (FIELDPROC)MakeProcInstance((FARPROC)LastNameFieldProc, hInstance);
- lpfnFirstNameFieldProc = (FIELDPROC)MakeProcInstance((FARPROC)FirstNameFieldProc, hInstance);
- lpfnMidInitFieldProc = (FIELDPROC)MakeProcInstance((FARPROC)MidInitFieldProc, hInstance);
- lpfnUserIDFieldProc = (FIELDPROC)MakeProcInstance((FARPROC)UserIDFieldProc, hInstance);
- lpfnPasswordFieldProc = (FIELDPROC)MakeProcInstance((FARPROC)PasswordFieldProc, hInstance);
- lpfnStartDateFieldProc = (FIELDPROC)MakeProcInstance((FARPROC)StartDateFieldProc, hInstance);
- lpfnEndDateFieldProc = (FIELDPROC)MakeProcInstance((FARPROC)EndDateFieldProc, hInstance);
-
- lpfnMakeLongPointer = MakeProcInstance(MakeLongPointer, hInstance);
-
-
- // Create Background window
- DeskTop = vwOpenView(hInstance,
- "Example3.exe",
- WS_VISIBLE | WS_OVERLAPPEDWINDOW | WS_MAXIMIZE,
- NULL,
- lpfnMainWndProc,
- lpfnMakeLongPointer);
-
- vwSetViewIcon(DeskTop, LoadIcon(hInstance, "Example3")); // Attach an icon
- hWndDeskTop = vwShowView(DeskTop); // Display
-
-
- /* Open User ID and Password entry screen */
- Insure1 = vwCreateView(hInstance,
- "Insure1",
- hWndDeskTop,
- lpfnInsure1ViewProc,
- lpfnMakeLongPointer);
-
-
- // Set up application variables and fieldprocs for both fields
- vwSetFieldVar(Insure1, 1, v1UserID);
- vwSetFieldVar(Insure1, 2, v1Password);
- vwSetFieldVar(Insure1, 7, &v2Okay);
- vwSetFieldProc(Insure1, 1, lpfnUserIDFieldProc);
- vwSetFieldProc(Insure1, 2, lpfnPasswordFieldProc);
-
-
-
-
- /* Open Name and Address entry screen */
- insure2 = vwCreateView(hInstance,
- "insure2",
- hWndDeskTop,
- lpfnInsure1ViewProc,
- lpfnMakeLongPointer);
-
- // Setup application variables for all fields
- vwSetFieldVar(insure2, 1, v2LastName);
- vwSetFieldVar(insure2, 2, v2FirstName);
- vwSetFieldVar(insure2, 3, v2MidInit);
- vwSetFieldVar(insure2, 4, v2Street);
- vwSetFieldVar(insure2, 5, v2City);
- vwSetFieldVar(insure2, 6, v2State);
- vwSetFieldVar(insure2, 7, v2Zipcode);
- vwSetFieldVar(insure2, 8, v2Telephone);
- vwSetFieldVar(insure2, 9, &v2Okay);
- vwSetFieldVar(insure2, 10, &v2Cancel);
-
- // Set up field procs for First, Last and Middle name fields
- // As the user moves through each of these fields, the name field on
- // the Policy input screen is dynamically updated to reflect the part
- // of the name entered. When all three are entered, the color of this
- // field on the policy screen is changed to rgbWHITE on rgbBLACK.
-
- vwSetFieldProc(insure2, 1, lpfnLastNameFieldProc);
- vwSetFieldProc(insure2, 2, lpfnFirstNameFieldProc);
- vwSetFieldProc(insure2, 3, lpfnMidInitFieldProc);
-
- /* Add color to the two button fields */
- vwSetFieldColors(insure2, 9, rgbBLUE, rgbGREEN, 0L, 0L);
- vwSetFieldColors(insure2, 10, rgbWHITE, rgbRED, 0L, 0L);
-
-
- /* Open Policy information screen */
- insure3 = vwCreateView(hInstance,
- "insure3",
- hWndDeskTop,
- lpfnInsure1ViewProc,
- lpfnMakeLongPointer);
-
- /* Set up application variables */
- vwSetFieldVar(insure3, 1, v3Name);
- vwSetFieldVar(insure3, 2, v3Policy);
- vwSetFieldVar(insure3, 3, &v3StartDate);
- vwSetFieldVar(insure3, 4, &v3EndDate);
- vwSetFieldVar(insure3, 5, &v3Coverage);
- vwSetFieldVar(insure3, 6, &v3Premium);
- vwSetFieldVar(insure3, 7, &v2Okay);
- vwSetFieldVar(insure3, 8, &v2Cancel);
-
- // Initialize application date fields to today's data and 1 year from
- // today
- time(<ime);
- pTime = gmtime(<ime);
- v3EndDate = v3StartDate = *pTime;
- v3EndDate.tm_year++;
-
- // Set up field procs for date fields for date checking
- vwSetFieldProc(insure3, 3, lpfnStartDateFieldProc);
- vwSetFieldProc(insure3, 4, lpfnEndDateFieldProc);
-
- // Add color to the two button fields
- vwSetFieldColors(insure3, 7, rgbBLUE, rgbGREEN, 0L, 0L);
- vwSetFieldColors(insure3, 8, rgbWHITE, rgbRED, 0L, 0L);
-
- // Temporarily turn off editing in each view as they are being
- // initially displayed. This prevents errors from being detected
- // before the user has had a chance to input data as the input focus
- // changes from view to view as they are displayed.
-
- vwSetViewEditingOff(Insure1);
- vwSetViewEditingOff(insure2);
- vwSetViewEditingOff(insure3);
-
- // Show Views from back to front for layered appearance
- hWndinsure3 = vwShowView(insure3);
- hWndinsure2 = vwShowView(insure2);
-
-
- // Obtain the text metrics for the system font and
- // modify various parameters to indirectly create two new fonts
- hDC = GetDC(hWndinsure3);
- GetTextMetrics(hDC, &tmFontInfo);
- memset( &lfNewFont, 0, sizeof (LOGFONT));
-
- // Change the height, width, weight, facename, pitch and family
- xWidth = tmFontInfo.tmAveCharWidth;
- yHeight = tmFontInfo.tmHeight + tmFontInfo.tmExternalLeading;
- lfNewFont.lfHeight = tmFontInfo.tmHeight * 2;
- lfNewFont.lfPitchAndFamily = FF_ROMAN;
- lfNewFont.lfWeight = 500;
- strcpy(lfNewFont.lfFaceName, "TMSRE");
-
- hTitleFont = CreateFontIndirect (&lfNewFont);
-
- // Set the height back to normal size for other text
- lfNewFont.lfHeight = tmFontInfo.tmHeight;
- hTitleTextFont = CreateFontIndirect (&lfNewFont);
- ReleaseDC(hWndinsure3, hDC);
-
- // Add text fields to the view dynamically using the new fonts
- vwSetTextField(Insure1, -1, 5, "Confidence Insurance Co.", hTitleFont);
- vwSetTextField(Insure1, -1, 25,
- "ProtoView Demonstration by ProtoView Development Co.", hTitleTextFont);
-
- // Show the UserID, Password entry screen
- hWndInsure1 = vwShowView(Insure1);
-
- // Turn on editing for all of the views
- vwSetViewEditingOn(Insure1);
- vwSetViewEditingOn(insure2);
- vwSetViewEditingOn(insure3);
-
- while(GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- FreeProcInstance((FARPROC)LastNameFieldProc);
- FreeProcInstance((FARPROC)FirstNameFieldProc);
- FreeProcInstance((FARPROC)MidInitFieldProc);
- FreeProcInstance((FARPROC)UserIDFieldProc);
- FreeProcInstance((FARPROC)PasswordFieldProc);
- FreeProcInstance((FARPROC)StartDateFieldProc);
- FreeProcInstance((FARPROC)EndDateFieldProc);
- FreeProcInstance(MakeLongPointer);
- DeleteObject(hTitleFont);
- DeleteObject(hTitleTextFont);
-
- return msg.wParam;
- }
-
- // All three views, insure1, insure2 and insure3 use this function for the viewproc.
- // Its purpose is process Okay and Cancel button clicks.
- long FAR PASCAL Insure1ViewProc(HWND hWnd, WORD wMessage, WORD wParam, LONG lParam)
- {
- GETVIEW;
- switch(wMessage)
- {
- case WM_COMMAND :
- if(wParam == vwGetFieldNo(View, &v2Okay))
- if(!vwEditView(View) && (View == Insure1))
- {
- Point.x = Point.y = 0;
- ClientToScreen(hWndDeskTop, &Point);
- GetClientRect(hWndDeskTop, &Rect);
- Rect.left = Point.x;
- Rect.top = Point.y;
- if(IsWindow(hWndinsure2))
- MoveWindow(hWndinsure2, Rect.left,
- Rect.top,
- Rect.right,
- Rect.bottom / 2, TRUE);
- if(IsWindow(hWndinsure3))
- MoveWindow(hWndinsure3, Rect.left,
- (Rect.bottom / 2) + Rect.top,
- Rect.right,
- Rect.bottom / 2, TRUE);
- vwHideView(Insure1);
- Okay = TRUE;
- return(0);
- }
- return 0;
- if(wParam == vwGetFieldNo(View, &v2Cancel))
- return 0;
- }
- return DefViewProc(hWnd, wMessage, wParam, lParam);
- }
-
-
- long FAR PASCAL MainWndProc(HWND hWnd, WORD wMessage, WORD wParam, LONG lParam)
- {
- GETVIEW;
- switch(wMessage)
- {
- /* If this view gets destroyed, Destroy the others as well */
- case WM_MOVE :
- case WM_SIZE :
- if(Okay && IsWindow(hWndinsure2) && IsWindow(hWndinsure3))
- {
- Point.x = Point.y = 0;
- ClientToScreen(hWndDeskTop, &Point);
- GetClientRect(hWndDeskTop, &Rect);
- Rect.left = Point.x;
- Rect.top = Point.y;
- MoveWindow(hWndinsure2, Rect.left,
- Rect.top,
- Rect.right,
- Rect.bottom / 2, TRUE);
- MoveWindow(hWndinsure3, Rect.left,
- (Rect.bottom / 2) + Rect.top,
- Rect.right,
- Rect.bottom / 2, TRUE);
- }
- break;
- case WM_DESTROY :
- PostQuitMessage(0);
- }
- return DefViewProc(hWnd, wMessage, wParam, lParam);
- }
-
- long FAR PASCAL UserIDFieldProc(HWND hWnd, WORD wMessage, WORD wParam, LONG lParam)
- {
- char szBuffer[50];
- VIEW View = vwGetView(hWnd);
- VWFIELD Field = GetWindowWord(hWnd, GWW_ID);
- switch(wMessage)
- {
- case WM_KILLFOCUS :
- /* When the user tries to leave the userid field, check to see if
- * the proper userid has been entered.
- * If it has not, then set the view error status to ViewScope */
-
- GetWindowText(hWnd, szBuffer, 40);
- if(lstricmp("Smith", szBuffer))
- vwSetViewError(View, Field,
- " Invalid User ID. Valid ID: SMITH", VE_APPSCOPE);
- return(vwGetDefFieldProc(View, Field)(hWnd, wMessage, wParam, lParam));
- break;
-
- default :
- return (vwGetDefFieldProc(View, Field)(hWnd, wMessage, wParam, lParam));
- }
- return 0L;
- }
-
- long FAR PASCAL PasswordFieldProc(HWND hWnd, WORD wMessage, WORD wParam, LONG lParam)
- {
- char szBuffer[50];
- static int ItemSelected;
- VIEW View = vwGetView(hWnd);
- VWFIELD Field = GetWindowWord(hWnd, GWW_ID);
- switch(wMessage)
- {
-
- case WM_KILLFOCUS :
- /* When the user tries to leave the password field, check to see if
- * the proper password has been entered.
- * If it has not, then set the view error status to ViewScope */
- GetWindowText(hWnd, szBuffer, 40);
- if(lstricmp("Tree", szBuffer))
- vwSetViewError(View, Field,
- " Invalid User Password. Valid Password: TREE", VE_VIEWSCOPE | VE_POPUP);
- return (vwGetDefFieldProc(View, Field)(hWnd, wMessage, wParam, lParam));
- break;
- default :
- return (vwGetDefFieldProc(View, Field)(hWnd, wMessage, wParam, lParam));
- }
- return 0L;
- }
-
- long FAR PASCAL StartDateFieldProc(HWND hWnd, WORD wMessage, WORD wParam, LONG lParam)
- {
- int error = FALSE;
- int Current;
- VIEW View = vwGetView(hWnd);
- VWFIELD Field = GetWindowWord(hWnd, GWW_ID);
- switch(wMessage)
- {
- case WM_KILLFOCUS :
- vwDoScrToApp(View, Field);
- vwDoScrToApp(View, Field + 1);
- if(v3StartDate.tm_year > v3EndDate.tm_year)
- error = TRUE;
- else
- if(v3StartDate.tm_year == v3EndDate.tm_year)
- if(v3StartDate.tm_mon > v3EndDate.tm_mon)
- error = TRUE;
- else
- if(v3StartDate.tm_year == v3EndDate.tm_year)
- if(v3StartDate.tm_mon == v3EndDate.tm_mon)
- if(v3StartDate.tm_mday > v3EndDate.tm_mday)
- error = TRUE;
- if(error)
- vwSetViewError(View, Field,
- " Start Date cannot be greater than End Date", VE_VIEWSCOPE | VE_POPUP);
-
- default :
- return (vwGetDefFieldProc(View, Field)(hWnd, wMessage, wParam, lParam));
- }
- return 0L;
- }
-
- long FAR PASCAL EndDateFieldProc(HWND hWnd, WORD wMessage, WORD wParam, LONG lParam)
- {
- int error = FALSE;
- VIEW View = vwGetView(hWnd);
- VWFIELD Field = GetWindowWord(hWnd, GWW_ID);
- switch(wMessage)
- {
- case WM_KILLFOCUS :
- vwDoScrToApp(View, Field);
- vwDoScrToApp(View, Field - 1 );
- if(v3StartDate.tm_year > v3EndDate.tm_year)
- error = TRUE;
- else
- if(v3StartDate.tm_year == v3EndDate.tm_year)
- if(v3StartDate.tm_mon > v3EndDate.tm_mon)
- error = TRUE;
- else
- if(v3StartDate.tm_year == v3EndDate.tm_year)
- if(v3StartDate.tm_mon == v3EndDate.tm_mon)
- if(v3StartDate.tm_mday > v3EndDate.tm_mday)
- error = TRUE;
- if(error)
- vwSetViewError(View, Field,
- " End Date cannot be less than Start Date", VE_VIEWSCOPE | VE_POPUP);
-
- default :
-
- return (vwGetDefFieldProc(View, Field)(hWnd, wMessage, wParam, lParam));
- }
- return 0L;
- }
-
- long FAR PASCAL LastNameFieldProc(HWND hWnd, WORD wMessage, WORD wParam, LONG lParam)
- {
- static char szBuffer[60];
- char Buff[60];
- VIEW View = vwGetView(hWnd);
- VWFIELD Field = GetWindowWord(hWnd, GWW_ID);
- switch(wMessage)
- {
- case WM_KILLFOCUS :
- GetWindowText(vwGetFieldWindow(View, Field), szBuffer, 40);
- if(!strlen(szBuffer))
- vwSetViewError(View, Field,
- " Please enter a Name", VE_APPSCOPE | VE_POPUP);
- GetWindowText(vwGetFieldWindow(View, 2), szBuffer, 40);
- lstrcat(szBuffer, " ");
- GetWindowText(vwGetFieldWindow(View, 3), Buff, 40);
- lstrcat(szBuffer, Buff);
- lstrcat(szBuffer, " ");
- GetWindowText(vwGetFieldWindow(View, 1), Buff, 40);
- lstrcat(szBuffer, Buff);
- lstrcpy(v3Name, szBuffer);
-
- if(insure3)
- {
- vwDoAppToScr(insure3, 1);
- }
- default :
- return (vwGetDefFieldProc(View, Field)(hWnd, wMessage, wParam, lParam));
- }
- return 0L;
- }
-
- long FAR PASCAL FirstNameFieldProc(HWND hWnd, WORD wMessage, WORD wParam, LONG lParam)
- {
- static char szBuffer[60];
- char Buff[60];
- VIEW View = vwGetView(hWnd);
- VWFIELD Field = GetWindowWord(hWnd, GWW_ID);
- switch(wMessage)
- {
- case WM_KILLFOCUS :
- GetWindowText(vwGetFieldWindow(View, 2), szBuffer, 40);
- lstrcat(szBuffer, " ");
- GetWindowText(vwGetFieldWindow(View, 3), Buff, 40);
- lstrcat(szBuffer, Buff);
- lstrcat(szBuffer, " ");
- GetWindowText(vwGetFieldWindow(View, 1), Buff, 40);
- lstrcat(szBuffer, Buff);
- lstrcpy(v3Name, szBuffer);
-
- if(insure3)
- {
- vwDoAppToScr(insure3, 1);
- }
- default :
- return (vwGetDefFieldProc(View, Field)(hWnd, wMessage, wParam, lParam));
- }
- return 0L;
- }
-
- long FAR PASCAL MidInitFieldProc(HWND hWnd, WORD wMessage, WORD wParam, LONG lParam)
- {
- static char szBuffer[60];
- char Buff[60];
- static int sw = FALSE;
- VIEW View = vwGetView(hWnd);
- VWFIELD Field = GetWindowWord(hWnd, GWW_ID);
- switch(wMessage)
- {
- case WM_KILLFOCUS :
- GetWindowText(vwGetFieldWindow(View, 2), szBuffer, 40);
- lstrcat(szBuffer, " ");
- GetWindowText(vwGetFieldWindow(View, 3), Buff, 40);
- lstrcat(szBuffer, Buff);
- lstrcat(szBuffer, " ");
- GetWindowText(vwGetFieldWindow(View, 1), Buff, 40);
- lstrcat(szBuffer, Buff);
- lstrcpy(v3Name, szBuffer);
-
- if(insure3)
- {
- vwDoAppToScr(insure3, 1);
- }
- if(!sw)
- {
- vwSetFieldColors(insure3, 1, rgbWHITE, rgbBLACK, rgbBLACK, rgbWHITE);
- vwPaintField(insure3, 1);
- sw =TRUE;
- }
-
- default :
- return (vwGetDefFieldProc(View, Field)(hWnd, wMessage, wParam, lParam));
- }
- return 0L;
- }
-
-
-
- BOOL FAR PASCAL MakeLongPointer()
- {
- static void far *Ptr;
- Ptr = &Ptr;
- return(FP_SEG(Ptr));
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-