home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / modula2 / library / os2 / checkbox.mod < prev    next >
Text File  |  1990-08-04  |  7KB  |  181 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. (*    An example of a checkbox control device.  Placing a check in the box    *)
  32. (*    on the screen will cause a beep to occur whenever the window is moved   *)
  33. (*    or resized.                                                             *)
  34. (*    Source code on page 135.                                                *)
  35. (*----------------------------------------------------------------------------*)
  36.  
  37. MODULE CHECKBOX;
  38.  
  39. (*# call(same_ds => off) *)
  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.  
  46. TYPE
  47.   StrPtr = POINTER TO ARRAY[0..0] OF CHAR;
  48.  
  49. CONST
  50.   szClientClass = 'Client Window';
  51.   ID_BUTTON = 1;
  52.   CWPM_CREATE = Win.WM_USER;
  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.   clrOldIndRGB  : COLOR;
  64.   flcreateFlags : LSET;
  65.   hwndControl   : HWND;
  66.   fsButtonState : BOOLEAN;
  67.  
  68. PROCEDURE Error;
  69. BEGIN
  70. END Error;
  71.  
  72. (*--------------------  Start of window procedure  ---------------------*)
  73. (*# save,call(near_call=>off,reg_param=>(),reg_saved=>(di,si,ds,es,st1,st2)) *)
  74.  
  75. PROCEDURE ClientWinProc(
  76.                        hwnd : HWND;
  77.                        msg:CARDINAL;
  78.                        mp1,mp2:Win.MPARAM)
  79.                        : Win.MRESULT;
  80. VAR
  81.   rcl                    : RECTL;
  82.   cx, cy                 : INTEGER;
  83.   cm                     : Win.COMMANDMSG;
  84.  
  85. BEGIN
  86.   CASE msg OF
  87.     | Win.WM_CREATE :
  88.         Win.PostMsg(hwnd,CWPM_CREATE,0,0);
  89.         RETURN Win.MPARAM(FALSE);
  90.  
  91.     | CWPM_CREATE :
  92.         IF NOT Win.QueryWindowRect(hwnd,rcl) THEN Error END;
  93.         cx := INTEGER(INTEGER(rcl.xRight - rcl.xLeft) DIV 2);
  94.         cy := INTEGER(INTEGER(rcl.yTop - rcl.yBottom) DIV 2);
  95.  
  96.         hwndControl := Win.CreateWindow(
  97.                           hwnd,
  98.                           StrPtr(Win.WC_BUTTON)^,
  99.                           'Beep on WM_PAINT',
  100.                           Win.WS_VISIBLE + Win.BS_AUTOCHECKBOX,
  101.                           cx - 100,cy - 10,200,20,
  102.                           hwnd,Win.HWND_TOP,ID_BUTTON,NIL,NIL);
  103.  
  104.         RETURN Win.MPARAM(TRUE);
  105.  
  106.  
  107.     | Win.WM_CONTROL :
  108.         fsButtonState := BOOLEAN(Win.SendMsg(hwndControl,Win.BM_QUERYCHECK,0,0));
  109.         RETURN Win.MPARAM(TRUE);
  110.  
  111.  
  112.     | Win.WM_PAINT :
  113.         IF (fsButtonState) THEN Win.Alarm(Win.HWND_DESKTOP,Win.WA_NOTE) END;
  114.         RETURN Win.DefWindowProc(hwnd,msg,mp1,mp2);
  115.  
  116.  
  117.     | Win.WM_ERASEBACKGROUND :
  118.         RETURN Win.MPARAM(TRUE);
  119.  
  120.   ELSE
  121.     RETURN Win.DefWindowProc(hwnd,msg,mp1,mp2)
  122.   END;
  123.   RETURN Win.MPARAM(FALSE);
  124. END ClientWinProc;
  125.  
  126. (*# restore *)
  127. (*---------------------  End of window procedure  ----------------------*)
  128.  
  129. BEGIN
  130.   fsButtonState := FALSE;
  131.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  132.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST;
  133.  
  134.   hab := Win.Initialize(NULL);
  135.   hmq := Win.CreateMsgQueue(hab,0);
  136.  
  137.  
  138.   IF NOT Win.RegisterClass(             (* Register window class        *)
  139.      hab,                               (* Anchor block handle          *)
  140.      szClientClass,                     (* Window class name            *)
  141.      ClientWinProc,                  (* Address of window procedure  *)
  142.      Win.CS_SIZEREDRAW,
  143.      0                                  (* No extra window words        *)
  144.      ) THEN Error END;
  145.  
  146.   hwnd := Win.CreateStdWindow(
  147.               Win.HWND_DESKTOP,
  148.               Win.WS_VISIBLE,
  149.               flcreateFlags,
  150.               szClientClass,
  151.               ' - Controls',
  152.               0,
  153.               NULL,
  154.               0,
  155.               hwndClient);
  156.  
  157.  
  158.   WHILE( Win.GetMsg( hab, qmsg, HWND(NULL), 0, 0 ) ) DO
  159.     r := Win.DispatchMsg( hab, qmsg );
  160.   END;
  161.  
  162.   IF NOT Win.DestroyWindow(hwndClient) THEN      (* and                          *)
  163.     Error;
  164.   END;
  165.  
  166.   IF NOT Win.DestroyWindow(hwnd) THEN      (* and                          *)
  167.     Error;
  168.   END;
  169.  
  170.   IF NOT Win.DestroyMsgQueue(hmq) THEN      (* and                          *)
  171.     Error;
  172.   END;
  173.  
  174.   IF NOT Win.Terminate(hab) THEN            (* terminate the application    *)
  175.     Error;
  176.   END;
  177.  
  178.   HALT;
  179.  
  180. END CHECKBOX.
  181.