home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2B.ZIP / WMPAINT.MOD < prev   
Text File  |  1990-10-04  |  6KB  |  153 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. (*    Creates a client window and writes a message in the middle of the       *)
  32. (*    window.                                                                 *)
  33. (*    Source code is on page 96.                                              *)
  34. (*----------------------------------------------------------------------------*)
  35.  
  36. (*# call(same_ds => off) *)
  37. (*# data(heap_size=> 3000) *)
  38.  
  39. MODULE WMPAINT;
  40.  
  41. IMPORT OS2DEF,Win,Gpi,Dos,Lib,SYSTEM,IO;
  42. FROM OS2DEF IMPORT HDC,HRGN,HAB,HPS,HBITMAP,HWND,HMODULE,HSEM,
  43.                    POINTL,RECTL,PID,TID,LSET,NULL,
  44.                    COLOR,NullVar,NullStr,BOOL ;
  45. FROM OS2MAC IMPORT SHORT1FROMMP,SHORT2FROMMP,MPFROMSHORT,MPFROM2SHORT;
  46.  
  47. TYPE
  48.   StrPtr = POINTER TO ARRAY[0..0] OF CHAR;
  49.  
  50. CONST
  51.   szClientClass = 'Client Window';
  52.   WindowId = 255;
  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. VAR
  77.   hps : HPS;
  78.   rcl : RECTL;
  79. BEGIN
  80.   CASE msg OF
  81.     | Win.WM_PAINT :
  82.         hps := Win.BeginPaint(hwnd,HPS(NULL),rcl);
  83.         Win.QueryWindowRect(hwnd,rcl);
  84.         Win.DrawText(hps,-1,"text in middle of window",rcl,
  85.                      0,0,Win.DT_CENTER+Win.DT_VCENTER+Win.DT_ERASERECT+
  86.                      Win.DT_TEXTATTRS);
  87.         Win.EndPaint(hps);
  88.  
  89.     | Win.WM_ERASEBACKGROUND :
  90.         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. (*# restore *)
  99.  
  100. (*---------------------  End of window procedure  ----------------------*)
  101.  
  102. BEGIN
  103.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  104.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST;
  105.  
  106.   hab := Win.Initialize(NULL);
  107.   hmq := Win.CreateMsgQueue(hab,0);
  108.  
  109.  
  110.   IF NOT Win.RegisterClass(             (* Register window class        *)
  111.      hab,                               (* Anchor block handle          *)
  112.      szClientClass,                     (* Window class name            *)
  113.      ClientWinProc,                  (* Address of window procedure  *)
  114.      Win.CS_SIZEREDRAW,
  115.      0                                  (* No extra window words        *)
  116.      ) THEN Error END;
  117.  
  118.   hwnd := Win.CreateStdWindow(
  119.               Win.HWND_DESKTOP,
  120.               Win.WS_VISIBLE,
  121.               flcreateFlags,
  122.               szClientClass,
  123.               ' - Client Window',
  124.               0,
  125.               NULL,
  126.               0,
  127.               hwndClient);
  128.  
  129.  
  130.   WHILE( Win.GetMsg( hab, qmsg, HWND(NULL), 0, 0 ) ) DO
  131.     r := Win.DispatchMsg( hab, qmsg );
  132.   END;
  133.  
  134.   IF NOT Win.DestroyWindow(hwndClient) THEN      (* and                          *)
  135.     Error;
  136.   END;
  137.  
  138.   IF NOT Win.DestroyWindow(hwnd) THEN      (* and                          *)
  139.     Error;
  140.   END;
  141.  
  142.   IF NOT Win.DestroyMsgQueue(hmq) THEN      (* and                          *)
  143.     Error;
  144.   END;
  145.  
  146.   IF NOT Win.Terminate(hab) THEN            (* terminate the application    *)
  147.     Error;
  148.   END;
  149.  
  150.   HALT;
  151.  
  152. END WMPAINT.
  153.