home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2.ZIP / MESSAGES.MOD < prev    next >
Text File  |  1990-08-05  |  6KB  |  171 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. (*    Provides a excellent way to see what messages are really being sent     *)
  32. (*    during the execution of this program.  When it first starts, you        *)
  33. (*    hear beeps for about 15 seconds before the client window is drawn.      *)
  34. (*    Every time you move the mouse a message will be posted.                 *)
  35. (*    Source code on page 106.                                                *)
  36. (*----------------------------------------------------------------------------*)
  37.  
  38. MODULE MESSAGES;
  39.  
  40. (*# call(same_ds => off) *)
  41.  
  42. IMPORT OS2DEF,Win,Gpi,Dos,Lib,SYSTEM,IO,Str;
  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. FROM PMMSG IMPORT msglist,NumMsg;
  47.  
  48. TYPE
  49.   StrPtr = POINTER TO ARRAY[0..0] OF CHAR;
  50.  
  51. CONST
  52.   szClientClass = 'Display Messages';
  53.  
  54. VAR
  55.   hab           : HAB;
  56.   hmq           : Win.HMQ;
  57.   qmsg          : Win.QMSG;
  58.   hwndClient,
  59.   client,
  60.   hwnd          : HWND;
  61.   r             : Win.MRESULT;
  62.   flcreateFlags : LSET;
  63.   route         : ARRAY [0..10] OF CHAR;
  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. CONST
  78.   questions = '??? ';
  79.   delim = ' ';
  80. VAR
  81.   hps : HPS;
  82.   rcl : RECTL;
  83.   szText,
  84.   str1,
  85.   str2,
  86.   str3,
  87.   msgnumstr : ARRAY [0..80] OF CHAR;
  88.   Done : BOOLEAN;
  89. BEGIN
  90.   Str.CardToStr(VAL(LONGCARD,msg),msgnumstr,10,Done);
  91.  
  92.   IF (msg > NumMsg + 1) THEN
  93.     Str.Concat(str1,questions,delim);
  94.     Str.Concat(str2,msgnumstr,delim);
  95.     Str.Concat(str3,str1,str2);
  96.     Str.Concat(szText,str3,route);
  97.   ELSE
  98.     Str.Concat(str1,msglist[msg],delim);
  99.     Str.Concat(str2,msgnumstr,delim);
  100.     Str.Concat(str3,str1,str2);
  101.     Str.Concat(szText,str3,route);
  102.   END;
  103.  
  104.   hps := Win.GetPS(hwnd);
  105.   Win.QueryWindowRect(hwnd,rcl);
  106.   Win.DrawText(hps,-1,szText,rcl,0,0,
  107.                Win.DT_CENTER+Win.DT_VCENTER+Win.DT_ERASERECT+Win.DT_TEXTATTRS);
  108.   Win.ReleasePS(hps);
  109.   Win.Alarm(Win.HWND_DESKTOP,Win.WA_NOTE);
  110.   Dos.Sleep(300);
  111.   RETURN Win.DefWindowProc(hwnd, msg, mp1, mp2)
  112. END ClientWinProc;
  113.  
  114. (*# restore *)
  115. (*---------------------  End of window procedure  ----------------------*)
  116.  
  117. BEGIN
  118.   route := 'sent';
  119.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  120.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST;
  121.  
  122.   hab := Win.Initialize(NULL);
  123.   hmq := Win.CreateMsgQueue(hab,0);
  124.  
  125.  
  126.   IF NOT Win.RegisterClass(             (* Register window class        *)
  127.      hab,                               (* Anchor block handle          *)
  128.      szClientClass,                     (* Window class name            *)
  129.      ClientWinProc,                  (* Address of window procedure  *)
  130.      0,
  131.      0                                  (* No extra window words        *)
  132.      ) THEN Error END;
  133.  
  134.   hwnd := Win.CreateStdWindow(
  135.               Win.HWND_DESKTOP,
  136.               Win.WS_VISIBLE,
  137.               flcreateFlags,
  138.               szClientClass,
  139.               'Messages',
  140.               0,
  141.               NULL,
  142.               0,
  143.               hwndClient);
  144.  
  145.  
  146.   WHILE( Win.GetMsg( hab, qmsg, HWND(NULL), 0, 0 ) ) DO
  147.     route := 'posted';
  148.     r := Win.DispatchMsg( hab, qmsg );
  149.     route := 'sent';
  150.   END;
  151.  
  152.   IF NOT Win.DestroyWindow(hwndClient) THEN      (* and                          *)
  153.     Error;
  154.   END;
  155.  
  156.   IF NOT Win.DestroyWindow(hwnd) THEN      (* and                          *)
  157.     Error;
  158.   END;
  159.  
  160.   IF NOT Win.DestroyMsgQueue(hmq) THEN      (* and                          *)
  161.     Error;
  162.   END;
  163.  
  164.   IF NOT Win.Terminate(hab) THEN            (* terminate the application    *)
  165.     Error;
  166.   END;
  167.  
  168.   HALT;
  169.  
  170. END MESSAGES.
  171.