home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / amiga / programm / 18306 < prev    next >
Encoding:
Text File  |  1993-01-07  |  7.0 KB  |  205 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!gatech!concert!samba!usenet
  3. From: Todd_Lewis@unc.edu (Todd M. Lewis)
  4. Subject: Re: Simple Question...
  5. Message-ID: <1993Jan7.202049.14130@samba.oit.unc.edu>
  6. Sender: usenet@samba.oit.unc.edu
  7. Nntp-Posting-Host: guitar.oit.unc.edu
  8. Organization: UNC Office of Information Technology
  9. References: <skelly.0n2s@amiganet.chi.il.us>
  10. Date: Thu, 7 Jan 1993 20:20:49 GMT
  11. Lines: 192
  12.  
  13. In article <skelly.0n2s@amiganet.chi.il.us> skelly@amiganet.chi.il.us (Sean  
  14. Kelly) writes:
  15. >     I am relatively new to C programming (been at it about 6 months) and
  16. >pretty much understand it with one MAJOR exception - WINDOWS!  I have written
  17. >about 20 or so programs all of which work fine, but most of which would be  
  18. much
  19. >nicer if I could figure out how the hell to work with windows.  I have four
  20. >different books (three of which are Amiga specific) on C and none of them
  21. >really get into windows much.  Would someone mind posting a little code that I
  22. >could use as an example of how to send text to a window??  I know pretty well
  23. >how to define one, but have never been able to get any text to show up in
  24. >them...
  25. >
  26. >%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%
  27. >%   Sean Kelly - Sysop Amizon BBS (312)594-1146                         %
  28. >%   Always looking for classic video games for the following systems:   %
  29. >%                                                                       %
  30. >%  Atari 2600-Atari 5200-ColecoVision-Atari 5200-Intellivision-Vectrex  %
  31. >%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%
  32.  
  33. This is a _little_ more than what you asked for, but it was handy, small,
  34. and it does put text into windows.  Hope it helps.
  35. --
  36.  _/_/_/  _/     Todd_Lewis@unc.edu          You can lead a horse to 
  37.   _/    _/     utoddl@guitar.oit.unc.edu   Mohammad, but you can't make
  38.  _/    _/_/_/                             a mountain drink a mole hill.
  39. #include <exec/types.h>
  40. #include <intuition/intuition.h>
  41. #include <graphics/rastport.h>
  42. #include <string.h>
  43.  
  44. #ifdef LATTICE
  45.   #include <proto/all.h>
  46. #elif AZTEC_C
  47.   #include <functions.h>
  48.   void _cli_parse( void ) {}
  49.   void _wb_parse( void ) {}
  50. #endif
  51.  
  52. static struct TextAttr TOPAZ60 = {
  53.         (STRPTR)"topaz.font",
  54.         TOPAZ_SIXTY,0,0
  55. };
  56. static struct ExtNewScreen NewScreenStructure = {
  57.         0,0,    /* screen XY origin relative to View */
  58.         640,200,        /* screen width and height */
  59.         2,      /* screen depth (number of bitplanes) */
  60.         0,1,    /* detail and block pens */
  61.         HIRES,  /* display modes for this screen */
  62.         CUSTOMSCREEN,   /* screen type */
  63.         &TOPAZ60,  /* pointer to default screen font */
  64.         (UBYTE *)"Old-look screen",   /* screen title */
  65.         NULL,   /* first in list of custom screen gadgets */
  66.         NULL,   /* pointer to custom BitMap structure */
  67.         NULL,   /* pointer to Extensions **NEW FOR V36+***/
  68. };
  69.  
  70. static struct NewWindow NewWindowStructure1 = {
  71.         50,24,  /* window XY origin relative to TopLeft of screen */
  72.         528,128,        /* window width and height */
  73.         0,1,    /* detail and block pens */
  74.         CLOSEWINDOW,    /* IDCMP flags */
  75.         WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH+
  76.           WINDOWCLOSE+ACTIVATE+NOCAREREFRESH, /* other window flags */
  77.         NULL,   /* first gadget in gadget list */
  78.         NULL,   /* custom CHECKMARK imagery */
  79.         (UBYTE *)"Old-look Window",   /* window title */
  80.         NULL,   /* custom screen pointer */
  81.         NULL,   /* custom bitmap */
  82.         5,5,    /* minimum width and height */
  83.         -1,-1,  /* maximum width and height */
  84.         CUSTOMSCREEN,    /* destination screen type */
  85. };
  86.  
  87. static char *old_look_text[] =
  88.     {
  89.       "This is what an old_style window looks like on",
  90.       "a custom screen.  It doesn't have the 3-D style",
  91.       "under any version of the OS.  Under 2.0 or above,",
  92.       "however, it does have a solid title bar rather",
  93.       "than the 1.x style banded title bar.  This is true",
  94.       "for all \"old\" program's windows.",
  95.       NULL,
  96.     };
  97.  
  98. static char *new_look_text[] =
  99.     {
  100.       "This is what a new-style window looks like on",
  101.       "a custom screen.  Under v36 or above it has",
  102.       "the 3-D style, but under 1.3.x or below it looks",
  103.       "like any other standard window.",
  104.       NULL,
  105.     };
  106.  
  107. static struct Screen *screen;
  108. static struct Window *window;
  109.  
  110. struct Library *IntuitionBase;
  111. struct Library *GfxBase;
  112.  
  113. static WORD screen_pens[] = {~0};
  114.  
  115. static struct TagItem screen_tags[] =
  116.     {
  117.       {SA_Pens, 0 },
  118.       {TAG_END, 0 }
  119.     };
  120.  
  121. void do_text( struct Window *w, char *txt[] )
  122.   {
  123.     SHORT i=2;
  124.     SetDrMd( w->RPort, JAM2 );
  125.     SetAPen( w->RPort,    1 );
  126.     SetBPen( w->RPort,    0 );
  127.     while( *txt )
  128.       {
  129.         Move( w->RPort, w->BorderLeft+2, w->BorderTop*i );
  130.         Text( w->RPort, (UBYTE *)*txt, strlen( *txt ) );
  131.         i++;
  132.         txt++;
  133.       }
  134.   }
  135.  
  136. void wait_for_CLOSEWINDOW( void )
  137.   {
  138.     UBYTE flag = 0;
  139.     struct IntuiMessage *message = NULL;
  140.     ULONG class;
  141.  
  142.     while ( !flag )
  143.       {
  144.         Wait( 1L << window->UserPort->mp_SigBit );
  145.         while( message = (struct IntuiMessage *)GetMsg(window->UserPort) )
  146.           {
  147.             class = message->Class;
  148.             ReplyMsg( (struct Message *)message );
  149.             switch( class )
  150.               {
  151.                 case CLOSEWINDOW :
  152.                   flag = 1;
  153.                   break;
  154.                 default:
  155.                   break;
  156.               }
  157.           }
  158.       }
  159.   }
  160.  
  161. int main( int argc, char *argv[] )
  162.   {
  163.     if ( (IntuitionBase = OpenLibrary((UBYTE *)"intuition.library",33L) ) &&
  164.          (GfxBase       = OpenLibrary((UBYTE *)"graphics.library", 33L) )   )
  165.       {
  166.         /*** Normal, "Old-look" screen ***/
  167.         if ( (screen = OpenScreen( (struct NewScreen *)&NewScreenStructure ) ))
  168.           {
  169.             NewWindowStructure1.Screen = screen;
  170.             if ( (window = OpenWindow( &NewWindowStructure1 ) ) )
  171.               {
  172.                 do_text( window, old_look_text );
  173.                 wait_for_CLOSEWINDOW();
  174.                 CloseWindow( window );
  175.               }
  176.             CloseScreen( screen );
  177.           }
  178.  
  179.         /*** Set up for "New-look" screen ***/
  180.         NewScreenStructure.DefaultTitle     = (UBYTE *)"New-look screen";
  181.         NewScreenStructure.Type     |= NS_EXTENDED;
  182.         NewScreenStructure.Extension = screen_tags;
  183.         screen_tags[0].ti_Data = (ULONG)&screen_pens[0];
  184.  
  185.         if ( (screen = OpenScreen( (struct NewScreen *)&NewScreenStructure )))
  186.           {
  187.             NewWindowStructure1.Screen = screen;
  188.             NewWindowStructure1.Title  = (UBYTE *)"New-look window";
  189.             if ( (window = OpenWindow( &NewWindowStructure1 ) ) )
  190.               {
  191.                 do_text( window, new_look_text );
  192.                 wait_for_CLOSEWINDOW();
  193.                 CloseWindow( window );
  194.               }
  195.             CloseScreen( screen );
  196.           }
  197.       }
  198.     if ( IntuitionBase ) CloseLibrary( IntuitionBase );
  199.     if ( GfxBase       ) CloseLibrary( GfxBase       );
  200.   }
  201.  
  202.  
  203.