home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2B.ZIP / BEEPS.MOD < prev    next >
Text File  |  1990-10-03  |  8KB  |  199 lines

  1. (*----------------------------------------------------------------------------*)
  2. (* Example OS/2 Presentation Manager Program adapted from the book            *)
  3. (* "OS/2 Presentation Manager - Programming Primer" by Asael Dror &           *)
  4. (* Robert Lafore                                                              *)
  5. (*                                                                            *)
  6. (* Example programs converted to JPI Modula-2 Version 2 for OS/2 1.2 by       *)
  7. (* Chris Barker, October 1990                                                 *)
  8. (*                                                                            *)
  9. (* Notes:  I am distributing these programs so that others can learn and also *)
  10. (*         so I can elicit feedback from the user community on programming for*)
  11. (*         OS/2 PM using Modula-2.  If your have any questions, suggestions,  *)
  12. (*         or comments I'd love to hear from you.  I may be reached at the    *)
  13. (*         following addresses:                                               *)
  14. (*                                                                            *)
  15. (*         Compuserve ID: 72261,2312                                          *)
  16. (*         Pete Norloff's OS/2 Shareware BBS - (703) 385-4325                 *)
  17. (*         Max's Doghouse BBS - (703) 548-7849                                *)
  18. (*           The above two BBS carry the Fidonet OS/2 echo which I read       *)
  19. (*           regularly.                                                       *)
  20. (*         Programmer's Corner - (301) 596-1180                               *)
  21. (*         CPCUG Mix (Window Sig) BBS - (301) 738-9060                        *)
  22. (*                                                                            *)
  23. (*         I hope I hear from you!                                            *)
  24. (*                                                                            *)
  25. (*               - Chris                                                      *)
  26. (*                                                                            *)
  27. (*----------------------------------------------------------------------------*)
  28.  
  29. (*----------------------------------------------------------------------------*)
  30. (*  Program Notes:                                                            *)
  31. (*                                                                            *)
  32. (*  Creates a Client Window with two menu selections which are defined        *)
  33. (*  in the resource file BEEPS.RC.                                            *)
  34. (*  Page 204.                                                                 *)
  35. (*                                                                            *)
  36. (*----------------------------------------------------------------------------*)
  37. (*  Compiling Notes:                                                          *)
  38. (*                                                                            *)
  39. (*  The following files should be available:                                  *)
  40. (*  BEEPS.H, BEEPS.RC                                                         *)
  41. (*                                                                            *)
  42. (*  Add the line: "run rc %N" to the end of your project file.  This will     *)
  43. (*  cause TS to invoke the Microsoft resource compiler after it has created   *)
  44. (*  the EXE file.  You also should have rc.exe in your path along with the    *)
  45. (*  OS/2 header files located in a directory that is referenced by the OS/2   *)
  46. (*  environment variable: INCLUDE.  For example SET INCLUDE = C:\TS\INCLUDE.  *)
  47. (*                                                                            *)
  48. (*----------------------------------------------------------------------------*)
  49. (*# call(same_ds => off) *)
  50. (*# data(heap_size=> 3000) *)
  51.  
  52. MODULE BEEPS;
  53.  
  54. IMPORT OS2DEF,Win,Gpi,Dos,Lib,SYSTEM;
  55. FROM OS2DEF IMPORT HDC,HRGN,HAB,HPS,HBITMAP,HWND,HMODULE,HSEM,
  56.                    POINTL,RECTL,PID,TID,LSET,NULL,
  57.                    COLOR,NullVar,NullStr,BOOL ;
  58. FROM OS2MAC IMPORT SHORT1FROMMP,SHORT2FROMMP,MPFROMSHORT,MPFROM2SHORT;
  59.  
  60. TYPE
  61.   StrPtr = POINTER TO ARRAY[0..0] OF CHAR;
  62.  
  63. CONST
  64.   szClientClass   = 'Client Window';
  65.   ID_FRAMERC      = 1;
  66.   ID_BEEP_SUBMENU = 100;
  67.   ID_BEEP         = 101;
  68.   ID_NOTESEL      = 103;
  69.   ID_WARNINGSEL   = 104;
  70.   ID_ERRORSEL     = 105;
  71.   ID_EXIT         = 110;
  72.  
  73.  
  74. VAR
  75.   rslt          : INTEGER;
  76.   hab           : HAB;
  77.   hmq           : Win.HMQ;
  78.   qmsg          : Win.QMSG;
  79.   hwndMenu,
  80.   hwnd,
  81.   hwndClient    : HWND;
  82.   r             : Win.MRESULT;
  83.   flcreateFlags : LSET;
  84.   fsSound       : Win.WA;
  85.   idCheckedItem : CARDINAL;
  86.  
  87. (*--------------------  Error reporting procedure  ---------------------*)
  88. PROCEDURE Error;
  89. VAR
  90. BEGIN
  91. END Error;
  92. (*-----------------  End of Error reporting procedure  ------------------*)
  93.  
  94. (*--------------------  Start of window procedure  ---------------------*)
  95. (*# save,call(near_call=>off,reg_param=>(),reg_saved=>(di,si,ds,es,st1,st2)) *)
  96.  
  97. PROCEDURE ClientWinProc(hwnd : HWND;
  98.                         msg:CARDINAL;
  99.                         mp1,mp2:Win.MPARAM)
  100.                         : Win.MRESULT;
  101.  
  102.  
  103. BEGIN
  104.   CASE msg OF
  105.     | Win.WM_COMMAND :
  106.         CASE SHORT1FROMMP(mp1) OF
  107.           | ID_BEEP :
  108.               Win.Alarm(Win.HWND_DESKTOP,fsSound);
  109.  
  110.           | ID_NOTESEL, ID_WARNINGSEL, ID_ERRORSEL :
  111.               Win.SendMsg(hwndMenu,Win.MM_SETITEMATTR,
  112.                          MPFROM2SHORT(idCheckedItem,CARDINAL(TRUE)),
  113.                          MPFROM2SHORT(CARDINAL(Win.MIA_CHECKED),0));
  114.  
  115.               Win.SendMsg(hwndMenu,Win.MM_SETITEMATTR,
  116.                          MPFROM2SHORT(SHORT1FROMMP(mp1),CARDINAL(TRUE)),
  117.                          MPFROM2SHORT(CARDINAL(Win.MIA_CHECKED),
  118.                                       CARDINAL(Win.MIA_CHECKED)));
  119.  
  120.               idCheckedItem := SHORT1FROMMP(mp1);
  121.  
  122.               CASE SHORT1FROMMP(mp1) OF
  123.                 | ID_NOTESEL : fsSound := Win.WA_NOTE;
  124.                 | ID_WARNINGSEL : fsSound := Win.WA_WARNING;
  125.                 | ID_ERRORSEL : fsSound := Win.WA_ERROR;
  126.               END;
  127.  
  128.           | ID_EXIT :
  129.               Win.PostMsg(hwnd,Win.WM_QUIT,NULL,NULL);
  130.  
  131.         END;
  132.  
  133.     | Win.WM_CREATE :
  134.         hwndMenu := Win.WindowFromID(Win.QueryWindow(hwnd,Win.QW_PARENT,
  135.                                          B_FALSE),Win.FID_MENU);
  136.  
  137.     | Win.WM_ERASEBACKGROUND :
  138.         RETURN Win.MPARAM(TRUE);
  139.  
  140.   ELSE
  141.     RETURN Win.DefWindowProc(hwnd, msg, mp1, mp2)
  142.   END;
  143.   RETURN Win.MPARAM(FALSE);
  144. END ClientWinProc;
  145.  
  146. (*# restore *)
  147. (*---------------------  End of window procedure  ----------------------*)
  148.  
  149. BEGIN
  150.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  151.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST +
  152.                    Win.FCF_MENU;
  153.  
  154.   fsSound         := Win.WA_NOTE;
  155.   idCheckedItem   := ID_NOTESEL;
  156.  
  157.   hab := Win.Initialize(NULL);
  158.   hmq := Win.CreateMsgQueue(hab,0);
  159.  
  160.   IF NOT Win.RegisterClass(             (* Register window class        *)
  161.      hab,                               (* Anchor block handle          *)
  162.      szClientClass,                     (* Window class name            *)
  163.      ClientWinProc,                  (* Address of window procedure  *)
  164.      0,
  165.      0                                  (* No extra window words        *)
  166.      ) THEN Error END;
  167.  
  168.   hwnd := Win.CreateStdWindow(
  169.               Win.HWND_DESKTOP,
  170.               Win.WS_VISIBLE,
  171.               flcreateFlags,
  172.               szClientClass,
  173.               ' - Menu',
  174.               0,
  175.               NULL,
  176.               ID_FRAMERC,
  177.               hwndClient);
  178.  
  179.  
  180.   WHILE (Win.GetMsg(hab,qmsg,HWND(NULL),0,0)) DO
  181.     r := Win.DispatchMsg(hab,qmsg);
  182.   END;
  183.  
  184.   IF NOT Win.DestroyWindow(hwnd) THEN
  185.     Error;
  186.   END;
  187.  
  188.   IF NOT Win.DestroyMsgQueue(hmq) THEN
  189.     Error;
  190.   END;
  191.  
  192.   IF NOT Win.Terminate(hab) THEN
  193.     Error;
  194.   END;
  195.  
  196.   HALT;
  197.  
  198. END BEEPS.
  199.