/**************************************************************************/ /*** 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 ***/ /*** ***/ /*** 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" #include "calchelp.h" #include "unifunc.h" #define GMEMCHUNK 96L /* Amount of memory to allocate at a time. */ extern HNUMOBJ ghnoNum; extern HWND hStatBox, hListBox, hEdit; extern TCHAR szBlank[6], *rgpsz[CSTRINGS]; extern LPTSTR gpszNum; extern INT nTempCom; extern BOOL gbRecord; extern BOOL FireUpPopupMenu( HWND, HINSTANCE, LPARAM ); GLOBALHANDLE hgMem, hMem; /* Coupla global memory handles. */ BOOL bFocus=TRUE; LONG lStatNum=0, /* Number of data. */ lReAllocCount; /* Number of data before ReAlloc. */ HNUMOBJ * lphnoStatNum; /* Holding place for stat data. */ /* Initiate or destroy the Statistics Box. */ VOID APIENTRY SetStat (BOOL bOnOff) { static int aStatOnlyKeys[] = { IDC_AVE, IDC_B_SUM, IDC_DEV, IDC_DATA }; int i; if (bOnOff) { /* Create. */ lReAllocCount=GMEMCHUNK/sizeof(ghnoNum); /* Set up lReAllocCount. */ /* Start the box. */ hStatBox=CreateDialog(hInst, MAKEINTRESOURCE(IDD_SB), NULL, StatBoxProc); /* Get a handle on some memory (16 bytes initially. */ if (!(hgMem=GlobalAlloc(GHND, 0L))) { StatError(); SendMessage(hStatBox, WM_COMMAND, GET_WM_COMMAND_MPS(ENDBOX, 0, 0)); return; } ShowWindow(hStatBox, SW_SHOWNORMAL); } else { int lIndex; if ( hStatBox ) { DestroyWindow(hStatBox); // Free the numobj's lphnoStatNum=(HNUMOBJ *)GlobalLock(hgMem); for( lIndex = 0; lIndex < lStatNum; lIndex++ ) NumObjDestroy( &lphnoStatNum[lIndex] ); GlobalUnlock(hgMem); lStatNum = 0; GlobalFree(hgMem); /* Free up the memory. */ hStatBox=0; /* Nullify handle. */ } } // set the active state of the Ave, Sum, s, and Dat buttons for ( i=0; iiCtrlId); WinHelp( hwndChild, rgpsz[IDS_HELPFILE], HELP_WM_HELP, (ULONG_PTR)(void *)control ); return TRUE; } case WM_CONTEXTMENU: WinHelp( (HWND)wParam, rgpsz[IDS_HELPFILE], HELP_CONTEXTMENU, (ULONG_PTR)(void *)control ); return TRUE; 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, IDC_STATLIST); return TRUE; case WM_COMMAND: /* Check for LOAD or double-click and recall number if so. */ if (GET_WM_COMMAND_CMD(wParam, lParam)==LBN_DBLCLK || GET_WM_COMMAND_ID(wParam, lParam)==IDC_LOAD) { /* Lock data, get pointer to it, and get index of item. */ lphnoStatNum=(HNUMOBJ *)GlobalLock(hgMem); lData=(LONG)SendMessage(hListBox,LB_GETCURSEL,0,0L); if (lStatNum>0 && lData !=LB_ERR) // SPEED: REVIEW: can we use a pointer instead of Assign? NumObjAssign( &ghnoNum, lphnoStatNum[lData]); /* Get the data. */ else MessageBeep(0); /* Cannodo if no data nor selection. */ // 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 IDC_FOCUS: /* Change focus back to main window. Primarily for */ /* use with the keyboard. */ SetFocus(g_hwndDlg); return (TRUE); case IDC_CD: /* Clear the selected item from the listbox. */ /* Get the index and a pointer to the data. */ lData=(LONG)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=(LONG)SendMessage(hListBox, LB_DELETESTRING, (WORD)lData, 0L); if ((--lStatNum)==0) goto ClearItAll; /* Place the highlight over the next one. */ if (lData