[net.micro.mac] Toolbox & C help!

betz@runx.OZ (Andrew Betzis) (08/18/86)

	I've got a problem with the following code segment (Megamax C).
	The function rescalepic() is supposed to take the windowpic for the passed window and rescale this picture to the size of the window. All seems to work unless I try to dispose of the old picture.

	Another question: If a setzone() is done to set the heap to the system heap and a newhandle() is done where is the master pointer stored (ie the application heap or the system heap)?
	The motivation for this question is how can I install a code segment in the system heap (eg vinstall() ) without instruction to the segment loader at launch.
	Last question: Calls to either sysbeep() or getmouse() (can't remember which) between open and close picture command crash the system (I've tried hlocks) ?

#include <stdio.h>
#include <win.h>
#include <event.h>
#include <control.h>
#include <qd.h>
#include <dialog.h>
#include <qdvars.h>
#include <misc.h>

											/* long	resume() */
resume()
{ exittoshell();}

/* makes a picture in rect_  */
												/* pichandle makepic(rect_) */
pichandle makepic(rect_)
rect	*rect_;
{
pichandle	pic_H;

	/* just draw and X with border */
	pic_H = openpicture(rect_);
		showpen();
		penpat(dkgray);
		pensize(5,5);
		framerect(rect_);
		moveto(rect_->a.left,rect_->a.top);
		lineto(rect_->a.right,rect_->a.bottom);
		moveto(rect_->a.right,rect_->a.top);
		lineto(rect_->a.left,rect_->a.bottom);
	closepicture();
	return(pic_H);
}

/* rescales windowpic to portrect of win_ */
														/* rescalepic (win_) */
rescalepic (rewin_)
windowptr rewin_;
{
pichandle	newpic_H, oldpic_H;

	setport(rewin_);
	oldpic_H = getwindowpic(rewin_);
	hlock(oldpic_H);
	newpic_H = openpicture( &(rewin_->portrect) );
		drawpicture(oldpic_H, &(rewin_->portrect) );
	closepicture();
	hunlock(oldpic_H);
	killpicture(oldpic_H);	/* IF I REMOVE THIS LINE THEN ALL WORKS */
			/* ELSE IT CRASHES */
	setwindowpic(rewin_, newpic_H);
}

main()
{
windowrecord	*winrec_[2];
windowptr		win_[2];
rect			rect[2];
point			pt;
eventrecord		event;
pichandle		contpic_H;
int				i;
long			t;

	initgraf(&theport);
	initwindows();
	initdialogs(resume);
	flushevents(everyevent, 0);
	setrect(&rect[0], 100, 100, screenbits.bounds.a.right-100,300);

	/* setup rect[1] smaller and move across a bit */
	rect[1] = rect[0];
	insetrect(&rect[1],10,10);
	offsetrect(&rect[1],50,0);

	/* setup initial windows */
	
	winrec_[0] = (windowrecord *)newptr(sizeof(windowrecord));
	winrec_[1] = (windowrecord *)newptr(sizeof(windowrecord));
	
	/* do behind one first */
	win_[1] = newwindow(winrec_[1],&rect[1],"",TRUE,plaindbox,(windowptr)-1,
						FALSE,(long)0);
	win_[0] = newwindow(winrec_[0],&rect[0],"",TRUE,plaindbox,(windowptr)-1,
						FALSE,(long)0);

	/* set up update pics */
	setport(win_[0]);
	contpic_H = makepic( &(win_[0]->portrect) );
	showpen();
	setport(win_[1]);
	showpen();
	setwindowpic(win_[0],contpic_H );	/* auto update */
	setwindowpic(win_[1],contpic_H );	/* same pic for other win */
	rescalepic(win_[1]);	/* rescale pic to fit in smaller 2nd win */
	t = tickcount();
	while (!button())
	{
		/* force Event Mng to call Win Mng */
		getnextevent(activmask+updatemask,&event);
		if ( tickcount() > (t + 60) )
		{
			selectwindow( win_[(i++)%2] );
			t = tickcount();
		}
	}
	exittoshell();
}

Thanks & smile,
andrew betzis.
________________________________________________________________________________
| Andrew Betzis,   |  ACSnet: betz@runx               CSNET: betz@runx.oz      |
|                  |    ARPA: betz%runx.oz@seismo.css.gov                      |
| Sydney,          |   JANET: runx.oz!betz@ukc                                 |
|                  |    UUCP: {enea,hplabs,mcvax,prlb2,seismo,ubc-vision,ukc}  |
| AUSTRALIA.       |          !munnari!runx.oz!betz                            |
|______________________________________________________________________________|