home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / mac / programm / 20500 < prev    next >
Encoding:
Text File  |  1993-01-01  |  4.9 KB  |  132 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!munnari.oz.au!newsroom.utas.edu.au!tasman.cc.utas.edu.au!justin
  3. From: justin@tasman.cc.utas.edu.au (Justin Ridge)
  4. Subject: Time Manager & INIT questions (4)
  5. Message-ID: <justin.725862918@tasman>
  6. Keywords: time manager, INIT, startup, icon, think C
  7. Sender: news@newsroom.utas.edu.au
  8. Organization: University of Tasmania, Australia.
  9. Date: Fri, 1 Jan 1993 04:35:18 GMT
  10. Lines: 120
  11.  
  12. G'day to all comp.sys.mac.programmers!
  13.  
  14. A little while back, I started programming on the Mac, and soon got the
  15. hang of resource management, dialogs, and other aspects of simple
  16. applications.  Over the Christmas break, I decided to branch out and look
  17. at things like system extensions (INITs), and soon struck some problems,
  18. which are detailed below.
  19.  
  20. I apologise for the verbosity of these problem descriptions, however if you
  21. bear with me I think the answers are in fact rather simple, and have most
  22. certainly been dealt with in the past by others.
  23. I'd appreciate it if you can help with even one of the topics!!!
  24. Please send responses directly to me (address below).
  25.  
  26. Problems: 1. Icons at startup
  27.           2. Delayed execution of an INIT
  28.           3. Delayed execution of an application
  29.           4. Notifying an INIT of events
  30.  
  31. 1. ICONS AT STARTUP
  32. -------------------
  33. How do I get an INIT to display its icon at startup time when it executes?
  34. Do I use routines like PlotIcon()?  If so, how do I know where to draw it
  35. along the bottom of the screen?
  36. Couldn't find much about this in IM so I am really lost, but I imagine it
  37. would only be half a dozen lines of code.
  38.  
  39. 2. DELAYED EXECUTION OF AN INIT
  40. -------------------------------
  41. Say I wish to have an INIT execute not at startup time, but 1 minute after
  42. startup.
  43. How is this accomplished?  I understand I must use the Time Manager...
  44. consider the following routine:
  45. ~~~~~
  46. pascal void delayedRoutine(void);
  47.  
  48. main() 
  49. {       
  50.   TMTask       theDel;
  51.   long         myDelay = 60000;
  52.   TimerProcPtr temp;
  53.  
  54.   InitGraf(&thePort);
  55.   FlushEvents(everyEvent, 0);
  56.   InitCursor();
  57.   MaxApplZone();
  58.  
  59.   temp = delayedRoutine;
  60.   theDel.tmAddr = temp;
  61.   theDel.tmWakeUp = 0;
  62.   theDel.tmReserved = 0;
  63.   InsXTime(&theDel);
  64.   PrimeTime(&theDel, myDelay);
  65. }
  66.  
  67. pascal void delayedRoutine(void)
  68. {
  69.   /* do something */
  70. }
  71. ~~~~~
  72. This is written in THINK C 5 under System 7, so I have had to declare the
  73. routine delayedRoutine() as a pascal procedure, as described on pp.213-214
  74. of the THINK C User Manual.  Yet this doesn't work!  Why?
  75. I also understand that the routine must be in memory when execution time
  76. comes round, but doesn't an INIT remain in memory indefinately after it is
  77. loaded? (If not, how do I modify the above code to get it to do so?)
  78.  
  79. 3. DELAYED EXECUTION OF AN APPLICATION
  80. --------------------------------------
  81. Say the routine in (2) was changed from an INIT into an application, which
  82. merely starts up, schedules delayedRoutine() for sometime in the future,
  83. then quits.  Then delayedRoutine() would be removed from memory, and
  84. couldn't be found at  execution time.  To avoid this, I build
  85. delayedRoutine() into a code resource which is loaded into the system heap,
  86. as suggested in IM VI 23-10:
  87.  
  88. delayedRoutineHandle = GetResource('CODE', 0);
  89.  
  90. OK, so I have loaded the routine, and I have a handle to it.
  91. Now how can I execute that routine?
  92. How can I get something of type TimerProcPtr and have the Time Manager call
  93. it after an arbitrary delay? i.e. what are the steps between GetResource
  94. and InsXTime?
  95.  
  96. 4. NOTIFYING AN INIT OF EVENTS
  97. ------------------------------
  98. This is the last problem (phew) and a fairly general one.  I have no
  99. problems writing an INIT which loads at startup time, performs a task and
  100. then quits.  My next job will be to write an INIT which performs ongoing
  101. tasks after startup.
  102. Say I want to write an INIT similar to CapsLock, which detects when a
  103. certain key is pressed, then draws a symbol.
  104. How do I get events such as mouseDown, key events etc. always to be sent to
  105. my INIT  after startup, so that I can examine them and take the desired
  106. action?
  107.  
  108. CONCLUSION
  109. ----------
  110. If anyone can give me any vague pointers as to how to go about these tasks,
  111. I would be most grateful.  If you can actually suggest some replacement
  112. code to correct any of my mistakes then that is a bonus!
  113. Also, if you have written routines yourself which do similar tasks, please be
  114. encouraged to send extracts as I will probably learn a lot more from actual
  115. examples than anything else!
  116.  
  117. Finally, please send any responses DIRECTLY TO ME, as this newsgroup is
  118. likely to scroll before I get a chance to read it again.
  119.  
  120. Thanks a lot for any tips,
  121. Regards,
  122. Justin Ridge.
  123.  
  124. justin@tasman.cc.utas.edu.au
  125.  
  126. --------------------------------------------------------------------------
  127. Justin Ridge,             |    Phone:  +61 02 202811
  128. Computing Centre          |    Fax  :  +61 02 231772
  129. University of Tasmania    |    Email:  Justin.Ridge@cc.utas.edu.au
  130. --------------------------------------------------------------------------
  131.  
  132.