Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!lll-tis!ames!ucsd!sdcsvax!ucsdhub!hp-sdd!hplabs!sdcrdcf!trwrb!scgvaxd!ashtate!dbase!drc From: drc@dbase.UUCP (Dennis Cohen) Newsgroups: comp.sys.mac.programmer Subject: Re: Dragging ICONs Message-ID: <312@dbase.UUCP> Date: 21 Feb 88 02:54:03 GMT References: <21013@bbn.COM> Organization: Ashton Tate Development Center Glendale Cal. Lines: 30 In article <21013@bbn.COM>, franco@bbn.com (Frank A. Lonigro) writes: > ... > I have this great book on programming the MAC in "C", "Using the > Macintosh ToolBox with C". It's a good book and I'm learning alot, but > it doesn't explain how to code the most used aspect of the Mac desktop, > namely, choosing an ICON and have it become its mask and then dragging it > to another spot on the desktop(be it in a window or the desktop itself). > I have this idea that I need to define a rectangle, stick the image of the > ICON in it and then detect a mouseDown event and determine if the Event.where > point is enclosed by that rectangle. This is all well and good except > how do you have it change to its mask? I also could use OffsetRect() to > move it, but there must be an easier way to find out the "dh, dv" parameters. > Is there such a function called DragRect() synonymous to DragWindow()?? > > Any and all help you can give would be greatly appreciated. > This isn't a code fragment, just some hints. First of all, you should be using a ICN# rather than an ICON, since an ICON doesn't have a mask, but the mask for the icon in an ICN# is the second 128 bytes. You should be creating a 32x32 pixel rectangle into which you place the icon with a call to DrawIcon. When you want the mask, get the mask from the ICN# and call DrawIcon again. For dragging it, you can call DragGrayRgn which is what DragWindow and DragControl call to move their outlines around. When it finally gets to its destination, redraw it in the new location and erase it from the old. This is all pretty easy once you've done it once or twice. Dennis Cohen Ashton-Tate Macintosh Division dBASE Mac Development Team