home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Multimedia Jumpstart 1.1a / CD_ROM.BIN / develpmt / source / hotspot / vbx / hotspot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-02  |  4.9 KB  |  164 lines

  1. /**************************************************************************
  2.  *
  3.  *  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4.  *  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5.  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6.  *  PURPOSE.
  7.  *
  8.  *  Copyright (c) 1993  Microsoft Corporation.  All Rights Reserved.
  9.  * 
  10.  **************************************************************************/
  11. /*
  12.     hotspot.c:
  13.         DeleteHotspot -- deletes a hotspot from linked list
  14.         DeleteHotspotList -- deletes them all
  15.         AddHotspot -- adds a hotspot to linked list
  16.         InitHotspots -- reads hotspots from HOT file into linked list
  17. */
  18.  
  19. #include <windows.h>
  20. #include <mmsystem.h>
  21. #include <digitalv.h>
  22. #include <string.h>
  23. #include <direct.h>
  24.  
  25. #include "hotspot.h"
  26.  
  27. char szMovieInfo[] = "MovieInfo";
  28.  
  29. /*
  30.     DeleteHotspot -- give it a pointer to a hotspot structure and
  31.         a pointer to a movieinfo structure, and it will delete the
  32.         hotspot from the movieinfo's hotspot list.  Minor bug: 
  33.         If you give it a hotspot for a different movieinfo,
  34.         it will free it anyway, but if you give it a hotspot and
  35.         a NULL movieinfo, it won't.  The list is doubly linked, so
  36.          it just switches some pointers.
  37. */
  38. void DeleteHotspot(PMOVIEINFO pMovieInfo, PHOTSPOT pHotspot)
  39. {
  40.     PHOTSPOT pPrev, pNext;
  41.     if (!pMovieInfo || !pHotspot)
  42.         return;
  43.     pPrev = pHotspot->pPrev;
  44.     pNext = pHotspot->pNext;
  45.     if (pPrev)
  46.     {
  47.         pPrev->pNext = pNext;
  48.     } else
  49.     {
  50.         pMovieInfo->pHotspotList = pNext;
  51.     }
  52.     if (pNext)
  53.     {
  54.         pNext->pPrev = pPrev;
  55.     }
  56.     if (pHotspot->pszCommand)
  57.         FREE(pHotspot->pszCommand);
  58.     if (pHotspot->pszHotspotID)
  59.         FREE(pHotspot->pszHotspotID);
  60.     FREE(pHotspot);
  61.     pHotspot = NULL;
  62. }
  63.  
  64. /*
  65.     DeleteHotspotList --
  66.         deletes a list of hotspots in a movieinfo -- faster that using
  67.         DeleteHotspot because it doesn't twiddle pointers -- just
  68.         marches down the next pointers and frees everything.
  69. */
  70. void DeleteHotspotList(PMOVIEINFO pMovieInfo)
  71. {
  72.     PHOTSPOT pHotspot, pNext;
  73.     pHotspot = pMovieInfo->pHotspotList;
  74.     while (pHotspot)
  75.     {
  76.         pNext = pHotspot->pNext;
  77.         DeleteHotspot(pMovieInfo, pHotspot);
  78.         pHotspot = pNext;
  79.     }
  80.     pMovieInfo->pHotspotList = NULL;
  81. }
  82.  
  83. /*
  84.     AddHotspot -- adds a hotspot (which you give it) to the front of
  85.         a hotspot list in the movieinfo (which you also give it).
  86.         The hotspot should be allocated using ALLOCATE -- see hotspot.h
  87. */
  88. void AddHotspot(PMOVIEINFO pMovieInfo, PHOTSPOT pHotspot)
  89. {
  90.     if (pMovieInfo->pHotspotList)
  91.     {
  92.         pMovieInfo->pHotspotList->pPrev = pHotspot;
  93.         pHotspot->pNext = pMovieInfo->pHotspotList;
  94.     }
  95.     pMovieInfo->pHotspotList = pHotspot;
  96. }
  97.  
  98. /* 
  99.     InitHotspots -- you give it a pointer to a movie structure and a
  100.         filename, and it adds a hotspot list to the movie structure from
  101.         the data in the file.  The file is a HOT file, and is stored
  102.         in a binary format: there's a tag indicating a .HOT file, then
  103.         the number of hotspots.  Then it loops through, reading six numbers
  104.         (the rect and the start/end frames) and two strings (the hostpotID
  105.         and the viewer command) for each one.  Strings of length 0 are
  106.         transformed into NULLs.
  107. */
  108. BOOL InitHotspots(PMOVIEINFO pMovieInfo, LPSTR pszHotFile)
  109. {
  110.     HFILE hFile;
  111.     char szBuf[256];
  112.     int hotcount, i;
  113.     PHOTSPOT pHotspot;
  114.     hFile = _lopen(pszHotFile,READ);
  115.     if (hFile == HFILE_ERROR)
  116.     {
  117.         MessageBox(GetFocus(),pszHotFile,"Can't read this file:",MB_OK);
  118.     }
  119.     _lread(hFile,szBuf,2);
  120.     if (szBuf[0] != 'H' || szBuf[1] != 'H')
  121.     {
  122.         MessageBox(GetFocus(),"File is not a hotspot file","Out of luck",MB_OK);
  123.     }
  124.     _lread(hFile,&hotcount,sizeof(hotcount));
  125.     DeleteHotspotList(pMovieInfo);
  126.     for (i=0;i<hotcount;i++)
  127.     {
  128.         int x;
  129.         if (! (pHotspot = (PHOTSPOT)ALLOCATE(sizeof(HOTSPOT))))
  130.         {
  131.             MessageBox(GetFocus(),"Unable to allocate HOTSPOT structure",
  132.                 "Big Problem Here",MB_OK);
  133.         }
  134.         _lread(hFile,&pHotspot->rc.left,sizeof(pHotspot->rc.left));
  135.         _lread(hFile,&pHotspot->rc.top,sizeof(pHotspot->rc.top));
  136.         _lread(hFile,&pHotspot->rc.right,sizeof(pHotspot->rc.right));
  137.         _lread(hFile,&pHotspot->rc.bottom,sizeof(pHotspot->rc.bottom));
  138.         _lread(hFile,&x,sizeof(x));
  139.         if (x)
  140.         {
  141.             _lread(hFile,szBuf,x); szBuf[x] = '\0';
  142.             pHotspot->pszHotspotID = (LPSTR) ALLOCATE(lstrlen(szBuf) + 1);
  143.             lstrcpy(pHotspot->pszHotspotID, szBuf);
  144.         }
  145.         else pHotspot->pszHotspotID = NULL;
  146.             _lread(hFile,&x,sizeof(x)); szBuf[x] = '\0';
  147.         if (x) _lwrite(hFile,pHotspot->pszCommand,x);
  148.             if (x)
  149.         {
  150.             _lread(hFile,szBuf,x);
  151.             pHotspot->pszCommand = (LPSTR) ALLOCATE(lstrlen(szBuf) + 1);
  152.             lstrcpy(pHotspot->pszCommand, szBuf);
  153.         }
  154.         else pHotspot->pszCommand = NULL;
  155.             _lread(hFile,&pHotspot->BeginFrame,sizeof(pHotspot->BeginFrame));
  156.         _lread(hFile,&pHotspot->EndFrame,sizeof(pHotspot->EndFrame));
  157.         _lread(hFile,&pHotspot->OnClick,sizeof(pHotspot->OnClick));
  158.         _lread(hFile,&pHotspot->ToFrame,sizeof(pHotspot->ToFrame));
  159.         AddHotspot(pMovieInfo, pHotspot);
  160.     }
  161.     _lclose(hFile);
  162.     return TRUE;
  163. }
  164.