home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2.ZIP / STATIC.MOD < prev    next >
Text File  |  1990-08-05  |  6KB  |  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, 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 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. MODULE STATIC;
  40.  
  41. (*# call(same_ds => off) *)
  42.  
  43. IMPORT OS2DEF,Win,Gpi,Dos,Lib,SYSTEM,IO;
  44. FROM OS2DEF IMPORT HDC,HRGN,HAB,HPS,HBITMAP,HWND,HMODULE,HSEM,
  45.                    POINTL,RECTL,PID,TID,LSET,NULL,
  46.                    COLOR,NullVar,NullStr,BOOL ;
  47.  
  48. TYPE
  49.   StrPtr = POINTER TO ARRAY[0..0] OF CHAR;
  50.  
  51. CONST
  52.   szClientClass = 'Client Window';
  53.   ID_WINDOW = 1;
  54.  
  55. VAR
  56.   hab           : HAB;
  57.   hmq           : Win.HMQ;
  58.   qmsg          : Win.QMSG;
  59.   hwndClient,
  60.   client,
  61.   hwnd          : HWND;
  62.   r             : Win.MRESULT;
  63.   flcreateFlags : LSET;
  64.  
  65. PROCEDURE Error;
  66. BEGIN
  67. END Error;
  68.  
  69. (*--------------------  Start of window procedure  ---------------------*)
  70. (*# save,call(near_call=>off,reg_param=>(),reg_saved=>(di,si,ds,es,st1,st2)) *)
  71.  
  72. PROCEDURE ClientWinProc(
  73.                        hwnd : HWND;
  74.                        msg:CARDINAL;
  75.                        mp1,mp2:Win.MPARAM)
  76.                        : Win.MRESULT;
  77. CONST
  78.   textsettings = Win.WS_VISIBLE+Win.WS_CLIPSIBLINGS+
  79.                  Win.SS_TEXT+CARDINAL(Win.DT_LEFT)+CARDINAL(Win.DT_TOP)+
  80.                  CARDINAL(Win.DT_WORDBREAK);
  81.  
  82. VAR
  83.   mm : Win.MOUSEMSG;
  84.   hwndControl : HWND;
  85.  
  86. BEGIN
  87.   mm := Win.MOUSEMSG(mp2);
  88.  
  89.   CASE msg OF
  90.     | Win.WM_BUTTON1DOWN :
  91.         hwndControl := Win.CreateWindow(
  92.                           hwnd,
  93.                           StrPtr(Win.WC_STATIC)^,
  94.                           'This is the text in the static window',
  95.                           textsettings,
  96.                           mm.x,mm.y,
  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.