home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Elysian Archive
/
AmigaElysianArchive.iso
/
prog
/
source
/
cxercise.lha
/
SIMPLEW3.C
< prev
Wrap
C/C++ Source or Header
|
1987-04-20
|
6KB
|
128 lines
/***********************************************\
* *
* Sample Intuition Screen & Window program #3 *
* *
* Written for ATUG's 'C SIG' by Dave Brittain *
* *
\***********************************************/
#include <exec/types.h>
#include <intuition/intuition.h>
struct IntuitionBase *IntuitionBase;
#define INTUITION_REV 0
struct IntuiText IntuiText =
{ 2, 0, /* FrontPen, BackPen */
JAM1, /* DrawMode, JAM1 = draw foreground but not background */
10, 20, /* LeftEdge, TopEdge */
}; /* TextAttr, IText & Text become NULL when not specified. */
struct NewScreen NS =
{ 0, 0, 640, 200, 2, /* LeftEdge, TopEdge, Width, Height, Depth */
0, 1, /* DetailPen, BlockPen */
HIRES, /* ViewModes */
CUSTOMSCREEN, /* Type */
NULL, /* Font */
"A Sample Screen", /* DefaultTitle */
}; /* Gadgets & CustomBitMap = NULL */
/*****************************************************************************\
* *
* A static initialization of a NewWindow data structure. This is used by *
* Intuition to create a window structure, which is a dynamically allocated, *
* and used structure. The other way of initializing a structure, would be *
* to write a list of simple assignment statements that assign a value to *
* each member of (field within) the structure. I prefer static initial- *
* ization whenever possible, since it is much quicker to type in, and it *
* doesn't generate any executable code. See page 12 of the Intuition Ref- *
* erence manual for the string of 18 assignment statements that does the *
* same thing as the static initialization below. See page B-12 & 13 of the *
* Intuition manual for the definition of the NewWindow structure. *
* *
\*****************************************************************************/
struct NewWindow SampleWindow =
{ 20, 20, 400, 100, /* LeftEdge, TopEdge, Width, Height */
0, 1, /* DetailPen, BlockPen */
CLOSEWINDOW, /* IDCMPFlags - Tells Intuition what events we want to
hear about. */
( WINDOWCLOSE | SMART_REFRESH | ACTIVATE | WINDOWSIZING | WINDOWDRAG |
WINDOWDRAG | WINDOWDEPTH | NOCAREREFRESH ), /* Flags */
NULL, /* FirstGadget - points to YOUR gadget list. */
NULL, /* CheckMark - points to YOUR checkmark image */
"A Simple Window #3", /* Title-points to the text "A Simple Window #2", which is
actually stored somewhere in an initialized data area */
NULL, NULL, /* Screen, BitMap */
100, 25, 640, 200, /* MinWidth, MinHeight, MaxWidth, MaxHeight */
CUSTOMSCREEN /* Type */
};
/* Temporary storage of IntuiMessages before they are replied to. */
struct IntuiMessage MyIM;
void main() /* a void function has no return value. */
{
struct Window *Window;
struct Screen *Screen;
struct IntuiMessage *IntuiMessage; /* The actual IntuiMessage. */
/***********************************************************\
* The following statements open the Intuition library for *
* programatic use. *
\***********************************************************/
if (((IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", INTUITION_REV)) != NULL)
&& ((Screen = (struct Screen *) OpenScreen(&NS)) != NULL))
{
/* Intuition & our screen are open, now write something into the screen: */
IntuiText.IText = "Sample text written to a sample screen";
IntuiText.LeftEdge = 150; /* start 150 pixels from left of screen. */
IntuiText.TopEdge = 150; /* 3/4 of the way down from the top. */
PrintIText(&Screen->RastPort, &IntuiText, 0, 0);
/* Now open the window, but first initialize the 'Screen' member of
the NewWindow (ours is called 'SampleWindow') structure, so
Intuition will know which custom screen to open our window on: */
SampleWindow.Screen = Screen;
if ((Window = (struct Window *) OpenWindow(&SampleWindow)) != NULL)
{ /* our window is now open, now write the pre-initialized text. */
IntuiText.LeftEdge = 30;
IntuiText.TopEdge = 30;
IntuiText.FrontPen = 3;
IntuiText.IText = "Sample text written to a simple window.";
PrintIText(Window->RPort, &IntuiText, 0, 0);
/* Now wait for Intuition to send us a CLOSEWINDOW message. */
do
{ WaitPort(Window->UserPort);
IntuiMessage = (struct IntuiMessage *) GetMsg(Window->UserPort);
MyIM = *IntuiMessage; /* Copy the message and reply right away */
ReplyMsg(IntuiMessage);
/**********************************************************************\
* *
* ALL messages should be processed here, using the copy of the message *
* that we placed into 'MyIM'. This allows Intuition to deallocate the *
* memory it allocated for the message, while we figure out what to do *
* with the message. Since we are only going to get a CLOSEWINDOW mes- *
* sage and quit, this is a bit overly cautious. *
* *
\**********************************************************************/
} while (MyIM.Class != CLOSEWINDOW);
if (Window != NULL) CloseWindow(Window);
};
if (Screen != NULL) CloseScreen(Screen);
if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
};
} /* End of program */