home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PM-M2.ZIP / RADIOBUT.MOD < prev    next >
Text File  |  1990-08-05  |  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. (*    Three choices will displayed on the client window in the Radio Button   *)
  32. (*    style.  Selecting one of the choices will subsequently change the desk- *)
  33. (*    top background to the color indicated.  When the program ends the desk- *)
  34. (*    top should be returned to its original color.                           *)
  35. (*    Source code on page 131.                                                *)
  36. (*----------------------------------------------------------------------------*)
  37.  
  38. MODULE RADIOBUT;
  39.  
  40. (*# call(same_ds => off) *)
  41.  
  42. IMPORT OS2DEF,Win,Gpi,Dos,Lib,SYSTEM,IO;
  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.  
  47. TYPE
  48.   StrPtr = POINTER TO ARRAY[0..0] OF CHAR;
  49.  
  50. CONST
  51.   szClientClass = 'Client Window';
  52.   ID_BUTTON1 = 1;
  53.   ID_BUTTON2 = 2;
  54.   ID_BUTTON3 = 3;
  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.   clrOldIndRGB  : COLOR;
  67.   flcreateFlags : LSET;
  68.  
  69. PROCEDURE Error;
  70. BEGIN
  71. END Error;
  72.  
  73. (*--------------------  Start of window procedure  ---------------------*)
  74. (*# save,call(near_call=>off,reg_param=>(),reg_saved=>(di,si,ds,es,st1,st2)) *)
  75.  
  76. PROCEDURE ClientWinProc(
  77.                        hwnd : HWND;
  78.                        msg:CARDINAL;
  79.                        mp1,mp2:Win.MPARAM)
  80.                        : Win.MRESULT;
  81. VAR
  82.   hwndControl1,
  83.   hwndControl2,
  84.   hwndControl3           : HWND;
  85.   rcl                    : RECTL;
  86.   cx, cy                 : INTEGER;
  87.   aclrIndRGB             : ARRAY [0..1] OF COLOR;
  88.   cm                     : Win.COMMANDMSG;
  89.  
  90. BEGIN
  91.   aclrIndRGB[0] := Win.SYSCLR_BACKGROUND;
  92.  
  93.   CASE msg OF
  94.     | Win.WM_CREATE :
  95.         Win.PostMsg(hwnd,CWPM_CREATE,0,0);
  96.         RETURN Win.MPARAM(FALSE);
  97.  
  98.     | CWPM_CREATE :
  99.         IF NOT Win.QueryWindowRect(hwnd,rcl) THEN Error END;
  100.         cx := INTEGER(INTEGER(rcl.xRight - rcl.xLeft) DIV 2);
  101.         cy := INTEGER(INTEGER(rcl.yTop - rcl.yBottom) DIV 2);
  102.  
  103.         hwndControl1 := Win.CreateWindow(
  104.                           hwnd,
  105.                           StrPtr(Win.WC_BUTTON)^,
  106.                           'Red',
  107.                           Win.WS_VISIBLE + Win.BS_AUTORADIOBUTTON,
  108.                           cx,cy + 20,60,15,
  109.                           hwnd,Win.HWND_TOP,ID_BUTTON1,NIL,NIL);
  110.  
  111.         hwndControl2 := Win.CreateWindow(
  112.                           hwnd,
  113.                           StrPtr(Win.WC_BUTTON)^,
  114.                           'Green',
  115.                           Win.WS_VISIBLE + Win.BS_AUTORADIOBUTTON,
  116.                           cx,cy,60,15,
  117.                           hwnd,
  118.                           Win.HWND_TOP,ID_BUTTON2,NIL,NIL);
  119.  
  120.         hwndControl3 := Win.CreateWindow(
  121.                           hwnd,
  122.                           StrPtr(Win.WC_BUTTON)^,
  123.                           'Blue',
  124.                           Win.WS_VISIBLE + Win.BS_AUTORADIOBUTTON,
  125.                           cx,cy -20,60,15,
  126.                           hwnd,
  127.                           Win.HWND_TOP,ID_BUTTON3,NIL,NIL);
  128.  
  129.         clrOldIndRGB := Win.QuerySysColor(Win.HWND_DESKTOP,Win.SYSCLR_BACKGROUND,
  130.                                           0);
  131.  
  132.         RETURN Win.MPARAM(TRUE);
  133.  
  134.  
  135.     | Win.WM_CONTROL :
  136.         cm := Win.COMMANDMSG(mp1);
  137.         CASE cm.source OF
  138.           | ID_BUTTON1 : aclrIndRGB[1] := Gpi.RGB_RED;
  139.           | ID_BUTTON2 : aclrIndRGB[1] := Gpi.RGB_GREEN;
  140.           | ID_BUTTON3 : aclrIndRGB[1] := Gpi.RGB_BLUE;
  141.         END;
  142.         IF NOT Win.SetSysColors(Win.HWND_DESKTOP,0,Gpi.LCOLF_INDRGB,0,2,
  143.                                 aclrIndRGB) THEN Error END;
  144.         RETURN Win.MPARAM(TRUE);
  145.  
  146.     | Win.WM_DESTROY :
  147.         aclrIndRGB[1] := clrOldIndRGB;
  148.         IF NOT Win.SetSysColors(Win.HWND_DESKTOP,0,Gpi.LCOLF_INDRGB,0,2,
  149.                          aclrIndRGB) THEN Error END;
  150.         RETURN Win.MPARAM(TRUE);
  151.  
  152.     | Win.WM_ERASEBACKGROUND :
  153.         RETURN Win.MPARAM(TRUE);
  154.  
  155.   ELSE
  156.     RETURN Win.DefWindowProc(hwnd, msg, mp1, mp2)
  157.   END;
  158.   RETURN Win.MPARAM(FALSE);
  159. END ClientWinProc;
  160.  
  161. (*# restore *)
  162. (*---------------------  End of window procedure  ----------------------*)
  163.  
  164. BEGIN
  165.   flcreateFlags := Win.FCF_TITLEBAR + Win.FCF_SYSMENU + Win.FCF_SIZEBORDER +
  166.                    Win.FCF_MINMAX + Win.FCF_SHELLPOSITION + Win.FCF_TASKLIST;
  167.  
  168.   hab := Win.Initialize(NULL);
  169.   hmq := Win.CreateMsgQueue(hab,0);
  170.  
  171.  
  172.   IF NOT Win.RegisterClass(             (* Register window class        *)
  173.      hab,                               (* Anchor block handle          *)
  174.      szClientClass,                     (* Window class name            *)
  175.      ClientWinProc,                  (* Address of window procedure  *)
  176.      Win.CS_SIZEREDRAW,
  177.      0                                  (* No extra window words        *)
  178.      ) THEN Error END;
  179.  
  180.   hwnd := Win.CreateStdWindow(
  181.               Win.HWND_DESKTOP,
  182.               Win.WS_VISIBLE,
  183.               flcreateFlags,
  184.               szClientClass,
  185.               ' - Controls',
  186.               0,
  187.               NULL,
  188.               0,
  189.               hwndClient);
  190.  
  191.  
  192.   WHILE( Win.GetMsg( hab, qmsg, HWND(NULL), 0, 0 ) ) DO
  193.     r := Win.DispatchMsg( hab, qmsg );
  194.   END;
  195.  
  196.   IF NOT Win.DestroyWindow(hwndClient) THEN      (* and                          *)
  197.     Error;
  198.   END;
  199.  
  200.   IF NOT Win.DestroyWindow(hwnd) 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 RADIOBUT.
  215.