Solved

'icns' resouce type

Posted on 1998-10-30
7
175 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
Independent Software Vendors: 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating Labels and Frequency list style reports in SAS code 9 112
iSeries DB2 Query 2 98
Use of condition with 'serial' in ansible 2 86
mapAB Challlenge 35 173
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 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