home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************
- TIMER.C
- **********************************************************/
-
- /*********************************************************
- ** Copyright (c) MegaKnowledge 1990
- **********************************************************/
-
- /*********************************************************
- * THIS FILE CONTAINS AN EXAMPLE OF USING 'C' WITH KAPPA *
-
- See Also kappa.c kappa.def kappa.mak
- *********************************************************/
-
- #include "kappa.h"
- #include "timer.h"
-
- TIMERTABLE TimerTable[TABLESIZE];
-
- /*********************************************************
- TimerProc
- MS-WINDOWS callback function for our timers. Calls the KAPPA function
- 'ApplyFunction' to evalute the user KAL function set by 'SetupTimer'.
- *********************************************************/
- WORD FAR PASCAL TimerProc (HWND hWnd, WORD wMsg, int nEvent, DWORD dwTime)
- {
- int i;
- TIMERTABLE *pTmp;
- LISTID idList;
-
- for (i=0, pTmp = TimerTable; i<TABLESIZE; i++, pTmp++)
- if (pTmp->nEvent == nEvent)
- if (ApplyFunction (pTmp->idFunc, 0, NULLID) == ERROR)
- {
- PostKappaErrorMessage();
- return ERROR;
- }
-
- return TRUE;
- }
-
- /*********************************************************
- SetupTimer
- This function is registerd to KAPPA in the file 'kappa.c'.
- It can be called from KAL with 2 arguments:
- 1. Name of a KAL function
- 2. Timer interval (in milliseconds, greater than 100)
- It returns the MS-WINDOWS timer event identifier to be use
- with 'DeleteTimer'.
- *********************************************************/
- short SetupTimer (ARGLIST lpArgs)
- {
- short i;
- TIMERTABLE *pTmp;
- ATOMID idFunc;
- WORD wInterval;
- static FARPROC lpTimerProc = LPNULL;
-
- if (lpTimerProc == LPNULL)
- lpTimerProc = MakeProcInstance ((FARPROC) TimerProc, hInstKappa);
-
- KappaGetArgAtom (lpArgs, 1, idFunc);
- KappaGetArgInt (lpArgs, 2, wInterval);
-
- if (wInterval < 100)
- wInterval = 100;
-
- for (i=0, pTmp = TimerTable; i<TABLESIZE; i++, pTmp++)
- if (pTmp->nEvent == NULL)
- {
- pTmp->idFunc = idFunc;
- pTmp->nEvent = SetTimer (NULL, NULL, wInterval, lpTimerProc);
- KappaReturnInt (pTmp->nEvent);
- }
- KappaReturnFalse;
- }
-
- /*********************************************************
- SetupTimer
- This function is registerd to KAPPA in the file 'kappa.c'.
- It can be called from KAL with 1 arguments:
- 1. Timer event identifier as returned by 'SetupTimer'
- *********************************************************/
- short DeleteTimer (ARGLIST lpArgs)
- {
- short i;
- TIMERTABLE *pTmp;
- int nEvent;
-
- KappaGetArgInt (lpArgs, 1, nEvent);
-
- for (i=0, pTmp = TimerTable; i<TABLESIZE; i++, pTmp++)
- if (pTmp->nEvent == nEvent)
- {
- SetTimer (NULL, nEvent, NULL, NULL);
- pTmp->nEvent = NULL;
- pTmp->idFunc = NULLID;
- KappaReturnTrue;
- }
-
- KappaReturnFalse;
- }
-
-