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