home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2B.ZIP / LISTBOX.MOD < prev    next >
Text File  |  1990-10-03  |  8KB  |  215 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. (*    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 146.                                                *)
  34. (*----------------------------------------------------------------------------*)
  35.  
  36. (*# call(same_ds => off) *)
  37. (*# data(heap_size=> 3000) *)
  38.  
  39. MODULE LISTBOX;
  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.             SHORT1FROMMR,MPFROMCHAR;
  47.  
  48. CONST
  49.   NWORDS = 9;
  50.  
  51. TYPE
  52.   StrPtr = POINTER TO ARRAY[0..0] OF CHAR;
  53.   ShortStr = ARRAY [0..50] OF CHAR;
  54.   ShortStrArray = ARRAY [0..1],[0..NWORDS] OF ShortStr;
  55.  
  56. CONST
  57.   szClientClass = 'Client Window';
  58.   CWP_CREATE = Win.WM_USER;
  59.   ID_WINDOW = 1;
  60.  
  61. VAR
  62.   hab           : HAB;
  63.   hmq           : Win.HMQ;
  64.   qmsg          : Win.QMSG;
  65.   hwndFrame,
  66.   hwndClient,
  67.   client,
  68.   hwnd          : HWND;
  69.   r             : Win.MRESULT;
  70.   clrOldIndRGB  : COLOR;
  71.   flcreateFlags : LSET;
  72.   ItemIndex     : CARDINAL;
  73.   hwndControl   : HWND;
  74.   statvar       : BOOLEAN;
  75.   aszGlossary   : ShortStrArray;
  76.  
  77. PROCEDURE Error;
  78. BEGIN
  79. END Error;
  80.  
  81. (*--------------------  Start of window procedure  ---------------------*)
  82. (*# save,call(near_call=>off,reg_param=>(),reg_saved=>(di,si,ds,es,st1,st2)) *)
  83.  
  84. PROCEDURE ClientWinProc(hwnd : HWND;
  85.                        msg:CARDINAL;
  86.                        mp1,mp2:Win.MPARAM)
  87.                        : Win.MRESULT;
  88. VAR
  89.   hps           : HPS;
  90.   rcl           : RECTL;
  91.   rslt          : BOOLEAN;
  92.   mrslt         : Win.MRESULT;
  93.  
  94. BEGIN
  95.   CASE msg OF
  96.     | Win.WM_CREATE :
  97.         Win.PostMsg(hwnd,CWP_CREATE,0,0);
  98.         RETURN Win.MPARAM(FALSE);
  99.  
  100.  
  101.     | CWP_CREATE :
  102.         hwndControl := Win.CreateWindow(
  103.                           hwnd,
  104.                           StrPtr(Win.WC_LISTBOX)^,
  105.                           'Glossary',
  106.                           Win.WS_VISIBLE,
  107.                           10,40,150,70,
  108.                           hwnd,Win.HWND_TOP,ID_WINDOW,
  109.                           NIL,NIL);
  110.  
  111.         FOR ItemIndex := 0 TO NWORDS - 1 DO
  112.             Win.SendMsg(hwndControl,Win.LM_INSERTITEM,
  113.                       MPFROMSHORT(ItemIndex),
  114.                       MPFROMCHAR(aszGlossary[0,INTEGER(ItemIndex)]));
  115.         END;
  116.  
  117.  
  118.     | Win.WM_CONTROL :
  119.         IF (SHORT2FROMMP(mp1) = Win.LN_SELECT) THEN
  120.           ItemIndex := SHORT1FROMMR(Win.SendMsg(hwndControl,Win.LM_QUERYSELECTION,
  121.                                  NULL,NULL));
  122.         Win.InvalidateRect(hwnd,RECTL(NullVar),B_FALSE);
  123.         END;
  124.  
  125.  
  126.     | Win.WM_PAINT :
  127.         hps := Win.BeginPaint(hwnd,HPS(NULL),RECTL(NullVar));
  128.         Gpi.Erase(hps);
  129.         rcl.xLeft := 10;
  130.         rcl.xRight := 500;
  131.         rcl.yBottom := 10;
  132.         rcl.yTop := 30;
  133.         Win.DrawText(hps,-1,aszGlossary[1,INTEGER(ItemIndex)],rcl,0,0,
  134.                      Win.DT_LEFT+Win.DT_VCENTER+Win.DT_ERASERECT+Win.DT_TEXTATTRS);
  135.         Win.EndPaint(hps);
  136.  
  137.   ELSE
  138.     RETURN Win.DefWindowProc(hwnd,msg,mp1,mp2)
  139.   END;
  140.   RETURN Win.MPARAM(FALSE);
  141. END ClientWinProc;
  142.  
  143. (*# restore *)
  144. (*---------------------  End of window procedure  ----------------------*)
  145.  
  146. BEGIN
  147.   aszGlossary[0,0] := 'Active window';
  148.   aszGlossary[1,0] := 'Frame window ancestor of Keyboard focus window';
  149.   aszGlossary[0,1] := 'Class';
  150.   aszGlossary[1,1] := 'Windows sharing a common procedure';
  151.   aszGlossary[0,2] := 'Controls';
  152.   aszGlossary[1,2] := 'What this chapter is all about';
  153.   aszGlossary[0,3] := 'List box';
  154.   aszGlossary[1,3] := 'The type of control window you are looking at';
  155.   aszGlossary[0,4] := 'Message';
  156.   aszGlossary[1,4] := 'Information sent to a window';
  157.   aszGlossary[0,5] := 'Owner';
  158.   aszGlossary[1,5] := 'Window to which owner sends notification messages';
  159.   aszGlossary[0,6] := 'Parent';
  160.   aszGlossary[1,6] := 'Window to which child is clipped';
  161.   aszGlossary[0,7] := 'Standard window';
  162.   aszGlossary[1,7] := 'Frame window plus children';
  163.   aszGlossary[0,8] := 'Window';
  164.   aszGlossary[1,8] := 'An object';
  165.   aszGlossary[0,9] := '';
  166.   aszGlossary[1,9] := 'Select a word';
  167.  
  168.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  169.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST;
  170.  
  171.   hab := Win.Initialize(NULL);
  172.   hmq := Win.CreateMsgQueue(hab,0);
  173.  
  174.  
  175.   IF NOT Win.RegisterClass(             (* Register window class        *)
  176.      hab,                               (* Anchor block handle          *)
  177.      szClientClass,                     (* Window class name            *)
  178.      ClientWinProc,                  (* Address of window procedure  *)
  179.      Win.CS_SIZEREDRAW+
  180.      Win.CS_CLIPCHILDREN,
  181.      0                                  (* No extra window words        *)
  182.      ) THEN Error END;
  183.  
  184.   hwndFrame := Win.CreateStdWindow(
  185.               Win.HWND_DESKTOP,
  186.               Win.WS_VISIBLE,
  187.               flcreateFlags,
  188.               szClientClass,
  189.               ' - Controls',
  190.               0,
  191.               NULL,
  192.               0,
  193.               hwndClient);
  194.  
  195.  
  196.   WHILE( Win.GetMsg(hab,qmsg,HWND(NULL),0,0)) DO
  197.     r := Win.DispatchMsg(hab,qmsg);
  198.   END;
  199.  
  200.   IF NOT Win.DestroyWindow(hwndFrame) THEN      (* and                          *)
  201.     Error;
  202.   END;
  203.  
  204.   IF NOT Win.DestroyMsgQueue(hmq) THEN      (* and                          *)
  205.     Error;
  206.   END;
  207.  
  208.   IF NOT Win.Terminate(hab) THEN            (* terminate the application    *)
  209.     Error;
  210.   END;
  211.  
  212.   HALT;
  213.  
  214. END LISTBOX.
  215.