home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2B.ZIP / BUTTONS.MOD < prev    next >
Text File  |  1990-10-03  |  8KB  |  205 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. (*    After creating the client window, two push buttons are displayed whose  *)
  32. (*    function should be obvious.                                             *)
  33. (*    Source code on page 125.                                                *)
  34. (*                                                                            *)
  35. (*----------------------------------------------------------------------------*)
  36.  
  37. (*# call(same_ds => off) *)
  38. (*# data(heap_size=> 3000) *)
  39.  
  40. MODULE BUTTONS;
  41.  
  42. IMPORT OS2DEF,Win,Gpi,Dos,Lib,SYSTEM;
  43. FROM OS2DEF IMPORT HDC,HRGN,HAB,HPS,HBITMAP,HWND,HMODULE,HSEM,
  44.                    POINTL,RECTL,PID,TID,LSET,NULL,
  45.                    COLOR,NullVar,NullStr,BOOL ;
  46. FROM OS2MAC IMPORT SHORT1FROMMP,SHORT2FROMMP,MPFROMSHORT,MPFROM2SHORT;
  47.  
  48. TYPE
  49.   StrPtr = POINTER TO ARRAY[0..0] OF CHAR;
  50.  
  51. CONST
  52.   szClientClass = 'Client Window';
  53.   ID_BUTTON1 = 1;
  54.   ID_BUTTON2 = 2;
  55.   CWPM_CREATE = Win.WM_USER;
  56.   ID_WINDOW = 1;
  57.  
  58. VAR
  59.   hab           : HAB;
  60.   hmq           : Win.HMQ;
  61.   qmsg          : Win.QMSG;
  62.   hwndClient,
  63.   client,
  64.   hwnd          : HWND;
  65.   r             : Win.MRESULT;
  66.   flcreateFlags : LSET;
  67.  
  68. (*--------------------  Error reporting procedure  ---------------------*)
  69. PROCEDURE Error;
  70. VAR
  71. BEGIN
  72. END Error;
  73.  
  74. (*--------------------  Start of window procedure  ---------------------*)
  75. (*# save,call(near_call=>off,reg_param=>(),reg_saved=>(di,si,ds,es,st1,st2)) *)
  76.  
  77. PROCEDURE ClientWinProc(
  78.                        hwnd : HWND;
  79.                        msg:CARDINAL;
  80.                        mp1,mp2:Win.MPARAM)
  81.                        : Win.MRESULT;
  82. CONST
  83.   textsettings = Win.WS_VISIBLE+Win.WS_CLIPSIBLINGS+
  84.                  Win.SS_TEXT+CARDINAL(Win.DT_LEFT)+CARDINAL(Win.DT_TOP)+
  85.                  CARDINAL(Win.DT_WORDBREAK);
  86.  
  87. VAR
  88.   hwndControl1,
  89.   hwndControl2           : HWND;
  90.   rcl                    : RECTL;
  91.   cx, cy,
  92.   x , y                  : INTEGER;
  93.   cm                     : Win.COMMANDMSG;
  94.  
  95. BEGIN
  96.   CASE msg OF
  97.     | Win.WM_CREATE :
  98.         IF NOT Win.PostMsg(hwnd,CWPM_CREATE,0,0) THEN
  99.           Error;
  100.         END;
  101.         RETURN Win.MPARAM(FALSE);
  102.  
  103.     | CWPM_CREATE :
  104.         x := 60; y := 30;
  105.         Win.QueryWindowRect(hwnd,rcl);
  106.         cx := INTEGER(INTEGER(rcl.xRight - rcl.xLeft) DIV 2 - x - x DIV 2);
  107.         cy := INTEGER(INTEGER(rcl.yTop - rcl.yBottom) DIV 2 - y DIV 2);
  108.  
  109.         hwndControl1 := Win.CreateWindow(
  110.                           hwnd,
  111.                           StrPtr(Win.WC_BUTTON)^,
  112.                           'Beep',
  113.                           Win.WS_VISIBLE + Win.BS_PUSHBUTTON,
  114.                           cx,cy,x,y,
  115.                           hwnd,Win.HWND_TOP,ID_BUTTON1,NIL,NIL);
  116.  
  117.         cx := cx + x;
  118.         cx := cx + x;
  119.  
  120.         hwndControl2 := Win.CreateWindow(
  121.                           hwnd,
  122.                           StrPtr(Win.WC_BUTTON)^,
  123.                           'Quit',
  124.                           Win.WS_VISIBLE + Win.BS_PUSHBUTTON,
  125.                           cx,cy,x,y,
  126.                           hwnd,
  127.                           Win.HWND_TOP,ID_BUTTON2,NIL,NIL);
  128.  
  129.  
  130.     | Win.WM_COMMAND :
  131.         IF (SHORT1FROMMP(mp2) = Win.CMDSRC_PUSHBUTTON) THEN
  132.           IF (SHORT1FROMMP(mp1) = ID_BUTTON1) THEN
  133.             Win.Alarm(Win.HWND_DESKTOP,Win.WA_NOTE);
  134.           ELSE
  135.             IF (SHORT1FROMMP(mp1) = ID_BUTTON2) THEN
  136.               Win.PostMsg(hwnd,Win.WM_QUIT,0,0);
  137.             END;
  138.           END;
  139.         END;
  140.  
  141.  
  142.     | Win.WM_ERASEBACKGROUND :
  143.         RETURN Win.MPARAM(TRUE);
  144.  
  145.   ELSE
  146.     RETURN Win.DefWindowProc(hwnd, msg, mp1, mp2)
  147.   END;
  148.   RETURN Win.MPARAM(FALSE);
  149. END ClientWinProc;
  150.  
  151. (*# restore *)
  152. (*---------------------  End of window procedure  ----------------------*)
  153.  
  154. BEGIN
  155.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  156.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST;
  157.  
  158.   hab := Win.Initialize(NULL);
  159.   hmq := Win.CreateMsgQueue(hab,0);
  160.  
  161.  
  162.   IF NOT Win.RegisterClass(             (* Register window class        *)
  163.      hab,                               (* Anchor block handle          *)
  164.      szClientClass,                     (* Window class name            *)
  165.      ClientWinProc,                  (* Address of window procedure  *)
  166.      Win.CS_SIZEREDRAW,
  167.      0                                  (* No extra window words        *)
  168.      ) THEN Error END;
  169.  
  170.   hwnd := Win.CreateStdWindow(
  171.               Win.HWND_DESKTOP,
  172.               Win.WS_VISIBLE,
  173.               flcreateFlags,
  174.               szClientClass,
  175.               ' - Controls',
  176.               0,
  177.               NULL,
  178.               0,
  179.               hwndClient);
  180.  
  181.  
  182.   WHILE( Win.GetMsg( hab, qmsg, HWND(NULL), 0, 0 ) ) DO
  183.     r := Win.DispatchMsg( hab, qmsg );
  184.   END;
  185.  
  186.   IF NOT Win.DestroyWindow(hwndClient) THEN      (* and                          *)
  187.     Error;
  188.   END;
  189.  
  190.   IF NOT Win.DestroyWindow(hwnd) THEN      (* and                          *)
  191.     Error;
  192.   END;
  193.  
  194.   IF NOT Win.DestroyMsgQueue(hmq) THEN      (* and                          *)
  195.     Error;
  196.   END;
  197.  
  198.   IF NOT Win.Terminate(hab) THEN            (* terminate the application    *)
  199.     Error;
  200.   END;
  201.  
  202.   HALT;
  203.  
  204. END BUTTONS.
  205.