Solved

'icns' resouce type

Posted on 1998-10-30
7
179 Views
Last Modified: 2013-12-26
How do I create an 'icns' resource and save it to a resource  file? I tried the following but didn't write the resource properly.
      
 fileId = FSpOpenResFile( &mySpec, fsRdWrPerm);
 myErr = GetIconSuite( &myIconSuite, 140,  svAllAvailableData);
 LoadResource(myIconSuite);
 DetachResource(myIconSuite);
 AddResource(myIconSuite, 'icns', -128, "\p");
      ChangedResource(myIconSuite);      
 CloseResFile( fileId );*/

Any inof on how to create an 'icns' resource from and Handle of IconSuite
0
Comment
Question by:dwp090598
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 

Author Comment

by:dwp090598
ID: 1291572
Edited text of question
0
 
LVL 3

Accepted Solution

by:
boonstra earned 100 total points
ID: 1291573
Delete the LoadResource and DetachResource calls.  LoadResource is used to read a purged resource or one that wasn't loaded because SetResLoad was FALSE.  In your case, GetIconSuite has created the resource data in memory, so LoadResource is not needed.

If you check ResError after the DetachResource call in the code you provided, you'll find you get a resNotFound error.  That's because the myIconSuite isn't part of a resource map yet, so it cannot be detached.

I've run the above code (minus LoadResource and DetachResource) on a resource file that contains icon resources, and it correctly creates an 'icns' resource that I've been able to read it back in.

However, I'm not sure why you want to create and save the 'icns' resource.  Isn't it just as easy to recreate it using GetIconSuite when you need it?
0
 

Author Comment

by:dwp090598
ID: 1291574
this answer showed me how to save a resource correctly, but failed to answer what I really needed to know. What I am trying to do is save an handle pointing to an icon suite to an 'icns' resource. 'icns' resource contains an entire IconFamily and is the new resource apple saves icon pixmap data in. Check the "System Resources" file in Syustem 8.5 for an example.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:boonstra
ID: 1291575
Sorry the answer didn't meet your intent.  I'll try to have another look to see if I can answer the real question.
0
 
LVL 3

Expert Comment

by:boonstra
ID: 1291576
On further investigation, the problem is that the handle created in memory by the GetIconSuite command doesn't match what is written in memory as the 'icns' resource.

It appears that the 'icns' resource data would have to be constructed piece by piece.  By disassembling the 'icns' resource, it appears to have the following format:

4 bytes: 'icns'
4 bytes: number of bytes in resource, minus 4

multiple occurrences of the following:
4 bytes: icon resource type (e.g., ics#')
4 bytes: size (N) of icon data that follows, plus 8
N bytes: icon data
.

I was able to create a valid 'icns' resource containing two icon types ('icl4' and 'icl8') with the following code.  You should be able to tailor this to do what you want.

#define kNumRsrcTypes 2
unsigned long rsrcTypes[kNumRsrcTypes] = {
      'icl4','icl8'
};


int main(void)
{
      FSSpec mySpec = {0,0,"\pMyRsrcFile.rsrc"};
      int fileId,i,j;
      Handle rsrcHdl,suiteRsrcHdl;
      OSErr err;
      long rsrcSize;
      
      fileId = FSpOpenResFile(&mySpec,fsRdWrPerm);
      if (fileId<0) DebugStr("\p could not open file");
      
      suiteRsrcHdl = NewHandle(8);
      *(long *)*suiteRsrcHdl = 'icns';
      *(long *)(4 + *suiteRsrcHdl) = 0;
      
      for (j=0; j<kNumRsrcTypes; j++) {
            for (i=128; i<149; i++) {
                  rsrcHdl = GetResource(rsrcTypes[j],128);
                  rsrcSize = GetHandleSize(rsrcHdl);
                  rsrcSize+=8;
                  err = PtrAndHand(&rsrcTypes[j],suiteRsrcHdl,4);
                  err = PtrAndHand(&rsrcSize,suiteRsrcHdl,4);
                  err = HandAndHand(rsrcHdl,suiteRsrcHdl);
                  *(long *)(4 + *suiteRsrcHdl) += 8+GetHandleSize(rsrcHdl);
            }
      }

      AddResource(suiteRsrcHdl,'icns',-128,"\pmyIconSuite");
      if (noErr!=ResError()) DebugStr("\p res err 3");
      ChangedResource(suiteRsrcHdl);
      if (noErr!=ResError()) DebugStr("\p res err 4");
      CloseResFile(fileId);

      return 0;      
}

0
 

Author Comment

by:dwp090598
ID: 1291577
Thanks boonstra, this really helped.
0
 

Author Comment

by:dwp090598
ID: 1291578
Thanks boonstra, this really helped.
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question