Solved

'icns' resouce type

Posted on 1998-10-30
7
171 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
  • 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 84
unable to delete all specified values regedit 38 155
withoutTen challenge 14 88
Line meaning 9 77
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
This video discusses moving either the default database or any database to a new volume.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now