! Saving (graphics) to file - saving window contents (PICT) in Code warrior C (on a Mac PPC) 
Author Message
 ! Saving (graphics) to file - saving window contents (PICT) in Code warrior C (on a Mac PPC)

Can anyone tell me where the following code fails.  It is an example from
ThinkReference which I have had to tweak a little since I think it is
designed for 68k code and not my required PPC code.  If anyone has a later
version of Think Reference2.0.1 you may be able to copy me the PPC code
example ("How to spool a picture to a file").

I want to call a function which snap shots the window/screen (as if
shift-command-3 was pressed)

Help would be greatly appreciated!

Currently, the function either crashes the computer, or creates a blank
file:

Pascal void PutPICTData(Ptr dataPtr, short byteCount);
void PictOut(void);

PicHandle       pHand2;
short   globalRef;

pascal void PutPICTData(Ptr dataPtr, short byteCount)
{
        long    longCount;

        longCount = byteCount;
        if (FSWrite(globalRef, &longCount, dataPtr) != noErr)
                        De{*filter*}();
        if (pHand2)    // Help QD take care of oddness in the picture
          (**pHand2).picSize += longCount;

Quote:
}

extern WindowPtr mainWindowPtr;
void PictOut()
{
        OSErr           err;
        short           i,
                                vrefnum;
        long            longCount,
                                longZero;
        QDProcs         myProcs;
        GrafPort        myPort;
        GrafPtr         myPortPtr,
                                oldPort;
        Rect            pictRect;

        //Initialize graphics
        MaxApplZone();
        MoreMasters();
        InitGraf(&qd.thePort);
        InitFonts();
        FlushEvents(everyEvent, 0);
        InitWindows();
        InitMenus();
        TEInit();
        InitDialogs(0L);
        InitCursor();
        setup_windows();        //initialises the main window

        //record exisiting port and change to a new one
        GetPort(&oldPort);
        myPortPtr = &myPort;
        OpenPort(myPortPtr);

        //create and open a file of type PICT
        err = Create("\ptest", 0, 'ttxt', 'PICT');
        if (err != dupFNErr && err != noErr) De{*filter*}();
        err = FSOpen("\ptest", 0, &globalRef);
        if (err) De{*filter*}();

        pHand2 = nil; //init picture

        //change default picture routines
        SetStdProcs(&myProcs);
        myPortPtr->grafProcs = &myProcs;
        myProcs.putPicProc = (UniversalProcPtr)&PutPICTData;        //call
this funct for put pic

        //init, alloc and write to file
        longZero = 0;
        longCount = 4;
        for (i = 1; i <= (512 + sizeof(Picture)) / 4; ++i)
        {
                err = FSWrite (globalRef, &longCount, &longZero);
                if (err) De{*filter*}();
        }
        //set up drawing environment
        SetRect(&pictRect,0,0,100,100);
        pHand2 = OpenPicture(&pictRect);

        //do some drawing
        ForeColor(blackColor);
        PaintRect(&pictRect);
        MoveTo(5,10);
        DrawString("\pThis is a picture saved to disk");

        //finish drawing
        ClosePicture();

        //do some file stuff
        if (SetFPos(globalRef, fsFromStart, 512) != noErr) De{*filter*}();
        longCount = sizeof(Picture);
        if (FSWrite(globalRef, &longCount, *pHand2) != noErr) De{*filter*}();
        if (FSClose(globalRef) != noErr) De{*filter*}();

        //change back now done
        myPortPtr->grafProcs = nil;
        KillPicture (pHand2);
        SetPort((GrafPort*)oldPort);

Quote:
}


                Adam James BSc (Hons)

WWW:             http://www.*-*-*.com/ ~aj/default.html
Location:       School of Information Systems,
                University of East Anglia, Norwich, NR4 7TJ. UK.



Sat, 21 Apr 2001 03:00:00 GMT  
 ! Saving (graphics) to file - saving window contents (PICT) in Code warrior C (on a Mac PPC)


Quote:
>Can anyone tell me where the following code fails.  It is an example from
>ThinkReference which I have had to tweak a little since I think it is
>designed for 68k code and not my required PPC code.

In comp.lang.c we discuss C code. If your code is platform-specific then
you should be looking for a platform related newsgroup.

Quote:
> If anyone has a later
>version of Think Reference2.0.1 you may be able to copy me the PPC code
>example ("How to spool a picture to a file").

>I want to call a function which snap shots the window/screen (as if
>shift-command-3 was pressed)

There is no such thing as a window/screen in C. Since you mention a Mac try
askin in one of the comp.sys.mac.programmer.* newsgroups.

--
-----------------------------------------


-----------------------------------------



Sun, 22 Apr 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to save watch window contents?

2. Saving Window Content to Bitmap / DIB

3. Saving Child Window Size, Position, Content

4. Saving contents of window to .bmp or .gif

5. Basic Open File, Save/ Save as functions for dos word processor

6. save content of memory to a file

7. How to obtain name of file on Save/Save As

8. How to save Clipboard content to bitmap file.

9. save content in a file using mfc

10. How to obtain name of file on Save/Save As

11. saving graphic informtion to file

12. Graphics file saving in C - Help

 

 
Powered by phpBB® Forum Software