home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
macintosh-c
/
macc-carbon-demos-nonbinhex.sit
/
macc-carbon-demos-nonbinhex
/
chap01-demo
/
SysMemRes.c
< prev
next >
Wrap
C/C++ Source or Header
|
2001-03-31
|
4KB
|
162 lines
// *******************************************************************************************
// SysMemRes.c
// *******************************************************************************************
//
// This program:
//
// • Loads a window template ('WIND') resource and creates a window.
//
// • Allocates a relocatable block in the application's heap, gets its size in bytes, draws
// the size in the window, and then disposes of the block.
//
// • Loads a purgeable 'PICT' resource and a non-purgeable 'STR ' resource and draws them in
// the window.
//
// • Checks if any error codes were generated as a result of calls to Memory Manager and
// Resource Manager functions.
//
// • Terminates when the mouse button is clicked.
//
// The program utilises the following resources:
//
// • A 'plst' resource.
//
// • A 'WIND' resource (purgeable).
//
// • A 'PICT' resource (purgeable).
//
// • A 'STR ' resource (non-purgeable).
//
// *******************************************************************************************
// ………………………………………………………………………………………………………………………………………………………………………………………………………………………… includes
#include <Carbon.h>
// …………………………………………………………………………………………………………………………………………………………………………………………………………………………… defines
#define rWindowResourceID 128
#define rStringResourceID 128
#define rPictureResourceID 128
// …………………………………………………………………………………………………………………………………………………………………………………………… function prototypes
void main (void);
void doPreliminaries (void);
void doNewWindow (void);
void doMemory (void);
void doResources (void);
// ************************************************************************************** main
void main(void)
{
doPreliminaries();
doNewWindow();
doMemory();
doResources();
QDFlushPortBuffer(GetWindowPort(FrontWindow()),NULL);
while(!Button())
;
}
// *************************************************************************** doPreliminaries
void doPreliminaries(void)
{
MoreMasterPointers(32);
InitCursor();
}
// ******************************************************************************* doNewWindow
void doNewWindow(void)
{
WindowRef windowRef;
windowRef = GetNewCWindow(rWindowResourceID,NULL,(WindowRef) -1);
if(windowRef == NULL)
{
SysBeep(10);
ExitToShell();
}
SetPortWindowPort(windowRef);
UseThemeFont(kThemeSystemFont,smSystemScript);
}
// ********************************************************************************** doMemory
void doMemory(void)
{
Handle theHdl;
Size blockSize;
OSErr memoryError;
Str255 theString;
theHdl = NewHandle(1024);
if(theHdl != NULL)
blockSize = GetHandleSize(theHdl);
memoryError = MemError();
if(memoryError == noErr)
{
MoveTo(170,35);
DrawString("\pBlock Size (Bytes) = ");
NumToString(blockSize,theString);
DrawString(theString);
MoveTo(165,55);
DrawString("\pNo Memory Manager errors");
DisposeHandle(theHdl);
}
}
// ******************************************************************************* doResources
void doResources(void)
{
PicHandle pictureHdl;
StringHandle stringHdl;
Rect pictureRect;
OSErr resourceError;
pictureHdl = GetPicture(rPictureResourceID);
if(pictureHdl == NULL)
{
SysBeep(10);
ExitToShell();
}
SetRect(&pictureRect,148,75,348,219);
HNoPurge((Handle) pictureHdl);
DrawPicture(pictureHdl,&pictureRect);
HPurge((Handle) pictureHdl);
stringHdl = GetString(rStringResourceID);
if(stringHdl == NULL)
{
SysBeep(10);
ExitToShell();
}
MoveTo(103,250);
DrawString(*stringHdl);
ReleaseResource((Handle) pictureHdl);
ReleaseResource((Handle) stringHdl);
resourceError = ResError();
if(resourceError == noErr)
{
MoveTo(160,270);
DrawString("\pNo Resource Manager errors");
}
}
// *******************************************************************************************