home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v5.zip / TOOLKT21 / CPLUS / SAMPLES / WPCAR / HORN.CPP < prev    next >
C/C++ Source or Header  |  1993-04-30  |  5KB  |  195 lines

  1. /******************************************************************************
  2. *
  3. *  Module Name: HORN.CPP
  4. *
  5. *  OS/2 Work Place Shell Sample Program
  6. *
  7. *  Copyright (C) 1992 IBM Corporation
  8. *
  9. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  10. *      sample code created by IBM Corporation. This sample code is not
  11. *      part of any standard or IBM product and is provided to you solely
  12. *      for  the purpose of assisting you in the development of your
  13. *      applications.  The code is provided "AS IS", without
  14. *      warranty of any kind.  IBM shall not be liable for any damages
  15. *      arising out of your use of the sample code, even if they have been
  16. *      advised of the possibility of such damages.                                                    *
  17. *
  18. *  Entry Points:
  19. *
  20. *     Class Methods:
  21. *
  22. *        QueryDuration
  23. *        SetDuration
  24. *        QueryHighTone
  25. *        SetHighTone
  26. *        QueryLowTone
  27. *        SetLowTone
  28. *        SetToDefault
  29. *        Beep
  30. *        SaveState
  31. *        RestoreState
  32. *
  33. *  Description:
  34. *
  35. *      This file contains the member functions of class Horn.
  36. ******************************************************************************/
  37. #include "carpp.xih"
  38.  
  39. /*
  40.  * Method: Horn::Horn
  41.  *
  42.  * Description:
  43.  *
  44.  *    This is the constructor for class Horn which initializes
  45.  *     the state data for an object of type Horn.
  46.  */
  47. Horn::Horn(VOID)
  48. {
  49.   lowTone = DEFAULT_LOTONE;
  50.   highTone = DEFAULT_HITONE;
  51.   duration = DEFAULT_DURATION;
  52. }
  53.  
  54. /*
  55.  * Method: Horn::QueryDuration
  56.  *
  57.  * Description:
  58.  *
  59.  *    Returns a ULONG value indicating the duration of the horn in 
  60.  *     milliseconds.
  61.  */
  62. ULONG Horn::QueryDuration(VOID)
  63. {
  64.   return duration;
  65. }
  66.  
  67. /*
  68.  * Method: Horn::SetDuration
  69.  *
  70.  * Description:
  71.  *
  72.  *    Sets the duration of the horn.  An argument of type ULONG is passed to
  73.  *     the function indicating the horn duration in milliseconds.
  74.  */
  75. VOID Horn::SetDuration(ULONG ulDuration)
  76. {
  77.   duration = ulDuration;
  78. }
  79.  
  80. /*
  81.  * Method: Horn::QueryHighTone
  82.  *
  83.  * Description:
  84.  *
  85.  *    Returns a ULONG value indicating the current beep frequency of the
  86.  *     horn's high tone.
  87.  */
  88. ULONG Horn::QueryHighTone(VOID)
  89. {
  90.   return highTone;
  91. }
  92.  
  93. /*
  94.  * Method: Horn::SetHighTone
  95.  *
  96.  * Description:
  97.  *
  98.  *    Sets the frequency of the horn's high tone.  An argument of type ULONG 
  99.  *     is passed to the function indicating the new frequency of the horn's
  100.  *     high tone.
  101.  */
  102. VOID Horn::SetHighTone(ULONG ulTone)
  103. {
  104.   highTone = ulTone;
  105. }
  106.  
  107. /*
  108.  * Method: Horn::QueryLowTone
  109.  *
  110.  * Description:
  111.  *
  112.  *    Returns a ULONG value indicating the current beep frequency of the
  113.  *     horn's low tone.
  114.  */
  115. ULONG Horn::QueryLowTone(VOID)
  116. {
  117.   return lowTone;
  118. }
  119.  
  120. /*
  121.  * Method: Horn::SetLowTone
  122.  *
  123.  * Description:
  124.  *
  125.  *    Sets the frequency of the horn's low tone.  An argument of type ULONG is
  126.  *     passed to the function indicating the new frequency of the horn's
  127.  *     low tone.
  128.  */
  129. VOID Horn::SetLowTone(ULONG ulTone)
  130. {
  131.   lowTone = ulTone;
  132. }
  133.  
  134. /*
  135.  * Method: Horn::SetToDefault
  136.  *
  137.  * Description:
  138.  *
  139.  *    Sets the default state of the object.
  140.  */
  141. VOID Horn::SetToDefault(VOID)
  142. {
  143.   lowTone = DEFAULT_LOTONE;
  144.   highTone = DEFAULT_HITONE;
  145.   duration = DEFAULT_DURATION;
  146. }
  147.  
  148. /*
  149.  * Method: Horn::Beep
  150.  *
  151.  * Description:
  152.  *
  153.  *    Beeps the horn using the data stored in the object.
  154.  */
  155. VOID Horn::Beep(VOID)
  156. {
  157.   DosBeep(QueryHighTone(), QueryDuration());
  158.   DosSleep(100);
  159.   DosBeep(QueryLowTone(), QueryDuration());
  160. }
  161.  
  162. /*
  163.  * Method: Horn::SaveState
  164.  *
  165.  * Description:
  166.  *
  167.  *    Saves the state of the current object in the OS2.INI file.  The input
  168.  *     arguments consist of a pointer to a Carpp object as well as a pointer 
  169.  *     to a string.  These two items are required so that the data associated 
  170.  *     with the object being saved can be stored in the OS2.INI file.
  171.  */
  172. VOID Horn::SaveState(Carpp *clientObject, PSZ szCarClassTitle)
  173. {
  174.   clientObject->wpSaveLong(szCarClassTitle, IDKEY_LOTONE, lowTone);
  175.   clientObject->wpSaveLong(szCarClassTitle, IDKEY_HITONE, highTone);
  176.   clientObject->wpSaveLong(szCarClassTitle, IDKEY_DURATION, duration);
  177. }
  178.  
  179. /*
  180.  * Method: Horn::RestoreState
  181.  *
  182.  * Description:
  183.  *
  184.  *    Restores the object's saved state from the OS2.INI file.  The input
  185.  *     arguments consist of a pointer to a Carpp object as well as a pointer 
  186.  *     to a string.  These two items are required so that the data associated
  187.  *     with the object being restored can be retrieved from the OS2.INI file.
  188.  */
  189. VOID Horn::RestoreState(Carpp *clientObject, PSZ szCarClassTitle)
  190. {
  191.   clientObject->wpRestoreLong(szCarClassTitle, IDKEY_LOTONE, &lowTone);
  192.   clientObject->wpRestoreLong(szCarClassTitle, IDKEY_HITONE, &highTone);
  193.   clientObject->wpRestoreLong(szCarClassTitle, IDKEY_DURATION, &duration);
  194. }
  195.