[comp.sys.mac.programmer] WDEF

tagreen@lothario.ucs.indiana.edu (Todd Green) (04/16/91)

I've been trying to write my own WDEF in THINK C 4.0.  I've
encountered several problems and was wondering if someone would be
kind enough to send me some sample code.  (Pascal or C is fine,
assembly if you must).

I've also had problems with ResEdit 2.1 when setting up my resources.
When I go to define the ProcID for the window the program (ResEdit)
crashes with an address error (1).  When I try to launch ResEdit again
it gives an error of (13).  I delete it and restore it from floppy,
but when I try to access the resource file with the WDEF (namely the
WIND resource that has my WDEF ) ResEdit crashes again with
"Application out of memory".

Has anyone else experinced this?

Thanks,

Todd
MacIIcx, 8meg, etc. etc.

-- 
Internet: tagreen@bronze.ucs.indiana.edu
NeXTMail: tagreen@lothario.ucs.indiana.edu
BitNet:	  tagreen@iubacs.bitnet

engber@ils.nwu.edu (Mike Engber) (04/16/91)

Below are what I claim to be the worlds shortest WDEF(5 lines) & CDEF(4 lines).

-ME

---

Here's a short example WDEF:

pascal long main(int v,WindowPtr w,int m,long p){Rect r=w->portRect,z;GrafPtr g;
GetPort(&g); SetPort(w); LocalToGlobal(&r);LocalToGlobal(&r.bottom); SetPort(g);
if(m==1){z=r;r.top=r.bottom-20;r.left=r.right-20;return PtInRect(p,&r)? wInGrow:
PtInRect(p,&z) ? wInDrag:wNoHit;} if(m==2){RectRgn(((WindowPeek)w)->contRgn,&r);
RectRgn(((WindowPeek)w)->strucRgn,&r);} if(m==5){FrameRect(p);} return 0L;}

It`s a borderless window that can be dragged around by clicking anywhere in
its content region. I have a program that uses it (so it`s actually useful).
The parameter, int m, makes this program THINK C specific. It should really
be, short m, but I needed the 2 chars to keep the line width < 80 for a
contest I was entering it in.

---

Here's an even shorter example CDEF (even 32 bit clean):

pascal long main(int v,ControlHandle c,int m,long p){Rect r=(*c)->contrlRect;
char*t=(*c)->contrlTitle;if(m==0){FrameRect(&r);InsetRect(&r,1,1);EraseRect(&r);
TextBox(t+1,t[0],&r,1);if((*c)->contrlHilite==10)InvertRect(&r);} if(m==1)
return PtInRect(*(Point*)&p,&r)?10:0L;if(m==2||m==10)RectRgn(p,&r);return 0L;}

It's a rectangular button.