#define kBaseResID 128
#define kMoveToFront (WindowPtr)-1L
#define kIconBytes 128
typedef unsigned char uint8_t;
typedef uint8_t IconData[kIconBytes];
char *gMyIconDataPtr; // NewPtr() returns a char ptr not a IconData ptr...more below
BitMap myIconMap; // initialized a BitMap on the stack...would love to know how to create
// a BitMap struct on the heap
WindowPtr window;
Rect destRect;
/* Functions */
void ToolBoxInit(void);
void WindowInit(void);
void IconInit(void);
/* main */
void main(void) {
ToolBoxInit();
WindowInit();
IconInit();
while( !Button() );
}
/* ToolBoxInit */
void ToolBoxInit(void) {
InitGraf(&thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(nil);
InitCursor();
}
/* WindowInit */
void WindowInit(void) {
window = GetNewWindow(kBaseResID, nil, kMoveToFront);
if(window == nil) {
SysBeep(10);
ExitToShell();
}
ShowWindow(window);
SetPort(window);
SetRect(&destRect, 40, 20, 200, 180); //set up the Rect within the window
// set it to 5 multiples of 32
}
/* IconInit */
void IconInit(void) {
gMyIconDataPtr = NewPtr(sizeof(IconData)); //this worked great! But again, returns a ptr
// to a char, not a ptr to type IconData
// NewPtr appears to be like malloc() but always
// returns a pointer to a char
myIconMap.baseAddr = gMyIconDataPtr; // set BitMap's baseAddr to gMyIconDataPtr
myIconMap.rowBytes = 4; // simplified your code to just '4' based on a Think C // reference
SetRect(&myIconMap.bounds, 0, 0, 31, 31); // set the bounds Rect to size of bit image
StuffHex(gMyIconDataPtr, "\p003FE000007FF000007FFC0000C78E000180070001000380020001800200008002000080020000800200008002F83C800200028002783C80025AAC8002008080020080800200408002044080020240800207E180031FF38001B01F0001C8270000C7CE0000FBFC00007C3A0000BFFD0007BFF5C018CFC3382080010440800102");
//the only thing I'm not sure I understand below is the 2nd argument to CopyBits().
//thePort is a apparently a global variable and the Think C reference showed this as
//an example and it worked. However, your code to use the window->port.portBits
//made more sense to me, but I kept getting a compile error 'No member value'
//or something like that. Any explanation to that?
CopyBits(&myIconMap, &thePort->portBits, &myIconMap.bounds, &destRect, srcCopy, nil);
}