home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2B.ZIP / ENTRY.MOD < prev    next >
Text File  |  1990-10-04  |  7KB  |  194 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. (*    Puts a text entry box in the bottom left corner of the client window.   *)
  32. (*    Text will be echoed above box as user enters new data.                  *)
  33. (*    Source code on page 138.                                                *)
  34. (*----------------------------------------------------------------------------*)
  35.  
  36. (*# call(same_ds => off) *)
  37. (*# data(heap_size=> 3000) *)
  38.  
  39. MODULE ENTRY;
  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.   ID_BUTTON = 1;
  53.   CWPM_CREATE = Win.WM_USER;
  54.   ID_WINDOW = 1;
  55.   MAXTEXT = 25;
  56.  
  57. VAR
  58.   hab           : HAB;
  59.   hmq           : Win.HMQ;
  60.   qmsg          : Win.QMSG;
  61.   hwndControl,
  62.   hwndFrame,
  63.   hwndClient,
  64.   client,
  65.   hwnd          : HWND;
  66.   r             : Win.MRESULT;
  67.   clrOldIndRGB  : COLOR;
  68.   flcreateFlags : LSET;
  69.   fsButtonState : BOOLEAN;
  70.   pszText  : ARRAY [0..MAXTEXT] OF CHAR;
  71.   cchText : CARDINAL;
  72.  
  73. PROCEDURE Error;
  74. BEGIN
  75. END Error;
  76.  
  77. (*--------------------  Start of window procedure  ---------------------*)
  78. (*# save,call(near_call=>off,reg_param=>(),reg_saved=>(di,si,ds,es,st1,st2)) *)
  79.  
  80. PROCEDURE ClientWinProc(
  81.                        hwnd : HWND;
  82.                        msg:CARDINAL;
  83.                        mp1,mp2:Win.MPARAM)
  84.                        : Win.MRESULT;
  85. TYPE
  86.   EFData = POINTER TO Win.ENTRYFDATA;
  87.  
  88. VAR
  89.   hps           : HPS;
  90.   rcl                    : RECTL;
  91.   EFCtlData              : EFData;
  92.   rslt                   : BOOLEAN;
  93.  
  94. BEGIN
  95.   CASE msg OF
  96.     | Win.WM_CREATE :
  97.         Win.PostMsg(hwnd,CWPM_CREATE,0,0);
  98.         RETURN Win.MPARAM(FALSE);
  99.  
  100.     | CWPM_CREATE :
  101.         EFCtlData^.cb := 8;
  102.         EFCtlData^.EditLimit := MAXTEXT -1;
  103.         EFCtlData^.MinSel := 0;
  104.         EFCtlData^.MaxSel := MAXTEXT - 1;
  105.  
  106.         hwndControl := Win.CreateWindow(
  107.                           hwnd,
  108.                           StrPtr(Win.WC_ENTRYFIELD)^,
  109.                           'Initial text',
  110.                           Win.WS_VISIBLE + Win.ES_MARGIN,
  111.                           10,10,175,20,
  112.                           hwnd,Win.HWND_TOP,ID_WINDOW,
  113.                           EFCtlData,NIL);
  114.  
  115.         Win.PostMsg(hwnd,Win.WM_CONTROL,MPFROM2SHORT(0,Win.EN_CHANGE),0);
  116.         Win.SetFocus(Win.HWND_DESKTOP,hwndControl);
  117.  
  118.     | Win.WM_CONTROL :
  119.         IF (SHORT2FROMMP(mp1) = Win.EN_CHANGE) THEN
  120.           cchText := CARDINAL(Win.QueryWindowText(hwndControl,MAXTEXT,pszText));
  121.           rslt := Win.InvalidateRect(hwnd,RECTL(NullVar),B_FALSE)
  122.         END;
  123.  
  124.     | Win.WM_PAINT :
  125.         hps := Win.BeginPaint(hwnd,HPS(NULL),rcl);
  126.         Gpi.Erase(hps);
  127.         rcl.xLeft := 10;
  128.         rcl.xRight := 400;
  129.         rcl.yBottom := 40;
  130.         rcl.yTop := 60;
  131.         Win.DrawText(hps,INTEGER(cchText),pszText,rcl,0,0,
  132.                      Win.DT_LEFT+Win.DT_VCENTER+Win.DT_ERASERECT+Win.DT_TEXTATTRS);
  133.         Win.EndPaint(hps);
  134.         RETURN Win.DefWindowProc(hwnd,msg,mp1,mp2);
  135.  
  136.   ELSE
  137.     RETURN Win.DefWindowProc(hwnd,msg,mp1,mp2)
  138.   END;
  139.   RETURN Win.MPARAM(FALSE);
  140. END ClientWinProc;
  141.  
  142. (*# restore *)
  143. (*---------------------  End of window procedure  ----------------------*)
  144.  
  145. BEGIN
  146.   cchText := 0;
  147.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  148.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST;
  149.  
  150.   hab := Win.Initialize(NULL);
  151.   hmq := Win.CreateMsgQueue(hab,0);
  152.  
  153.  
  154.   IF NOT Win.RegisterClass(             (* Register window class        *)
  155.      hab,                               (* Anchor block handle          *)
  156.      szClientClass,                     (* Window class name            *)
  157.      ClientWinProc,                  (* Address of window procedure  *)
  158.      Win.CS_SIZEREDRAW+
  159.      Win.CS_CLIPCHILDREN,
  160.      0                                  (* No extra window words        *)
  161.      ) THEN Error END;
  162.  
  163.   hwndFrame := Win.CreateStdWindow(
  164.               Win.HWND_DESKTOP,
  165.               Win.WS_VISIBLE,
  166.               flcreateFlags,
  167.               szClientClass,
  168.               ' - Controls',
  169.               0,
  170.               NULL,
  171.               0,
  172.               hwndClient);
  173.  
  174.  
  175.   WHILE( Win.GetMsg(hab,qmsg,HWND(NULL),0,0)) DO
  176.     r := Win.DispatchMsg(hab,qmsg);
  177.   END;
  178.  
  179.   IF NOT Win.DestroyWindow(hwndFrame) THEN      (* and                          *)
  180.     Error;
  181.   END;
  182.  
  183.   IF NOT Win.DestroyMsgQueue(hmq) THEN      (* and                          *)
  184.     Error;
  185.   END;
  186.  
  187.   IF NOT Win.Terminate(hab) THEN            (* terminate the application    *)
  188.     Error;
  189.   END;
  190.  
  191.   HALT;
  192.  
  193. END ENTRY.
  194.