home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2B.ZIP / STATIC.MOD < prev    next >
Text File  |  1990-10-03  |  7KB  |  168 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 standard client window.  Whenever you click the mouse a       *)
  32. (*    short phrase will drawn to the right and above the mouse pointer.       *)
  33. (*    Repeated mouse clicks will result in more messages to be written.       *)
  34. (*    Note that when the window is redrawn the current images maintain their  *)
  35. (*    relative window positions.                                              *)
  36. (*    Source code on page 118.                                                *)
  37. (*----------------------------------------------------------------------------*)
  38.  
  39. (*# call(same_ds => off) *)
  40. (*# data(heap_size=> 3000) *)
  41.  
  42. MODULE STATIC;
  43.  
  44. IMPORT OS2DEF,Win,Gpi,Dos,Lib,SYSTEM,IO;
  45. FROM OS2DEF IMPORT HDC,HRGN,HAB,HPS,HBITMAP,HWND,HMODULE,HSEM,
  46.                    POINTL,RECTL,PID,TID,LSET,NULL,
  47.                    COLOR,NullVar,NullStr,BOOL ;
  48. FROM OS2MAC IMPORT SHORT1FROMMP,SHORT2FROMMP,MPFROMSHORT,MPFROM2SHORT;
  49.  
  50. TYPE
  51.   StrPtr = POINTER TO ARRAY[0..0] OF CHAR;
  52.  
  53. CONST
  54.   szClientClass = 'Client Window';
  55.   ID_WINDOW = 1;
  56.  
  57. VAR
  58.   hab           : HAB;
  59.   hmq           : Win.HMQ;
  60.   qmsg          : Win.QMSG;
  61.   hwndClient,
  62.   client,
  63.   hwnd          : HWND;
  64.   r             : Win.MRESULT;
  65.   flcreateFlags : LSET;
  66.  
  67. PROCEDURE Error;
  68. BEGIN
  69. END Error;
  70.  
  71. (*--------------------  Start of window procedure  ---------------------*)
  72. (*# save,call(near_call=>off,reg_param=>(),reg_saved=>(di,si,ds,es,st1,st2)) *)
  73.  
  74. PROCEDURE ClientWinProc(
  75.                        hwnd : HWND;
  76.                        msg:CARDINAL;
  77.                        mp1,mp2:Win.MPARAM)
  78.                        : Win.MRESULT;
  79. CONST
  80.   textsettings = Win.WS_VISIBLE+Win.WS_CLIPSIBLINGS+
  81.                  Win.SS_TEXT+CARDINAL(Win.DT_LEFT)+CARDINAL(Win.DT_TOP)+
  82.                  CARDINAL(Win.DT_WORDBREAK);
  83.  
  84. VAR
  85.   hwndControl : HWND;
  86.  
  87. BEGIN
  88.   CASE msg OF
  89.     | Win.WM_BUTTON1DOWN :
  90.         hwndControl := Win.CreateWindow(
  91.                           hwnd,
  92.                           StrPtr(Win.WC_STATIC)^,
  93.                           'This is the text in the static window',
  94.                           textsettings,
  95.                           INTEGER(SHORT1FROMMP(mp1)),
  96.                           INTEGER(SHORT2FROMMP(mp1)),
  97.                           60,80,
  98.                           hwnd,
  99.                           Win.HWND_TOP,ID_WINDOW,NIL,NIL);
  100.  
  101.         RETURN Win.MPARAM(FALSE);
  102.  
  103.     | Win.WM_ERASEBACKGROUND :
  104.         RETURN Win.MPARAM(TRUE)
  105.  
  106.   ELSE
  107.     RETURN Win.DefWindowProc(hwnd, msg, mp1, mp2)
  108.   END;
  109.   RETURN Win.MPARAM(FALSE);
  110. END ClientWinProc;
  111.  
  112.  
  113.  
  114. (*# restore *)
  115. (*---------------------  End of window procedure  ----------------------*)
  116.  
  117. BEGIN
  118.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  119.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST;
  120.  
  121.   hab := Win.Initialize(NULL);
  122.   hmq := Win.CreateMsgQueue(hab,0);
  123.  
  124.  
  125.   IF NOT Win.RegisterClass(             (* Register window class        *)
  126.      hab,                               (* Anchor block handle          *)
  127.      szClientClass,                     (* Window class name            *)
  128.      ClientWinProc,                  (* Address of window procedure  *)
  129.      Win.CS_SIZEREDRAW,
  130.      0                                  (* No extra window words        *)
  131.      ) THEN Error END;
  132.  
  133.   hwnd := Win.CreateStdWindow(
  134.               Win.HWND_DESKTOP,
  135.               Win.WS_VISIBLE,
  136.               flcreateFlags,
  137.               szClientClass,
  138.               ' - Controls',
  139.               0,
  140.               NULL,
  141.               0,
  142.               hwndClient);
  143.  
  144.  
  145.   WHILE( Win.GetMsg( hab, qmsg, HWND(NULL), 0, 0 ) ) DO
  146.     r := Win.DispatchMsg( hab, qmsg );
  147.   END;
  148.  
  149.   IF NOT Win.DestroyWindow(hwndClient) THEN      (* and                          *)
  150.     Error;
  151.   END;
  152.  
  153.   IF NOT Win.DestroyWindow(hwnd) THEN      (* and                          *)
  154.     Error;
  155.   END;
  156.  
  157.   IF NOT Win.DestroyMsgQueue(hmq) THEN      (* and                          *)
  158.     Error;
  159.   END;
  160.  
  161.   IF NOT Win.Terminate(hab) THEN            (* terminate the application    *)
  162.     Error;
  163.   END;
  164.  
  165.   HALT;
  166.  
  167. END STATIC.
  168.