home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 127.lha / DragSample / DragSample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-21  |  2.7 KB  |  94 lines

  1. /*    This program demonstrates how one can create a gadget for a window
  2.         which allows you to drag the window by clicking anywhere in the window
  3.         that does not have a ~normal~ user or system gadget
  4.         many a time I was unable to drag a window to another screen location
  5.         because another window was over the drag bar and the top window
  6.         did  not have front to back gadgets
  7.  
  8.         This works as is but be advised that if you use it in your own
  9.         program and your program allows the user to re-size the window
  10.         then you are going to have to remove the gadget, redefine it's size
  11.         to conform to the windows new size, and then add it back to the window
  12.  
  13.         Enjoy!   by BIT-WIZ
  14.     */
  15.  
  16.  
  17. #include <intuition/intuitionbase.h>
  18.  
  19. struct    IntuitionBase    *IntuitionBase=NULL;
  20. struct    Window                *wind;
  21.  
  22. /* put a gadget up in the middle to show that it takes precedence over 
  23.    the drag gadget
  24.  */
  25. struct    IntuiText    gadtext= { 1,0,JAM1,5,7,NULL,"Hello",NULL } ;
  26.  
  27. struct Gadget Gadget1 = {
  28.   NULL,                /*    next                     */
  29.   20,20,            /*    left, top         */
  30.   50,20,            /*    width, height    */
  31.   GADGHCOMP,    /*    FLAGS                    */
  32.   RELVERIFY,    /*    Activation        */
  33.   BOOLGADGET,    /*    Type                    */
  34.   NULL,                /*    Render                */
  35.   NULL,                /*    Select                */
  36.   &gadtext,        /*    text                    */
  37.   NULL,                /*    Mutual                */
  38.   NULL,                /*    Special                */
  39.   NULL,                /*    ID                        */
  40.   NULL                /*    user info            */
  41. };
  42.  
  43. /* this is the full window drag gadget - add this one in LAST for it to work
  44.    OK
  45.  */
  46. struct Gadget Gadget2 = {
  47.   NULL,                        /*    next                     */
  48.   0,0,                        /*    left, top         */
  49.   150,50,                    /*    width, height    */
  50.   GADGHNONE,            /*    FLAGS                    */
  51.   GADGIMMEDIATE,    /*    Activation        */
  52.   WDRAGGING,            /*    Type                    */
  53.   NULL,                        /*    Render                */
  54.   NULL,                        /*    Select                */
  55.   NULL,                        /*    text                    */
  56.   NULL,                        /*    Mutual                */
  57.   NULL,                        /*    Special                */
  58.   NULL,                        /*    ID                        */
  59.   NULL                        /*    user info            */
  60. };
  61.  
  62. struct NewWindow ns = {
  63.   100,50,    /*    left, top            */
  64.   150,50,    /*    width, height    */
  65.   0,1,        /*    pens                    */
  66.   NULL,        /*    IDCMPFLAGS        */
  67.   WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SMART_REFRESH,    /*    Flags    - to show it works */
  68.   &Gadget1,    /*    normal gadget(s)        */
  69.   NULL,            /*    no checkmark image    */
  70.   "Sample",    /*    sample text                    */
  71.   NULL,            /*    WBENCHSCREEN                */
  72.   NULL,            /*    NO bitmap                        */
  73.   0,0,            /*    don't allow sizing    */
  74.   0,0,            /*    don't allow sizing    */
  75.   WBENCHSCREEN    /*    type                        */
  76. };
  77.  
  78. void main()
  79. {
  80.     int    i,j;        /* temp counters    */
  81.     
  82.     IntuitionBase=(struct    IntuitionBase *)OpenLibrary("intuition.library",0L);
  83.     if ( IntuitionBase )    wind=(struct    Window *)OpenWindow(&ns);
  84.     if ( wind )
  85.         {
  86.             AddGadget(wind,&Gadget2,-1);
  87.             RefreshGadgets(wind->FirstGadget,wind,0);
  88.             for ( i=0 ; i < 2500 ; i++ ) for ( j=0 ; j < 1000 ; j++);    
  89.         }
  90.     if ( wind ) CloseWindow(wind);
  91.     if ( IntuitionBase ) CloseLibrary(IntuitionBase);
  92.     exit(0);
  93. }
  94.