home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2B.ZIP / BEEP.MOD < prev    next >
Text File  |  1990-10-03  |  7KB  |  164 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 BEEP.RC.                                             *)
  34. (*  Page 198.                                                                 *)
  35. (*                                                                            *)
  36. (*----------------------------------------------------------------------------*)
  37. (*  Compiling Notes:                                                          *)
  38. (*                                                                            *)
  39. (*  The following files should be available:                                  *)
  40. (*  BEEP.H, BEEP.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 BEEP;
  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 =     101;
  67.   ID_EXIT =     103;
  68.  
  69. VAR
  70.   rslt          : INTEGER;
  71.   hab           : HAB;
  72.   hmq           : Win.HMQ;
  73.   qmsg          : Win.QMSG;
  74.   hwnd,
  75.   hwndClient    : HWND;
  76.   r             : Win.MRESULT;
  77.   flcreateFlags : LSET;
  78.  
  79. (*--------------------  Error reporting procedure  ---------------------*)
  80. PROCEDURE Error;
  81. VAR
  82. BEGIN
  83. END Error;
  84. (*-----------------  End of Error reporting procedure  ------------------*)
  85.  
  86. (*--------------------  Start of window procedure  ---------------------*)
  87. (*# save,call(near_call=>off,reg_param=>(),reg_saved=>(di,si,ds,es,st1,st2)) *)
  88.  
  89. PROCEDURE ClientWinProc(hwnd : HWND;
  90.                         msg:CARDINAL;
  91.                         mp1,mp2:Win.MPARAM)
  92.                         : Win.MRESULT;
  93.  
  94. BEGIN
  95.   CASE msg OF
  96.     | Win.WM_COMMAND :
  97.         CASE SHORT1FROMMP(mp1) OF
  98.           | ID_BEEP :
  99.               Win.Alarm(Win.HWND_DESKTOP,Win.WA_NOTE);
  100.  
  101.           | ID_EXIT :
  102.               Win.PostMsg(hwnd,Win.WM_QUIT,NULL,NULL);
  103.         END;
  104.  
  105.     | Win.WM_ERASEBACKGROUND :
  106.         RETURN Win.MPARAM(TRUE);
  107.  
  108.   ELSE
  109.     RETURN Win.DefWindowProc(hwnd, msg, mp1, mp2)
  110.   END;
  111.   RETURN Win.MPARAM(FALSE);
  112. END ClientWinProc;
  113.  
  114. (*# restore *)
  115. (*---------------------  End of window procedure  ----------------------*)
  116.  
  117. BEGIN
  118.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  119.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST +
  120.                    Win.FCF_MENU;
  121.  
  122.   hab := Win.Initialize(NULL);
  123.   hmq := Win.CreateMsgQueue(hab,0);
  124.  
  125.   IF NOT Win.RegisterClass(             (* Register window class        *)
  126.      hab,                               (* Anchor block handle          *)
  127.      szClientClass,                     (* Window class name            *)
  128.      ClientWinProc,                  (* Address of window procedure  *)
  129.      0,
  130.      0                                  (* No extra window words        *)
  131.      ) THEN Error END;
  132.  
  133.   hwnd := Win.CreateStdWindow(
  134.               Win.HWND_DESKTOP,
  135.               Win.WS_VISIBLE,
  136.               flcreateFlags,
  137.               szClientClass,
  138.               ' - Menu',
  139.               0,
  140.               NULL,
  141.               ID_FRAMERC,
  142.               hwndClient);
  143.  
  144.  
  145.   WHILE (Win.GetMsg(hab,qmsg,HWND(NULL),0,0)) DO
  146.     r := Win.DispatchMsg(hab,qmsg);
  147.   END;
  148.  
  149.   IF NOT Win.DestroyWindow(hwnd) THEN
  150.     Error;
  151.   END;
  152.  
  153.   IF NOT Win.DestroyMsgQueue(hmq) THEN
  154.     Error;
  155.   END;
  156.  
  157.   IF NOT Win.Terminate(hab) THEN
  158.     Error;
  159.   END;
  160.  
  161.   HALT;
  162.  
  163. END BEEP.
  164.