cmsdataq.c
/*-------------------------------------------------------------------- CMSDATAQ.C -- CMS Data Aquisition window L. R. Erickson, Apr. 1994 -------------------------------------------------------------------*/ #include <windows.h> #include <stdio.h> #include <float.h> #include <math.h> #include <string.h> #include "cms.h" static cxMinSize, cyMinSize ; static cxDispChar, cyDispChar ; static iNumDispPts, iNumDispLines ; #define IDCNTL_SETUPBUTTON 100 //************* Start of CMSDataAcqWndProc ************************* long FAR PASCAL _export CMSDataAcqWndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam) { static HWND hwndClient, hwndFrame, hwndDispSetupButton ; static HMENU hMenuDataAcq, hMenuDataAcqWindow ; static FARPROC lpfnDataSetupDlgProc ; int i ; PAINTSTRUCT ps ; HDC hdc ; switch (message) { case WM_CREATE: // Save window handles hwndClient = GetParent (hwnd) ; hwndFrame = GetParent (hwndClient) ; lpfnDataSetupDlgProc = MakeProcInstance ((FARPROC) DataSetupDlgProc, globhCMSInst) ; hMenuDataAcq = LoadMenu (globhCMSInst, "CMSDataAcqMenu") ; hMenuDataAcqWindow = GetSubMenu (hMenuDataAcq, DATAACQ_MENU_POS) ; CalcMinSize () ; // Make a control button hwndDispSetupButton = CreateWindow ( globCntrlClass[CC_BUTTONINDEX], "DATA SETUP", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 21 * cxDispChar, ((iNumDispLines - 2) * cyDispChar) + (cyDispChar / 2), 12 * cxDispChar, (7 * globcyCharSpace) / 4, hwnd, IDCNTL_SETUPBUTTON, globhCMSInst, NULL) ; // Start other windows // PostMessage (hwndFrame, WM_COMMAND, ID_MAKEOPSWIN, 0L) ; return 0 ; case WM_MDIACTIVATE: // Set the Data Acquisition menu if gaining focus if (wParam == TRUE) SendMessage (hwndClient, WM_MDISETMENU, 0, MAKELONG (hMenuDataAcq, hMenuDataAcqWindow)) ; DrawMenuBar (hwndFrame) ; return 0 ; case WM_SIZE : ReSizeData (lParam) ; MoveWindow (hwndDispSetupButton, 21 * cxDispChar, ((iNumDispLines - 2) * cyDispChar) + (cyDispChar / 2), 12 * cxDispChar, (7 * globcyCharSpace) / 4, TRUE) ; break ; case WM_PAINT : hdc = BeginPaint (hwnd, &ps) ; for (i = 0 ; i < iNumDispPts ; i++) DrawDataPt(hwnd, i, hdc) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_COMMAND : switch (wParam) { case IDCNTL_SETUPBUTTON : if (DialogBox (globhCMSInst, "DataSetupDlgBox", hwnd, lpfnDataSetupDlgProc)) InvalidateRect (hwnd, NULL, TRUE) ; return 0 ; } return 0 ; case WM_DESTROY : DestroyMenu (hMenuDataAcq) ; return 0 ; } return DefMDIChildProc (hwnd, message, wParam, lParam) ; } //************* End of CMSDataAcqWndProc ************************* //****************** Start of DrawDataPt ************************* void DrawDataPt( HWND hwnd, int Point, HDC hdc) { RECT PtRect ; char szReadingBuf[8] ; PtRect.top = (Point / 3) * cyDispChar ; PtRect.bottom = PtRect.top + cyDispChar ; PtRect.left = ((Point % 3) * (18 * cxDispChar)) + cxDispChar ; PtRect.right = PtRect.left + (8 * cxDispChar) ; DrawText (hdc, (LPSTR) CMSData[CMSData[Point].disporder].displabel, 8, &PtRect, DT_NOCLIP | DT_SINGLELINE | DT_LEFT) ; PtRect.left = PtRect.right ; PtRect.right = PtRect.left + (8 * cxDispChar) ; if ((CMSData[Point].reading < 999) && (CMSData[Point].reading > -999)) { _snprintf (szReadingBuf, 7, "%5.2f", CMSData[Point].reading ) ; } else { strcpy ( szReadingBuf, "RNGERR") ; } DrawText (hdc, szReadingBuf, -1, &PtRect, DT_NOCLIP | DT_SINGLELINE | DT_RIGHT) ; } //****************** End of DrawDataPt ************************* //****************** Start of CalcMinSize ************************ void CalcMinSize (void) { cxMinSize = globcxCharSpace * 54 ; iNumDispPts = 0 ; while (CMSData[iNumDispPts].disporder < 999) iNumDispPts ++ ; iNumDispLines = ((iNumDispPts + 2) / 3) + 2 ; cyMinSize = iNumDispLines * globcyCharSpace ; } //****************** End of CalcMinSize ************************ //****************** Start of ResizeData ************************ void ReSizeData (LONG lParam) { if ((int) LOWORD (lParam) <= cxMinSize) cxDispChar = globcxCharSpace ; else cxDispChar = (int) (((LONG) globcxCharSpace * (LONG) LOWORD (lParam)) / (LONG) cxMinSize) ; if ((int) HIWORD (lParam) <= cyMinSize) cyDispChar = globcyCharSpace ; else cyDispChar = (int) (((LONG) globcyCharSpace * (LONG) HIWORD (lParam)) / (LONG) cyMinSize) ; } //****************** End of ResizeData ************************ //****************** Start of DataSetupDlgProc ************************ BOOL FAR PASCAL _export DataSetupDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam) { switch (message) { case WM_INITDIALOG : LoadPtList (hDlg) ; return TRUE ; case WM_COMMAND : switch (wParam) { case ID_DISPDLGEXIT : EndDialog (hDlg, 0) ; return TRUE ; } break ; } return FALSE ; } //****************** End of DataSetupDlgProc ************************ //******************* Start of LoadPtList ********************** void LoadPtList (HWND hwnd) { int i ; HWND hwndList ; hwndList = GetDlgItem(hwnd, ID_DISPDLGPT) ; for (i = 0 ; i < iNumDataPts ; i++) SendMessage ( hwndList, CB_ADDSTRING, 0, (LONG) (LPSTR) CMSData[i].instru) ; } //******************* End of LoadPtList **********************