Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!casbah.acns.nwu.edu!ils.nwu.edu!engber From: engber@ils.nwu.edu (Mike Engber) Newsgroups: comp.sys.mac.programmer Subject: Re: WDEF (here`s the world's shortest WDEF & CDEF) Summary: obfuscated defprocs Message-ID: <1386@anaxagoras.ils.nwu.edu> Date: 16 Apr 91 14:17:08 GMT References: <1991Apr15.192546.20563@bronze.ucs.indiana.edu> Organization: The Institute for the Learning Sciences Lines: 30 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.