Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!stevec From: stevec@Apple.COM (Steve Christensen) Newsgroups: comp.sys.mac.programmer Subject: Re: Source code request Message-ID: <51694@apple.Apple.COM> Date: 19 Apr 91 00:05:36 GMT References: <4c3JO2600WBLE0ZlJU@andrew.cmu.edu> Organization: Apple Computer Inc., Cupertino, CA Lines: 43 rg2c+@andrew.cmu.edu (Robert Nelson Gasch) writes: >I've been trying to get CopyBits to work properly, but so far I have >managed to generate nothing but junk. This has gone on for quite >a while by now and it's getting annoying. So if anybody out >there has the source code for some program they would be willing >to donate, I'd appreciate hearing from them. Alternativeley, >if some samples exist on some FTP server, I'd be equally happy. >I just want something I can look at and figure out what I'm >doing wrong. Anything will do. Well, here's a sample snippet that uses CopyBits. Let's assume we have already created a window and we want to draw an icon in it (yes, I know we could just call PlotIcon, but this is an example). WindowPtr theWindow; BitMap theBits; Rect destRect; Handle theIcon; theIcon = GetResource('ICON', 128); // get the icon HLock(theIcon); // and lock it while we use it theBits.baseAddr = *theIcon; // point to the icon's data theBits.rowBytes = 4; // 32 pixels == 4 bytes SetRect(&theBits.bounds,0,0,16,16); // icon's bounding rectangle SetRect(destRect,20,10,36,26); // where the icon goes CopyBits(&theBits,&theWindow->portBits,&theBits.bounds,&destRect,srcCopy,nil); That's all there is to it. You could also specify theBits.bounds in the window's local coordinates and use it as both the srcRect and dstRect in this case. You could also specify a portion of the icon by setting up another rectangle in theBits.bounds' coordinate system and use it for the srcRect... steve -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Steve Christensen Never hit a man with glasses. stevec@apple.com Hit him with a baseball bat.