home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Elysian Archive
/
AmigaElysianArchive.iso
/
prog
/
source
/
cxercise.lha
/
SIMPLEW2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1987-04-20
|
5KB
|
102 lines
/***********************************************\
* *
* Sample Intuition Screen & Window program #2 *
* *
* 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 */
NULL, /* TextAttr */
"Sample text for a simple window.", /* IText */
NULL, /* NextText */
};
/*****************************************************************************\
* *
* 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, 300, 100, /* LeftEdge, TopEdge, Width, Height */
0, 1, /* DetailPen, BlockPen */
CLOSEWINDOW, /* IDCMPFlags - Tells Intuition what events we want to
hear about. */
( WINDOWCLOSE | SMART_REFRESH | ACTIVATE |
WINDOWDEPTH | WINDOWDRAG ), /* Flags */
NULL, /* FirstGadget - points to YOUR gadget list. */
NULL, /* CheckMark - points to YOUR checkmark image */
"A Simple Window #2", /* Title-points to the text "A Simple Window #2", which is
actually stored somewhere in an initialized data area */
NULL, /* Screen */
NULL, /* BitMap */
100, 25, 640, 200, /* MinWidth, MinHeight, MaxWidth, MaxHeight */
WBENCHSCREEN /* 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 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)
&& ((Window = (struct Window *)
OpenWindow(&SampleWindow)) != NULL))
{ /* Intuition & our window are open, now write the pre-initialized text. */
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 (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
};
} /* End of program */