home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2B.ZIP / POSTMSG.MOD < prev    next >
Text File  |  1990-10-04  |  6KB  |  147 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. (*    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.  
  37. (*# call(same_ds => off) *)
  38. (*# data(heap_size=> 3000) *)
  39.  
  40. MODULE POSTMSG;
  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. FROM OS2MAC IMPORT SHORT1FROMMP,SHORT2FROMMP,MPFROMSHORT,MPFROM2SHORT;
  47.  
  48. TYPE
  49.   StrPtr = POINTER TO ARRAY[0..0] OF CHAR;
  50.  
  51. CONST
  52.   szClientClass = 'Client Window';
  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.  
  64. PROCEDURE Error;
  65. BEGIN
  66. END Error;
  67.  
  68. (*--------------------  Start of window procedure  ---------------------*)
  69. (*# save,call(near_call=>off,reg_param=>(),reg_saved=>(di,si,ds,es,st1,st2)) *)
  70.  
  71. PROCEDURE ClientWinProc(
  72.                        hwnd : HWND;
  73.                        msg:CARDINAL;
  74.                        mp1,mp2:Win.MPARAM)
  75.                        : Win.MRESULT;
  76.  
  77. BEGIN
  78.   CASE msg OF
  79.     | Win.WM_BUTTON1DOWN :
  80.         Win.PostMsg(NULL,Win.WM_QUIT,NULL,NULL);
  81.         RETURN Win.MPARAM(TRUE);
  82.  
  83.     | Win.WM_ERASEBACKGROUND :
  84.         RETURN Win.MPARAM(TRUE)
  85.  
  86.   ELSE
  87.     RETURN Win.DefWindowProc(hwnd, msg, mp1, mp2)
  88.   END;
  89.   RETURN Win.MPARAM(FALSE);
  90. END ClientWinProc;
  91.  
  92.  
  93. (*# restore *)
  94. (*---------------------  End of window procedure  ----------------------*)
  95.  
  96. BEGIN
  97.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  98.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST;
  99.  
  100.   hab := Win.Initialize(NULL);
  101.   hmq := Win.CreateMsgQueue(hab,0);
  102.  
  103.  
  104.   IF NOT Win.RegisterClass(             (* Register window class        *)
  105.      hab,                               (* Anchor block handle          *)
  106.      szClientClass,                     (* Window class name            *)
  107.      ClientWinProc,                  (* Address of window procedure  *)
  108.      0,                                 (* No special Class Style       *)
  109.      0                                  (* No extra window words        *)
  110.      ) THEN Error END;
  111.  
  112.   hwnd := Win.CreateStdWindow(
  113.               Win.HWND_DESKTOP,
  114.               Win.WS_VISIBLE,
  115.               flcreateFlags,
  116.               szClientClass,
  117.               ' - Client Window',
  118.               0,
  119.               NULL,
  120.               0,
  121.               hwndClient);
  122.  
  123.  
  124.   WHILE( Win.GetMsg( hab, qmsg, HWND(NULL), 0, 0 ) ) DO
  125.     r := Win.DispatchMsg( hab, qmsg );
  126.   END;
  127.  
  128.   IF NOT Win.DestroyWindow(hwndClient) THEN      (* and                          *)
  129.     Error;
  130.   END;
  131.  
  132.   IF NOT Win.DestroyWindow(hwnd) THEN      (* and                          *)
  133.     Error;
  134.   END;
  135.  
  136.   IF NOT Win.DestroyMsgQueue(hmq) THEN      (* and                          *)
  137.     Error;
  138.   END;
  139.  
  140.   IF NOT Win.Terminate(hab) THEN            (* terminate the application    *)
  141.     Error;
  142.   END;
  143.  
  144.   HALT;
  145.  
  146. END POSTMSG.
  147.