/**************************************************************************/ /*** SCICALC Scientific Calculator for Windows 3.00.12 ***/ /*** By Kraig Brockschmidt, Microsoft Co-op, Contractor, 1988-1989 ***/ /*** (c)1989 Microsoft Corporation. All Rights Reserved. ***/ /*** ***/ /*** scistat.c ***/ /*** ***/ /*** Functions contained: ***/ /*** SetStat--Enable/disable the stat box, show or destroy the ***/ /*** modeless dialog box. ***/ /*** StatBoxProc--procedure for the statbox. Handles the RET, LOAD, ***/ /*** CD, and CAD buttons, and handles double-clicks. ***/ /*** StatFunctions--routines for DATA, SUM, AVE, and deviations. ***/ /*** ***/ /*** Functions called: ***/ /*** SetStat, SetNumDisplay ***/ /*** ***/ /*** Last modification Thu 26-Jan-1990 ***/ /*** -by- Amit Chatterjee [amitc] 26-Jan-1990. ***/ /*** Following bug fix was made: ***/ /*** ***/ /*** Bug # 8499. ***/ /*** While fixing numbers in the stat array in memory, instead of using ***/ /*** the following for statement: ***/ /*** for (lIndex=lData; lIndex < lStatNum - 1 ; lIndex++) ***/ /*** the fix was to use: ***/ /*** for (lIndex=lData; lIndex < lStatNum ; lIndex++) ***/ /*** This is because lStatNum has already been decremented to care of ***/ /*** a number being deleted. ***/ /*** This fix will be in build 1.59. ***/ /**************************************************************************/ #include "scicalc.h" #define GMEMCHUNK 96L /* Amount of memory to allocate at a time. */ extern double fpNum; extern HWND hgWnd, hStatBox, hListBox, hEdit; extern BOOL bInv; extern TCHAR szfpNum[50], szBlank[6], *rgpsz[CSTRINGS]; extern HANDLE hInst; extern INT nTempCom; extern INT nInitShowWindow; extern BOOL gbRecord; GLOBALHANDLE hgMem, hMem; /* Coupla global memory handles. */ BOOL bFocus=TRUE; LONG lStatNum=0, /* Number of data. */ lReAllocCount; /* Number of data before ReAlloc. */ double FAR * lpfpStatNum, /* Holding place for stat data. */ FAR * lTemp; /* Temp pointer for some arithmetic. */ /* Initiate or destroy the Statistics Box. */ VOID APIENTRY SetStat (BOOL bOnOff) { static FARPROC lpfnList; /* Pointer to the procedure. */ if (bOnOff) { /* Create. */ lReAllocCount=GMEMCHUNK/sizeof(fpNum); /* Set up lReAllocCount. */ /* Start the box. */ lpfnList=MakeProcInstance((FARPROC)StatBoxProc, hInst); hStatBox=CreateDialog(hInst, TEXT("SB"), NULL, (WNDPROC)lpfnList); /* Get a handle on some memory (16 bytes initially. */ if (!(hgMem=GlobalAlloc(GHND, 0L))) { StatError(); //SendMessage(hStatBox, WM_COMMAND, ENDBOX, 0L); SendMessage(hStatBox, WM_COMMAND, GET_WM_COMMAND_MPS(ENDBOX, 0, 0)); return; } ShowWindow(hStatBox, SW_SHOWNORMAL); /* Set the indicator. */ SetDlgItemText(hgWnd, STATTEXT, rgpsz[IDS_STATFLAG]); } else { DestroyWindow(hStatBox); GlobalFree(hgMem); /* Free up the memory. */ hStatBox=0; /* Nullify handle. */ FreeProcInstance(lpfnList); SetDlgItemText(hgWnd, STATTEXT, szBlank); /* Nuke the indicator. */ } return; } /* Windows procedure for the Dialog Statistix Box. */ BOOL FAR APIENTRY StatBoxProc ( HWND hStatBox, UINT iMessage, WPARAM wParam, LONG lParam) { static LONG lData=-1; /* Data index in listbox. */ LONG lIndex; /* Temp index for counting. */ DWORD dwSize; /* Holding place for GlobalSize. */ switch (iMessage) { case WM_CLOSE: SetStat(FALSE); case WM_DESTROY: lStatNum=0L; /* Reset data count. */ return(TRUE); case WM_INITDIALOG: /* Get a handle to this here things listbox display. */ hListBox=GetDlgItem(hStatBox, STATLIST); return(nInitShowWindow != SW_SHOWMINNOACTIVE); case WM_COMMAND: /* Check for LOAD or double-click and recall number if so. */ // if (HIWORD(lParam)==LBN_DBLCLK || wParam==LOAD) // { // /* Lock data, get pointer to it, and get index of item. */ // lpfpStatNum=(double FAR *)GlobalLock(hgMem); // lData=SendMessage(hListBox,LB_GETCURSEL,0,0L); if (GET_WM_COMMAND_CMD(wParam, lParam)==LBN_DBLCLK || GET_WM_COMMAND_ID(wParam, lParam)==LOAD){ /* Lock data, get pointer to it, and get index of item. */ lpfpStatNum=(double FAR *)GlobalLock(hgMem); lData=SendMessage(hListBox,LB_GETCURSEL,0,0L); if (lStatNum>0 && lData !=LB_ERR) fpNum=*(lpfpStatNum+lData); /* Get the data. */ else MessageBeep(0); /* Cannodo if no data nor selection. */ /*SendMessage(hgWnd, WM_COMMAND, DISPFP, 0L);*/ // Cancel kbd input mode gbRecord = FALSE; DisplayNum (); nTempCom = 32; GlobalUnlock(hgMem); /* Let the memory move! */ break; } // switch (wParam) switch (GET_WM_COMMAND_ID(wParam, lParam)) { case FOCUS: /* Change focus back to main window. Primarily for */ /* use with the keyboard. */ SetFocus(hgWnd); return (TRUE); case CD: /* Clear the selected item from the listbox. */ /* Get the index and a pointer to the data. */ lData=SendMessage(hListBox,LB_GETCURSEL,0,0L); /* Check for possible error conditions. */ if (lData==LB_ERR || lData > lStatNum-1 || lStatNum==0) { MessageBeep (0); break; } /* Fix listbox strings. */ lIndex=SendMessage(hListBox, LB_DELETESTRING, (WORD)lData, 0L); if ((--lStatNum)==0) goto ClearItAll; /* Place the highlight over the next one. */ if (lData