home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2B.ZIP / STRING.MOD < prev    next >
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. (*                                                                            *)
  32. (*----------------------------------------------------------------------------*)
  33. (*# call(same_ds => off) *)
  34. (*# data(heap_size=> 3000) *)
  35.  
  36. MODULE STRING;
  37.  
  38. IMPORT OS2DEF,Win,Gpi,Dos,Lib,SYSTEM;
  39. FROM OS2DEF IMPORT HDC,HRGN,HAB,HPS,HBITMAP,HWND,HMODULE,HSEM,
  40.                    POINTL,RECTL,PID,TID,LSET,NULL,
  41.                    COLOR,NullVar,NullStr,BOOL ;
  42. FROM OS2MAC IMPORT SHORT1FROMMP,SHORT2FROMMP,MPFROMSHORT,MPFROM2SHORT;
  43.  
  44. TYPE
  45.   StrPtr = POINTER TO ARRAY[0..0] OF CHAR;
  46.  
  47. CONST
  48.   szClientClass = 'Client Window';
  49.   CWPM_CREATE = Win.WM_USER;
  50.   ID_TITLE = 1;
  51.   ID_MSG = 2;
  52.  
  53. VAR
  54.   rslt          : INTEGER;
  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.   chBuf         : ARRAY [0..257] OF CHAR;
  64.   szBuf         : ARRAY [0..100] OF CHAR;
  65.  
  66. (*--------------------  Error reporting procedure  ---------------------*)
  67. PROCEDURE Error;
  68. VAR
  69. BEGIN
  70. END Error;
  71.  
  72. (*--------------------  Start of window procedure  ---------------------*)
  73. (*# save,call(near_call=>off,reg_param=>(),reg_saved=>(di,si,ds,es,st1,st2)) *)
  74.  
  75. PROCEDURE ClientWinProc(hwnd : HWND;
  76.                         msg:CARDINAL;
  77.                         mp1,mp2:Win.MPARAM)
  78.                         : Win.MRESULT;
  79.  
  80. VAR
  81.   hps                    : HPS;
  82.   rectl                    : RECTL;
  83.  
  84. BEGIN
  85.   CASE msg OF
  86.     | Win.WM_CREATE :
  87.         rslt := Win.LoadString(hab,NULL,ID_MSG,SIZE(szBuf),szBuf);
  88.  
  89.     | Win.WM_PAINT:
  90.         hps := Win.BeginPaint(hwnd,HPS(NULL),RECTL(NullVar));
  91.         Win.QueryWindowRect(hwnd,rectl);
  92.         Win.DrawText(hps,-1,szBuf,rectl,0,0,
  93.           Win.DT_CENTER+Win.DT_VCENTER+Win.DT_ERASERECT+Win.DT_TEXTATTRS);
  94.         Win.EndPaint(hps);
  95.  
  96.   ELSE
  97.     RETURN Win.DefWindowProc(hwnd, msg, mp1, mp2)
  98.   END;
  99.   RETURN Win.MPARAM(FALSE);
  100. END ClientWinProc;
  101.  
  102. (*# restore *)
  103. (*---------------------  End of window procedure  ----------------------*)
  104.  
  105. BEGIN
  106.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  107.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST;
  108.  
  109.   hab := Win.Initialize(NULL);
  110.   hmq := Win.CreateMsgQueue(hab,0);
  111.  
  112.   rslt := Win.LoadString(hab,NULL,ID_TITLE,SIZE(chBuf),chBuf);
  113.  
  114.   IF NOT Win.RegisterClass(             (* Register window class        *)
  115.      hab,                               (* Anchor block handle          *)
  116.      szClientClass,                     (* Window class name            *)
  117.      ClientWinProc,                  (* Address of window procedure  *)
  118.      Win.CS_SIZEREDRAW,
  119.      0                                  (* No extra window words        *)
  120.      ) THEN Error END;
  121.  
  122.   hwnd := Win.CreateStdWindow(
  123.               Win.HWND_DESKTOP,
  124.               Win.WS_VISIBLE,
  125.               flcreateFlags,
  126.               szClientClass,
  127.               chBuf,
  128.               0,
  129.               NULL,
  130.               0,
  131.               hwndClient);
  132.  
  133.  
  134.   WHILE( Win.GetMsg( hab, qmsg, HWND(NULL), 0, 0 ) ) DO
  135.     r := Win.DispatchMsg(hab,qmsg);
  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 STRING.
  153.