diff --git a/Listener/main.c b/Listener/main.c index 8ce4b7e..b6d3ef1 100644 --- a/Listener/main.c +++ b/Listener/main.c @@ -8,7 +8,7 @@ */ -#pragma nda NDAOpen NDAClose NDAAction NDAInit -1 0x03FF " Listener\\H**" +#pragma nda NDAOpen NDAClose NDAAction NDAInit 5 0x03FF " Listener\\H**" #include @@ -21,14 +21,21 @@ #include #include #include +#include + +#include #include "main.h" -static BOOLEAN ndaActive; -static GrafPortPtr winPtr; +static BOOLEAN ndaActive = FALSE; +static GrafPortPtr winPtr = NULL; static unsigned int userId; +static char line1[50]; +static char line2[50]; +static char line3[50]; + void NDAClose(void) { @@ -47,7 +54,9 @@ void NDAInit(int code) /* When code is 1, this is tool startup, otherwise tool * shutdown. */ - + strcpy(line1, "Hello, world!"); + strcpy(line2, "Hello, world!"); + strcpy(line3, "Hello, world!"); if (code) { ndaActive = FALSE; userId = MMStartUp(); @@ -61,9 +70,21 @@ void NDAInit(int code) #pragma databank 1 void DrawContents(void) { + Rect frame; + GetPortRect(&frame); + frame.v2 -= frame.v1; + frame.h2 -= frame.h1; + frame.h1 = 0; + frame.v1 = 0; + EraseRect(&frame); + PenNormal(); MoveTo(7,10); - DrawCString("Hello, world!"); + DrawCString(line1); + MoveTo(7,20); + DrawCString(line2); + MoveTo(7,30); + DrawCString(line3); } #pragma databank 0 @@ -115,6 +136,19 @@ GrafPortPtr NDAOpen(void) void HandleRun(void) { + static BOOLEAN keySent = FALSE; + + if (winPtr == NULL) + return; + + if (winPtr == FrontWindow()) + return; + + if (keySent) + return; + + PostEvent(keyDownEvt, 0x00C0004A); + keySent = TRUE; } @@ -123,8 +157,27 @@ void HandleControl(EventRecord *event) } +void InvalidateWindow(void) +{ + Rect frame; + SetPort(winPtr); + GetPortRect(&frame); + frame.v2 -= frame.v1; + frame.h2 -= frame.h1; + frame.h1 = 0; + frame.v1 = 0; + InvalRect(&frame); +} + + void HandleKey(EventRecord *event) { + if (winPtr != NULL) { + sprintf(line1, "what = $%X", event->what); + sprintf(line2, "message = $%lX", event->message); + sprintf(line3, "modifiers = $%X", event->modifiers); + InvalidateWindow(); + } } diff --git a/Listener/main.rez b/Listener/main.rez index 4abe934..b908920 100644 --- a/Listener/main.rez +++ b/Listener/main.rez @@ -39,7 +39,7 @@ resource rWindParam1 (windowRes) { {0,0}, /* page ver horiz */ 0, /* winfoRefcon */ 0, /* wInfoHeight */ - {50,50,62,200}, /* wposition */ + {50,10,86,310}, /* wposition */ infront, /* wPlane */ nil, /* wStorage */ $0800 /* wInVerb */