home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / desqview / taskman.arc / TASKMAN.BAS < prev    next >
Encoding:
BASIC Source File  |  1989-03-16  |  9.3 KB  |  415 lines

  1. DECLARE SUB PopUp ()
  2. DECLARE SUB ScrapTop ()
  3. DECLARE FUNCTION WhoIsTop% ()
  4. DECLARE SUB LogTop (slot%)
  5. DECLARE FUNCTION FindFreeSlot% ()
  6. DECLARE SUB ClearUp ()
  7. DECLARE SUB DisableKbd ()
  8. DECLARE SUB ShowSwitchMenu ()
  9. DECLARE SUB CloseAuxWin ()
  10. DECLARE SUB RestoreMainMenu ()
  11. DECLARE SUB ProcessKey ()
  12. DECLARE SUB PopDown ()
  13. DECLARE SUB ProcessMail ()
  14. DECLARE SUB Initialize ()
  15. DECLARE SUB ProgramBody ()
  16.  
  17. '***************************************************************************
  18. '*
  19. '*  Name:               TASKMAN
  20. '*
  21. '*  Function:           Replace the DESQview menu with a customized
  22. '*                      task manager.
  23. '*
  24. '***************************************************************************
  25.  
  26. ' $INCLUDE: 'dvapi.bi'
  27.  
  28. TYPE TaskData
  29. Handle AS LONG
  30. Title AS STRING * 23
  31. Position AS INTEGER
  32. END TYPE
  33.  
  34.  
  35. ' minimum API version required and actual API version
  36. CONST required = &H201
  37. DIM version AS INTEGER
  38.                      
  39. ' Object handles
  40. DIM SHARED win&, kbd&, pan&, obj&, mal&, auxwin&, auxkbd&, myapp&
  41.  
  42. ' Constants
  43. CONST YES = -1
  44. CONST NO = 0
  45. CONST MAINMENU = 1
  46. CONST OPENMENU = 2
  47. CONST SWITCHMENU = 3
  48. CONST CLOSECONFIRM = 4
  49. CONST EXITCONFIRM = 5
  50. CONST HELPSCREEN = 6
  51. CONST OPENERROR = 7
  52. CONST OPENMAX = 8
  53.  
  54. ' Variables
  55. DIM SHARED PoppedUp%, CurrentMenu%, Done%, MenuField%, NumProg%
  56. DIM SHARED TaskList%(3)
  57. DIM SHARED TaskInfo(4) AS TaskData
  58. DIM SHARED PifName$(2)
  59. DIM SHARED Fentry AS FieldEntry
  60.  
  61. ' Data Statements
  62. DATA "c:\taskman\sd-pif.dvp"
  63. DATA "c:\taskman\ss-pif.dvp"
  64.  
  65. '***************************************************************************
  66. ' Main Module - check for DESQview present and enable required extensions
  67. '***************************************************************************
  68.  
  69. ' Initialize DESQview interface and get API version number
  70. version = ApiInit%
  71.  
  72. ' If DESQview is not running or version is too low, display a message
  73. IF version < required THEN
  74.   OPEN "CONS:" FOR OUTPUT AS 1
  75.   PRINT #1, USING "This program requires DESQview version #.##"; required \ 256 + (required MOD 256) / 100
  76.   CLOSE 1
  77. ELSE
  78.   ' Tell DESQview what extensions to enable and start application
  79.   CALL ApiLevel(required)
  80.   CALL ProgramBody
  81. END IF
  82.  
  83. ' Disable DESQview interface and return from program
  84. CALL ApiExit
  85.  
  86. SUB ClearUp
  87.  
  88. CALL KeyFree(kbd&)
  89. CALL WinFree(win&)
  90.  
  91. CALL WinAllow(myapp&, AlwDvmenu)
  92. CALL WinCancel(myapp&, NtfDvkey)
  93.  
  94. END SUB
  95.  
  96. SUB CloseAuxWin
  97.  
  98. CALL KeyFree(auxkbd&)
  99. CALL WinFree(auxwin&)
  100. CALL ObqSubfrom(auxkbd&)
  101.  
  102. END SUB
  103.  
  104. SUB DisableKbd
  105.  
  106. CALL KeyClose(kbd&)
  107. CALL ObqSubfrom(kbd&)
  108.  
  109. END SUB
  110.  
  111. FUNCTION FindFreeSlot%
  112.  
  113. FindFreeSlot% = 0
  114.  
  115. FOR i = 2 TO 4
  116.   IF TaskInfo(i).Handle = 0 THEN
  117.     FindFreeSlot% = i
  118.     EXIT FOR
  119.   END IF
  120. NEXT i
  121.  
  122. END FUNCTION
  123.  
  124. SUB Initialize
  125.  
  126. IF NOT ApiInteractive THEN
  127.   CALL WinHide(WinMe&)
  128.   CALL WinRedraw(WinMe&)
  129. END IF
  130.  
  131. myapp& = TskMe&
  132. pan& = PanNew&
  133. mal& = MalMe&
  134.  
  135. READ PifName$(1), PifName$(2)
  136.  
  137. FOR i = 2 TO 4
  138.   TaskInfo(i).Position = 99
  139. NEXT i
  140.  
  141. stat% = PanOpen%(pan&, "c:\taskman\taskman.plb")
  142. stat% = PanApply%(pan&, WinMe&, "menubar", win&, kbd&)
  143.  
  144. CALL FldType(win&, 3, FltInactive)
  145.  
  146. PoppedUp% = YES
  147. CurrentMenu% = MAINMENU
  148.  
  149. CALL WinDisallow(myapp&, AlwDvmenu)
  150. CALL WinNotify(myapp&, NtfDvkey)
  151.  
  152. CALL ObqOpen
  153.  
  154. Done% = NO
  155.  
  156. END SUB
  157.  
  158. SUB LogTop (slot%)
  159.  
  160.  
  161. IF TaskInfo(slot%).Position <> 1 THEN
  162.   breakslot% = TaskInfo(slot%).Position
  163.   TaskInfo(slot%).Position = 1
  164.  
  165.   FOR i = 2 TO 4
  166.     IF i <> slot% AND TaskInfo(i).Handle <> 0 AND TaskInfo(i).Position < breakslot% THEN
  167.       TaskInfo(i).Position = TaskInfo(i).Position + 1
  168.     END IF
  169.   NEXT i
  170. END IF
  171.  
  172. END SUB
  173.  
  174. SUB PopDown
  175.  
  176. CALL AppHide(myapp&)
  177. PoppedUp% = NO
  178.  
  179. END SUB
  180.  
  181. SUB PopUp
  182.  
  183. CALL AppGoFore(myapp&)
  184. CALL KeyErase(kbd&)
  185. CALL FldPoint(win&, MenuField%, 0, 0)
  186.  
  187. PoppedUp% = YES
  188.  
  189. END SUB
  190.  
  191. SUB ProcessKey
  192.  
  193. IF obj& = kbd& THEN
  194.   kbuf$ = KeyRead$(kbd&)
  195.   kstat% = KeyStatus(kbd&)
  196. ELSE
  197.   kbuf$ = KeyRead$(auxkbd&)
  198.   kstat% = KeyStatus(auxkbd&)
  199. END IF
  200.  
  201. IF LEN(kbuf$) > 0 THEN selfield% = ASC(kbuf$) ELSE selfield% = 0
  202.  
  203. SELECT CASE CurrentMenu%
  204.   CASE MAINMENU
  205.     SELECT CASE selfield%
  206.       CASE 0
  207.         IF NumProg% <> 0 THEN CALL PopDown
  208.       CASE 1
  209.         errstat% = PanApply%(pan&, win&, "open", auxwin&, auxkbd&)
  210.         CurrentMenu% = OPENMENU
  211.         CALL DisableKbd
  212.       CASE 2
  213.         CALL DisableKbd
  214.         CALL ShowSwitchMenu
  215.         CurrentMenu% = SWITCHMENU
  216.       CASE 3
  217.         errstat% = PanApply%(pan&, win&, "close", auxwin&, auxkbd&)
  218.         CALL FldWrite(auxwin&, 3, RIGHT$(STR$(WhoIsTop%), 1))
  219.         CurrentMenu% = CLOSECONFIRM
  220.         CALL DisableKbd
  221.       CASE 4
  222.         errstat% = PanApply%(pan&, win&, "confirm", auxwin&, auxkbd&)
  223.         CurrentMenu% = EXITCONFIRM
  224.         CALL DisableKbd
  225.       CASE 5
  226.         errstat% = PanApply%(pan&, win&, "help", auxwin&, auxkbd&)
  227.         CurrentMenu% = HELPSCREEN
  228.         CALL DisableKbd
  229.       CASE 6
  230.       CASE 7 TO 9
  231.         CALL LogTop(selfield% - 5)
  232.         CALL AppGoFore(TaskInfo(selfield% - 5).Handle)
  233.         CALL PopDown
  234.     END SELECT
  235.     IF selfield% < 6 THEN MenuField% = selfield%
  236.   CASE OPENMENU
  237.     IF selfield% <> 0 THEN
  238.       slot% = FindFreeSlot%
  239.       IF slot% = 0 THEN
  240.         errstat% = PanApply%(pan&, auxwin&, "maxerror", auxwin&, auxkbd&)
  241.         CurrentMenu% = OPENMAX
  242.       ELSE
  243.         ' Cancel Notification during AppStart to ignore spurious notification
  244.         ' message
  245.         CALL WinCancel(myapp&, NtfDvkey)
  246.         startwin& = AppStart&(PifName$(selfield%))
  247.         CALL WinNotify(myapp&, NtfDvkey)
  248.  
  249.         IF startwin& = 0 THEN
  250.           errstat% = PanApply%(pan&, auxwin&, "nostart", auxwin&, auxkbd&)
  251.           CurrentMenu% = OPENERROR
  252.         ELSE
  253.           CALL CloseAuxWin
  254.           CALL RestoreMainMenu
  255.           CurrentMenu% = MAINMENU
  256.           CALL PopDown
  257.  
  258.           NumProg% = NumProg% + 1
  259.           CALL LogTop(slot%)
  260.  
  261.           TaskInfo(slot%).Handle = startwin&
  262.           TaskInfo(slot%).Title = " #" + RIGHT$(STR$(slot%), 1) + " " + QryTitle$(startwin&)
  263.  
  264.           CALL FldType(win&, 3, FltDeselect)
  265.           CALL FldType(win&, 4, FltInactive)
  266.           CALL FldType(win&, slot% + 5, FltDeselect)
  267.  
  268.         END IF
  269.       END IF
  270.     ELSE
  271.       CALL CloseAuxWin
  272.       CALL RestoreMainMenu
  273.       CurrentMenu% = MAINMENU
  274.     END IF
  275.   CASE SWITCHMENU
  276.     contents$ = QryField(auxwin&, selfield%)
  277.     CALL CloseAuxWin
  278.     CALL RestoreMainMenu
  279.     CurrentMenu% = MAINMENU
  280.     IF selfield% > 1 THEN
  281.       slot% = VAL(MID$(contents$, 3, 1))
  282.       CALL LogTop(slot%)
  283.       CALL AppGoFore(TaskInfo(slot%).Handle)
  284.       CALL PopDown
  285.     END IF
  286.   CASE CLOSECONFIRM
  287.     IF selfield% = 1 THEN
  288.       ' Cancel Notification during TskFree to ignore spurious notification
  289.       ' message
  290.       CALL WinCancel(myapp&, NtfDvkey)
  291.       CALL TskFree(TaskInfo(WhoIsTop%).Handle)
  292.       CALL WinNotify(myapp&, NtfDvkey)
  293.  
  294.       CALL FldType(win&, WhoIsTop% + 5, FltInactive)
  295.       CALL ScrapTop
  296.       NumProg% = NumProg% - 1
  297.       IF NumProg% = 0 THEN
  298.         CALL FldType(win&, 3, FltInactive)
  299.         CALL FldType(win&, 4, FltDeselect)
  300.       END IF
  301.     END IF
  302.     CALL CloseAuxWin
  303.     CALL RestoreMainMenu
  304.     CurrentMenu% = MAINMENU
  305.     IF NumProg% <> 0 THEN CALL PopDown
  306.   CASE EXITCONFIRM
  307.     CALL CloseAuxWin
  308.     CALL RestoreMainMenu
  309.     CurrentMenu% = MAINMENU
  310.     IF selfield% = 1 THEN Done% = -1
  311.   CASE HELPSCREEN
  312.     CALL CloseAuxWin
  313.     CALL RestoreMainMenu
  314.     CurrentMenu% = MAINMENU
  315.   CASE OPENERROR
  316.     CALL CloseAuxWin
  317.     CALL RestoreMainMenu
  318.     CurrentMenu% = MAINMENU
  319.   CASE OPENMAX
  320.     CALL CloseAuxWin
  321.     CALL RestoreMainMenu
  322.     CurrentMenu% = MAINMENU
  323. END SELECT
  324.  
  325.  
  326. END SUB
  327.  
  328. SUB ProcessMail
  329.  
  330. message$ = MalRead$(mal&)
  331. status% = MalStatus%(mal&)
  332.  
  333. IF status% = &H80 AND ASC(message$) = &H50 THEN
  334.   CALL PopUp
  335. END IF
  336.  
  337. END SUB
  338.  
  339. SUB ProgramBody
  340. '***************************************************************************
  341. ' ProgramBody -
  342. '***************************************************************************
  343.  
  344. CALL Initialize
  345.  
  346. DO
  347.   obj& = ObqRead&
  348.   SELECT CASE obj&
  349.   CASE mal&
  350.     CALL ProcessMail
  351.   CASE kbd&
  352.     CALL ProcessKey
  353.   CASE auxkbd&
  354.     CALL ProcessKey
  355.   END SELECT
  356. LOOP UNTIL Done%
  357.  
  358. CALL ClearUp
  359.  
  360. END SUB
  361.  
  362. SUB RestoreMainMenu
  363.  
  364. CALL KeyOpen(kbd&, win&)
  365. CALL FldReset(win&)
  366. CALL FldPoint(win&, MenuField%, 0, 0)
  367.  
  368. END SUB
  369.  
  370. SUB ScrapTop
  371.  
  372. topslot% = WhoIsTop%
  373. TaskInfo(topslot%).Handle = 0
  374. TaskInfo(topslot%).Position = 99
  375. TaskInfo(topslot%).Title = ""
  376. FOR i = 2 TO 4
  377.   IF TaskInfo(i).Handle <> 0 THEN
  378.     TaskInfo(i).Position = TaskInfo(i).Position - 1
  379.   END IF
  380. NEXT i
  381.  
  382. END SUB
  383.  
  384. SUB ShowSwitchMenu
  385.  
  386. errstat% = PanApply%(pan&, win&, "switch", auxwin&, auxkbd&)
  387. auxkbd& = KeyNew&
  388. CALL KeyOpen(auxkbd&, auxwin&)
  389. CALL KeyAddto(auxkbd&, KbfField)
  390. fieldno% = 2
  391. FOR i = 2 TO 4
  392.   IF TaskInfo(i).Handle <> 0 THEN
  393.     CALL FldWrite(auxwin&, fieldno%, TaskInfo(i).Title)
  394.     nobytes% = QryEntry%(auxwin&, fieldno%, Fentry)
  395.     Fentry.FeType = FltDeselect
  396.     Fentry.FeKey1ormode = ASC(MID$(QryField$(auxwin&, fieldno%), 3, 1))
  397.     Fentry.FeKey2 = 0
  398.     CALL FldEntry(auxwin&, fieldno%, Fentry)
  399.     fieldno% = fieldno% + 1
  400.   END IF
  401. NEXT i
  402. CALL WinUnhide(auxwin&)
  403. CALL WinRedraw(auxwin&)
  404.  
  405. END SUB
  406.  
  407. FUNCTION WhoIsTop%
  408.  
  409. FOR i = 2 TO 4
  410.  IF TaskInfo(i).Position = 1 THEN WhoIsTop% = i
  411. NEXT i
  412.  
  413. END FUNCTION
  414.  
  415.