home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / mac / programm / 20382 < prev    next >
Encoding:
Text File  |  1992-12-29  |  4.6 KB  |  177 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!paladin.american.edu!gatech!usenet.ins.cwru.edu!agate!dog.ee.lbl.gov!hellgate.utah.edu!fcom.cc.utah.edu!news
  3. From: Dmitry Boldyrev <dmitry@chemistry.chem.utah.edu>
  4. Subject: Re: Volume icons?
  5. Message-ID: <1992Dec29.183956.26804@fcom.cc.utah.edu>
  6. Sender: news@fcom.cc.utah.edu
  7. Organization: University of Utah
  8. X-Useragent: Nuntius v1.0
  9. References: <168C3EAA8.UC525655@mizzou1.missouri.edu>
  10. Date: Tue, 29 Dec 92 18:39:56 GMT
  11. Lines: 164
  12.  
  13. >Hi all-
  14. >Where can i find the icon definition for a mounted volume?
  15. >I have looked through all the (I think) relevant material in
  16. >IM I-VI, but obviously I've missed something somewhere, but all
  17. >IM talks about are file icons. Help!
  18. >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. >Mark Eaton                    | Opinions? We're not allowed to have
  20. >UC525655@MIZZOU1.MISSOURI.EDU | opinions at Mizzou... get back to me
  21. >                              | in '94 when I graduate... ;)
  22.  
  23. Hello Mark,
  24. Here, I have smth for you...
  25. ============================ CUT HERE ============================
  26.  
  27. /*    this is the data structure pointed to in the result of the
  28.     disk driver call csCode=21 (get ICN#/comment).  This call
  29.     works on all devices.
  30. */
  31.  
  32. typedef struct TInfoBlk {
  33.     unsigned char    icon[128];        /* icon */
  34.     unsigned char    mask[128];        /* mask */
  35.     Str255            infoString;        /* info string (for get info) */
  36. } TInfoBlk,*TInfoPtr;
  37.  
  38. void GetDiskInfo(short driverRefNum,short driveNum,TInfoPtr *dataBlk);
  39. void DrawInfo(TInfoPtr infoBlock);
  40. void GetAllInfo(void);
  41. void GetAllInfoYourWay(void);
  42.  
  43.  
  44. void main(void)
  45. {
  46.     WindowPtr theWindow;
  47.     Rect wBounds;
  48.  
  49. #ifdef THINK_C
  50.     InitGraf(&thePort);
  51. #else
  52.     InitGraf(&qd.thePort);
  53. #endif
  54.     InitFonts();
  55.     InitWindows();
  56.     InitMenus();
  57.     TEInit();
  58.     InitDialogs(nil);
  59.     FlushEvents(everyEvent,0);
  60.     InitCursor();
  61.     
  62.     SetRect(&wBounds,40,40,100,100);
  63.     theWindow = NewWindow
  64. (nil,&wBounds,(StringPtr)"\pIcons",true,documentProc,
  65.                 (WindowPtr)(-1),true,0L);
  66.     SetPort(theWindow);
  67.     GetAllInfo();
  68.     DisposeWindow(theWindow);
  69. }
  70.  
  71.  
  72. /*    This routine traverses the currently mounted volumes
  73.     index using PBHGetVInfo().  The drive # and device
  74.     driver number for each volume is extracted from the
  75.     parameter block, and passed into GetDiskInfo() to
  76.     call the disk drivers.
  77.     
  78.     Once the data has been retrieved, the icon is plotted
  79. */
  80.  
  81. void GetAllInfo(void)
  82. {
  83.     HParamBlockRec vBlock;    /* volume parameter block used to traverse
  84. mounted vols */
  85.     OSErr err;
  86.     TInfoPtr dataBlk;        /* pointer used to point to result of csCode=21 call
  87. */
  88.     
  89.     vBlock.volumeParam.ioNamePtr = nil;
  90.     vBlock.volumeParam.ioVRefNum = 0;
  91.     vBlock.volumeParam.ioVolIndex = 1;
  92.     
  93.     do {
  94.         err = PBHGetVInfo (&vBlock,false);
  95.         vBlock.volumeParam.ioVolIndex++;
  96.         if (err==noErr) {
  97.             GetDiskInfo(vBlock.volumeParam.ioVDRefNum,
  98.                         vBlock.volumeParam.ioVDrvInfo,&dataBlk);
  99.             if (dataBlk)
  100.                 DrawInfo(dataBlk);
  101.         }
  102.     } while (err==noErr);
  103. }
  104.  
  105.  
  106. /*    GetDiskInfo() makes the call to the volume's driver to get the
  107.     volume icon and info string.  A pointer to this data is returned
  108.     by reference in dataBlk
  109.     
  110.     This routine tries to call the disk's driver with csCode=22,
  111.     which attempts to get info on a specific physical volume.
  112.     
  113.     If the csCode=22 call fails, I call csCode=21 to get the generalized
  114.     media icon.
  115.     
  116.     Both calls are documented in IM V-470
  117. */
  118.  
  119. void GetDiskInfo(short driverRefNum,short driveNum,TInfoPtr *dataBlk)
  120. {
  121.     CntrlParam pBlock;
  122.     OSErr err;
  123.     
  124.     pBlock.ioVRefNum = driveNum;
  125.     pBlock.ioCRefNum = driverRefNum;
  126.     pBlock.csCode = 22;
  127.     
  128.     err = PBControl(&pBlock,false);
  129.     if (err==controlErr) {
  130.         pBlock.ioVRefNum = driveNum;
  131.         pBlock.ioCRefNum = driverRefNum;
  132.         pBlock.csCode = 21;
  133.         err = PBControl(&pBlock,false);
  134.     }
  135.     
  136.     if (err==noErr)
  137.         *dataBlk = (TInfoPtr) *(Ptr *)pBlock.csParam; /* messy way to get the
  138. locn out */
  139.     else *dataBlk = nil;
  140. }
  141.  
  142.  
  143.  
  144. /*    this routine uses CopyBits to draw the icon on the screen (ignoring
  145. the mask and
  146.     the info string).  Make sure you put up a window and call SetPort()
  147. first!
  148. */
  149.  
  150. void DrawInfo(TInfoPtr infoBlock)
  151. {
  152.     BitMap iconMap;
  153.     Rect destRect;
  154.     
  155.     iconMap.baseAddr = (Ptr)infoBlock;
  156.     iconMap.rowBytes = 4;
  157.     SetRect(&iconMap.bounds,0,0,32,32);
  158.     SetRect(&destRect,0,0,32,32);
  159.     OffsetRect(&destRect,10,10);
  160.     CopyBits(&iconMap,&thePort->portBits,&iconMap.bounds,&destRect,
  161.             srcCopy,nil);
  162.     while (!Button());
  163.     while (Button());
  164. }
  165. ============================ CUT HERE ============================
  166.  
  167. Guess, it make sense..
  168. .................................................
  169. Dmitry Boldyrev,
  170. Department of Chemistry, University of Utah.
  171. Internet: dmitry@chemistry.chem.utah.edu
  172.           
  173.                -- "I only know that I know nothing"
  174.                                       - Socrates
  175.