home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2.ZIP / WMPAINT.MOD < prev    next >
Text File  |  1990-08-05  |  6KB  |  152 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. (*    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. MODULE WMPAINT;
  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.   WindowId = 255;
  51.  
  52. VAR
  53.   hab           : HAB;
  54.   hmq           : Win.HMQ;
  55.   qmsg          : Win.QMSG;
  56.   hwndClient,
  57.   client,
  58.   hwnd          : HWND;
  59.   r             : Win.MRESULT;
  60.   flcreateFlags : LSET;
  61.  
  62. PROCEDURE Error;
  63. BEGIN
  64. END Error;
  65.  
  66. (*--------------------  Start of window procedure  ---------------------*)
  67. (*# save,call(near_call=>off,reg_param=>(),reg_saved=>(di,si,ds,es,st1,st2)) *)
  68.  
  69. PROCEDURE ClientWinProc(
  70.                        hwnd : HWND;
  71.                        msg:CARDINAL;
  72.                        mp1,mp2:Win.MPARAM)
  73.                        : Win.MRESULT;
  74. VAR
  75.   hps : HPS;
  76.   rcl : RECTL;
  77. BEGIN
  78. (* Example 5 page 93 *)
  79.   CASE msg OF
  80.     | Win.WM_PAINT :
  81.         hps := Win.BeginPaint(hwnd,HPS(NULL),rcl);
  82.         Win.QueryWindowRect(hwnd,rcl);
  83.         Win.DrawText(hps,-1,"text in middle of window",rcl,
  84.                      0,0,Win.DT_CENTER+Win.DT_VCENTER+Win.DT_ERASERECT+
  85.                      Win.DT_TEXTATTRS);
  86.         Win.EndPaint(hps);
  87.  
  88.     | Win.WM_ERASEBACKGROUND :
  89.         RETURN Win.MPARAM(TRUE)
  90.  
  91.   ELSE
  92.     RETURN Win.DefWindowProc(hwnd, msg, mp1, mp2)
  93.   END;
  94.   RETURN Win.MPARAM(FALSE);
  95. END ClientWinProc;
  96.  
  97. (*# restore *)
  98.  
  99. (*---------------------  End of window procedure  ----------------------*)
  100.  
  101. BEGIN
  102.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  103.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST;
  104.  
  105.   hab := Win.Initialize(NULL);
  106.   hmq := Win.CreateMsgQueue(hab,0);
  107.  
  108.  
  109.   IF NOT Win.RegisterClass(             (* Register window class        *)
  110.      hab,                               (* Anchor block handle          *)
  111.      szClientClass,                     (* Window class name            *)
  112.      ClientWinProc,                  (* Address of window procedure  *)
  113.      Win.CS_SIZEREDRAW,
  114.      0                                  (* No extra window words        *)
  115.      ) THEN Error END;
  116.  
  117.   hwnd := Win.CreateStdWindow(
  118.               Win.HWND_DESKTOP,
  119.               Win.WS_VISIBLE,
  120.               flcreateFlags,
  121.               szClientClass,
  122.               ' - Client Window',
  123.               0,
  124.               NULL,
  125.               0,
  126.               hwndClient);
  127.  
  128.  
  129.   WHILE( Win.GetMsg( hab, qmsg, HWND(NULL), 0, 0 ) ) DO
  130.     r := Win.DispatchMsg( hab, qmsg );
  131.   END;
  132.  
  133.   IF NOT Win.DestroyWindow(hwndClient) THEN      (* and                          *)
  134.     Error;
  135.   END;
  136.  
  137.   IF NOT Win.DestroyWindow(hwnd) THEN      (* and                          *)
  138.     Error;
  139.   END;
  140.  
  141.   IF NOT Win.DestroyMsgQueue(hmq) THEN      (* and                          *)
  142.     Error;
  143.   END;
  144.  
  145.   IF NOT Win.Terminate(hab) THEN            (* terminate the application    *)
  146.     Error;
  147.   END;
  148.  
  149.   HALT;
  150.  
  151. END WMPAINT.
  152.