// rectapp.cpp #include "pointt.h" class rect { POINTT upper; POINTT lower; public: rect(int ux,int uy,int lx,int ly) {upper=POINTT(ux,uy); lower=POINTT(lx,ly);} rect(POINTT &u, POINTT &l) { upper=u; lower=l; } void moveTo(int ux,int uy, int lx, int ly) {upper=POINTT(ux,uy); lower=POINTT(lx,ly);} void moveTo(POINTT &u, POINTT &l) { upper=u; lower=l; } int includes(POINTT p) { return ( upper <= p && p <= lower ); } int includes(int x,int y) { return includes(POINTT(x,y)); } void draw(window *W) { W->setPen(blue,solidLine,1); W->line(upper.x,upper.y,lower.x,upper.y); W->line(lower.x,upper.y,lower.x,lower.y); W->line(lower.x,lower.y,upper.x,lower.y); W->line(upper.x,lower.y,upper.x,upper.y); } }; // rect class rectApplication : public application { public: rectApplication(char *apName, char *apTitle, HANDLE thisInst, HANDLE prevInst): application(apName, apTitle, thisInst, prevInst){}; void mouseDown(int,int); void paint(); }; // rectApplication rect *theRectangle = NULL; void rectApplication::mouseDown(int x,int y) { if ( theRectangle != NULL ) { if ( theRectangle->includes(x,y) ) { delete theRectangle; theRectangle = new rect(x,y,x+50,y+20); } } else theRectangle = new rect(x,y,x+50,y+20); clearAndUpdate(); } void rectApplication::paint() { if ( theRectangle != NULL ) theRectangle->draw(this); } int PASCAL WinMain(HANDLE thisInst, HANDLE prevInst, LPSTR, int) { rectApplication theApp("PENS","Little Application Framework",thisInst,prevInst); return theApp.run(); }