home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2B.ZIP / POSITION.MOD < prev    next >
Text File  |  1990-10-03  |  6KB  |  154 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. (*    Again, a basic client window is created.  If you move the mouse pointer *)
  32. (*    to the left quarter of the screen, and press the left mouse button      *)
  33. (*    you will hear a short high beep.  If you move the mouse to any other    *)
  34. (*    region and press again you will hear a lower beep.                      *)
  35. (*    Source code on page 84                                                  *)
  36. (*----------------------------------------------------------------------------*)
  37.  
  38. (*# call(same_ds => off) *)
  39. (*# data(heap_size=> 3000) *)
  40.  
  41. MODULE POSITION;
  42.  
  43. IMPORT OS2DEF,Win,Gpi,Dos,Lib,SYSTEM,IO;
  44. FROM OS2DEF IMPORT HDC,HRGN,HAB,HPS,HBITMAP,HWND,HMODULE,HSEM,
  45.                    POINTL,RECTL,PID,TID,LSET,NULL,
  46.                    COLOR,NullVar,NullStr,BOOL ;
  47. FROM OS2MAC IMPORT SHORT1FROMMP,SHORT2FROMMP,MPFROMSHORT,MPFROM2SHORT;
  48.  
  49. TYPE
  50.   StrPtr = POINTER TO ARRAY[0..0] OF CHAR;
  51.  
  52. CONST
  53.   szClientClass = 'Client Window';
  54.  
  55. VAR
  56.   hab           : HAB;
  57.   hmq           : Win.HMQ;
  58.   qmsg          : Win.QMSG;
  59.   hwndClient,
  60.   client,
  61.   hwnd          : HWND;
  62.   r             : Win.MRESULT;
  63.   flcreateFlags : LSET;
  64.  
  65. PROCEDURE Error;
  66. BEGIN
  67. END Error;
  68.  
  69. (*--------------------  Start of window procedure  ---------------------*)
  70. (*# save,call(near_call=>off,reg_param=>(),reg_saved=>(di,si,ds,es,st1,st2)) *)
  71.  
  72. PROCEDURE ClientWinProc(
  73.                        hwnd : HWND;
  74.                        msg:CARDINAL;
  75.                        mp1,mp2:Win.MPARAM)
  76.                        : Win.MRESULT;
  77.  
  78.  
  79. BEGIN
  80.   CASE msg OF
  81.     | Win.WM_BUTTON1DOWN :
  82.           IF (SHORT1FROMMP(mp1) < 100) THEN
  83.              Win.SetActiveWindow(Win.HWND_DESKTOP,hwnd);
  84.              Win.Alarm(Win.HWND_DESKTOP,Win.WA_NOTE);
  85.              RETURN Win.MPARAM(TRUE);
  86.           ELSE
  87.              Win.Alarm(Win.HWND_DESKTOP,Win.WA_ERROR);
  88.           END;
  89.  
  90.     | Win.WM_ERASEBACKGROUND : RETURN Win.MPARAM(TRUE)
  91.  
  92.   ELSE
  93.     RETURN Win.DefWindowProc(hwnd, msg, mp1, mp2)
  94.   END;
  95.   RETURN Win.MPARAM(FALSE);
  96. END ClientWinProc;
  97.  
  98.  
  99.  
  100. (*# restore *)
  101. (*---------------------  End of window procedure  ----------------------*)
  102.  
  103. BEGIN
  104.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  105.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST;
  106.  
  107.   hab := Win.Initialize(NULL);
  108.   hmq := Win.CreateMsgQueue(hab,0);
  109.  
  110.  
  111.   IF NOT Win.RegisterClass(             (* Register window class        *)
  112.      hab,                               (* Anchor block handle          *)
  113.      szClientClass,                     (* Window class name            *)
  114.      ClientWinProc,                  (* Address of window procedure  *)
  115.      0,                                 (* No special Class Style       *)
  116.      0                                  (* No extra window words        *)
  117.      ) THEN Error END;
  118.  
  119.   hwnd := Win.CreateStdWindow(
  120.               Win.HWND_DESKTOP,
  121.               Win.WS_VISIBLE,
  122.               flcreateFlags,
  123.               szClientClass,
  124.               ' - Client Window',
  125.               0,
  126.               NULL,
  127.               0,
  128.               hwndClient);
  129.  
  130.  
  131.   WHILE( Win.GetMsg( hab, qmsg, HWND(NULL), 0, 0 ) ) DO
  132.     r := Win.DispatchMsg( hab, qmsg );
  133.   END;
  134.  
  135.   IF NOT Win.DestroyWindow(hwndClient) THEN      (* and                          *)
  136.     Error;
  137.   END;
  138.  
  139.   IF NOT Win.DestroyWindow(hwnd) THEN      (* and                          *)
  140.     Error;
  141.   END;
  142.  
  143.   IF NOT Win.DestroyMsgQueue(hmq) THEN      (* and                          *)
  144.     Error;
  145.   END;
  146.  
  147.   IF NOT Win.Terminate(hab) THEN            (* terminate the application    *)
  148.     Error;
  149.   END;
  150.  
  151.   HALT;
  152.  
  153. END POSITION.
  154.