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