home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Multimedia Jumpstart 1.1a / CD_ROM.BIN / develpmt / source / hotspot / editor / dlg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-03  |  15.9 KB  |  338 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.  
  13.     dlg.c has:
  14.         About -- Processes messages for "About" dialog box
  15.         FrameDlg -- Modeless dialog; allows user to play the movie,
  16.             advance or reverse a frame, or jump to a specified
  17.             frame.  Also displays current frame (e.g. Frame x of y)
  18.         SelectDlg -- Proc for display of current hotspot coords.
  19.         HotspotDlg -- Modal dialog that appears when user double clicks in
  20.             a hotspot rect so that user can set hotspot id,
  21.             command, etc.
  22. */    
  23.  
  24. #include <windows.h>
  25. #include <mmsystem.h>
  26. #include <digitalv.h>
  27. #include <viewer.h>
  28. #include <string.h>
  29. #include <commdlg.h>
  30. #include <stdlib.h>
  31.  
  32. #include "hotspot.h"
  33. #include "avihed.h"            /* specific to this program          */
  34. #include "avihede.h"
  35.  
  36. /*
  37.     About -- calls EndDialog when IDOK or IDCANCEL is recieved.
  38. */
  39.  
  40. BOOL __export CALLBACK About(hDlg, message, wParam, lParam)
  41. HWND hDlg;               /* window handle of the dialog box */
  42. unsigned message;        /* type of message                 */
  43. WORD wParam;             /* message-specific information    */
  44. LONG lParam;
  45. {
  46.     switch (message)
  47.     {
  48.         case WM_INITDIALOG:            /* message: initialize dialog box */
  49.             return (TRUE);
  50.  
  51.         case WM_COMMAND:               /* message: received a command */
  52.             if (wParam == IDOK         /* "OK" box selected?          */
  53.                 || wParam == IDCANCEL) /* System menu close command?  */
  54.             {
  55.                 EndDialog(hDlg, TRUE); /* Exits the dialog box        */
  56.                 return (TRUE);
  57.             }
  58.             break;
  59.     }
  60.     return (FALSE);               /* Didn't process a message    */
  61. }
  62. /*
  63.     FrameDlg -- responds when user presses play, stop, forward frame,
  64.         reverse frame, and goto frame buttons on screen.  See each
  65.         message handler for more comments.
  66. */
  67. BOOL __export CALLBACK FrameDlg(hDlg, message, wParam, lParam)
  68. HWND hDlg;               /* window handle of the dialog box */
  69. unsigned message;        /* type of message                 */
  70. WORD wParam;             /* message-specific information    */
  71. LONG lParam;
  72. {
  73.     char szBuf[129];
  74.     HDC hDC;
  75.     
  76.     switch (message)
  77.     {
  78.         case WM_INITDIALOG:            /* message: initialize dialog box */
  79.             return (TRUE);
  80.  
  81.         case WM_SIZE:
  82.         case WM_MOVE: 
  83.             GetWindowRect(hDlg, &rcwndDlg);
  84.             break;
  85.             
  86.         case WM_COMMAND:
  87.             switch (wParam)
  88.                 {
  89.                 // ID_PLAY -- if playing, seek to current frame minus 1
  90.                 // and stop, by using MCI_SEEK.  Change button to "play".
  91.                 // If not playing, change button to stop and call playmovie().
  92.                 case ID_PLAY:
  93.                     if (pMovieInfo)                        
  94.                         {
  95.                         if (pMovieInfo->fPlaying)
  96.                             {
  97.                             MCI_SEEK_PARMS mciSeek;
  98.                             //playMovie(pMovieInfo, 0);
  99.                             pMovieInfo->fPlaying = FALSE;
  100.                             pMovieInfo->dwCurrentFrame = GetMovieFrame(pMovieInfo);
  101.                             mciSeek.dwTo = pMovieInfo->dwCurrentFrame - 1;
  102.                             mciSendCommand(pMovieInfo->wMCIDeviceID, MCI_SEEK, MCI_TO | MCI_WAIT,
  103.                                         (DWORD) (LPMCI_SEEK_PARMS)&mciSeek);
  104.                     
  105.                             
  106.                             wsprintf(szBuf, "%ld of %ld", pMovieInfo->dwCurrentFrame,
  107.                                                       pMovieInfo->dwMovieLength);
  108.                             SetDlgItemText(hwndDlg, ID_CURRENTFRAME, szBuf);                        
  109.                             SetDlgItemText(hwndDlg, ID_PLAY, "Play");
  110.                             EnableWindow(GetDlgItem(hwndDlg, ID_FORWARD), TRUE);
  111.                             EnableWindow(GetDlgItem(hwndDlg, ID_REVERSE), TRUE);                    
  112.                             }
  113.                         else
  114.                             {                                                
  115.                             SetDlgItemText(hwndDlg, ID_PLAY, "Stop");
  116.                             EnableWindow(GetDlgItem(hwndDlg, ID_FORWARD), FALSE);
  117.                             EnableWindow(GetDlgItem(hwndDlg, ID_REVERSE), FALSE);
  118.                             playMovie(pMovieInfo, 1);
  119.                             pMovieInfo->fPlaying = TRUE;
  120.                             }
  121.                         }
  122.                     break;
  123.                 
  124.                 // ID_FORWARD -- increment dwCurrentFrame and call setMovie
  125.                 // to update the screen, call DrawRects to show hotspots,
  126.                 // call SetDlgItemText to show user new frame #.
  127.                 case ID_FORWARD:
  128.                     if (pMovieInfo->dwCurrentFrame < pMovieInfo->dwMovieLength)
  129.                         {
  130.                         ++pMovieInfo->dwCurrentFrame;
  131.                         setMovie(pMovieInfo, pMovieInfo->dwCurrentFrame, hDlg);
  132.                         hDC = GetDC(pMovieInfo->hwndMovie);
  133.                         DrawRects(hDC, pMovieInfo);
  134.                         ReleaseDC(pMovieInfo->hwndMovie, hDC);
  135.                         wsprintf(szBuf, "%ld of %ld", pMovieInfo->dwCurrentFrame,
  136.                                                       pMovieInfo->dwMovieLength);
  137.                         SetDlgItemText(hDlg, ID_CURRENTFRAME, szBuf);
  138.                         }
  139.                     break;
  140.                     
  141.                 // ID_REVERSE -- decrement dwCurrentFrame and call setMovie
  142.                 // to update the screen, call DrawRects to show hotspots,
  143.                 // call SetDlgItemText to show user new frame #.
  144.                 case ID_REVERSE:
  145.                     if (pMovieInfo->dwCurrentFrame > 0)         // 0 = first frame
  146.                         {
  147.                         --pMovieInfo->dwCurrentFrame;
  148.                         setMovie(pMovieInfo, pMovieInfo->dwCurrentFrame, hDlg);
  149.                         hDC = GetDC(pMovieInfo->hwndMovie);
  150.                         DrawRects(hDC, pMovieInfo);
  151.                         ReleaseDC(pMovieInfo->hwndMovie, hDC);                    
  152.                         wsprintf(szBuf, "%ld of %ld", pMovieInfo->dwCurrentFrame,
  153.                                                       pMovieInfo->dwMovieLength);
  154.                         SetDlgItemText(hDlg, ID_CURRENTFRAME, szBuf);
  155.                         }                                        
  156.                     break;
  157.                     
  158.                 // ID_GOFRAME -- get the frame number from GetDlgItemText,
  159.                 // then put it in dwCurrentFrame and do the same DrawRects
  160.                 // and SetDlgItemText stuff that ID_FORWARD and ID_REVERSE
  161.                 // (see) do.
  162.                 case ID_GOFRAME:
  163.                     {                    
  164.                     DWORD dwFrame;
  165.                     
  166.                     GetDlgItemText(hDlg, ID_FRAMEEDIT, szBuf, sizeof(szBuf) - 1);
  167.                     dwFrame = atol(szBuf);
  168.                                         
  169.                     if (dwFrame != pMovieInfo->dwCurrentFrame &&
  170.                             dwFrame <= pMovieInfo->dwMovieLength &&
  171.                             dwFrame >= 0)
  172.                         {                            
  173.                         pMovieInfo->dwCurrentFrame = dwFrame;
  174.                         setMovie(pMovieInfo, pMovieInfo->dwCurrentFrame, hDlg);
  175.                         hDC = GetDC(pMovieInfo->hwndMovie);
  176.                         DrawRects(hDC, pMovieInfo);
  177.                         ReleaseDC(pMovieInfo->hwndMovie, hDC);                        
  178.                         wsprintf(szBuf, "%ld of %ld", pMovieInfo->dwCurrentFrame,
  179.                                                       pMovieInfo->dwMovieLength);
  180.                         SetDlgItemText(hDlg, ID_CURRENTFRAME, szBuf);                        
  181.                         }
  182.                     }
  183.                     return (TRUE);                                
  184.                 }
  185.             break;
  186.     }
  187.     return (FALSE);               /* Didn't process a message    */
  188. }
  189.  
  190.  
  191. /*
  192.     SelectDlg -- catches WM_MOVE messages and updates rcwndSelectDlg
  193.         to the new coordinates.  This is so the rect can get saved
  194.         and resored from the INI file.
  195. */
  196. BOOL __export CALLBACK SelectDlg(hDlg, message, wParam, lParam)
  197. HWND hDlg;               /* window handle of the dialog box */
  198. unsigned message;        /* type of message                 */
  199. WORD wParam;             /* message-specific information    */
  200. LONG lParam;
  201. {
  202.     switch (message)
  203.     {
  204.         case WM_INITDIALOG:            /* message: initialize dialog box */
  205.             return (TRUE);
  206.             
  207.         case WM_SIZE:
  208.         case WM_MOVE:
  209.             GetWindowRect(hDlg, &rcwndSelectDlg);
  210.             break;
  211.             
  212.     }
  213.     return (FALSE);               /* Didn't process a message    */
  214. }
  215.  
  216. /*
  217.     HotspotDlg -- this is for that big dialog box that pops up when
  218.         you double click a hotspot.  Processes WM_INITDIALOG and
  219.         IDOK messages.  WM_INITDIALOG transfers data from the MOVIEINFO
  220.         into the dialog box, and the IDOK routine transfers the data
  221.         from the dialog box back into the MOVIEINFO.
  222. */
  223. BOOL __export CALLBACK HotspotDlg(hDlg, message, wParam, lParam)  
  224. HWND hDlg;               /* window handle of the dialog box */
  225. unsigned message;        /* type of message                 */
  226. WORD wParam;             /* message-specific information    */
  227. LONG lParam;
  228. {
  229.     char szBuf[129];
  230.     static PHOTSPOT pHotspot;    
  231.     BOOL bTranslated;
  232.     
  233.     switch (message)
  234.     {
  235.         case WM_INITDIALOG:            /* message: initialize dialog box */
  236.             // pHotspot passed as lParam
  237.             pHotspot = (PHOTSPOT) lParam;
  238.             SetDlgItemInt(hDlg, ID_LEFT, pHotspot->rc.left, FALSE);
  239.             SetDlgItemInt(hDlg, ID_TOP, pHotspot->rc.top, FALSE);
  240.             SetDlgItemInt(hDlg, ID_RIGHT, pHotspot->rc.right, FALSE);
  241.             SetDlgItemInt(hDlg, ID_BOTTOM, pHotspot->rc.bottom, FALSE);            
  242.             SetDlgItemInt(hDlg, ID_BEGINFRAME, pHotspot->BeginFrame, FALSE);
  243.             SetDlgItemInt(hDlg, ID_ENDFRAME, pHotspot->EndFrame, FALSE);
  244.             CheckRadioButton(hDlg, ID_CONTINUE, ID_JUMP, pHotspot->OnClick);
  245.             if (pHotspot->pszCommand)
  246.                 SetDlgItemText(hDlg, ID_COMMAND, pHotspot->pszCommand);
  247.             if (pHotspot->pszHotspotID)
  248.                 SetDlgItemText(hDlg, ID_HOTSPOTID, pHotspot->pszHotspotID);
  249.             SetDlgItemInt(hDlg, ID_TOFRAME, pHotspot->ToFrame, FALSE);
  250.             return (TRUE);
  251.  
  252.         case WM_COMMAND:
  253.             switch (wParam)
  254.                 {
  255.                 case IDOK:
  256.                     //if (!GetDlgItemText(hDlg, ID_HOTSPOTID, szBuf, sizeof(szBuf) - 1))
  257.                         //{
  258.                         //MessageBox(hDlg, "You must enter Hotspot ID","Incomplete record:",
  259.                                         //MB_OK | MB_ICONEXCLAMATION);
  260.                         //return (TRUE);                                        
  261.                         //}
  262.                     //else            // yeah, this is pretty scary 
  263.                         {
  264.                         PHOTSPOT pHotspotList, pHsp;
  265.                         pHotspotList = pHotspot;
  266.                         
  267.                         if (pHotspotList->pPrev)            // if there's a previous, then
  268.                             {
  269.                             while (pHotspotList->pPrev)     // get to beginning of list
  270.                                 {
  271.                                 pHotspotList = pHotspotList->pPrev;
  272.                                 if (pHotspotList)           // if not NULL, store it
  273.                                     pHsp = pHotspotList;
  274.                                 }
  275.                             }
  276.                                                     else
  277.                         pHsp = pHotspotList;            // if not, just set to the only one
  278.                         while (pHsp)
  279.                             {
  280.                             //if (pHsp != pHotspot)           // if it's not this one
  281.                                 //{
  282.                                 //if (pHsp->pszHotspotID)     // if memory allocated
  283.                                     //{                       // compare the strings
  284.                                     //if (0 == (lstrcmp(pHsp->pszHotspotID, szBuf)))
  285.                                         //{
  286.                                         //MessageBox(hDlg, "Another Hotspot already has that ID",
  287.                                                 //"Error", MB_OK | MB_ICONEXCLAMATION);
  288.                                         //return (TRUE);
  289.                                         //}
  290.                                     //}
  291.                                 //}
  292.                             pHsp = pHsp->pNext;             // next one
  293.                             }                        
  294.                         }                        
  295.                     pHotspot->rc.left = GetDlgItemInt(hDlg, ID_LEFT, &bTranslated, TRUE);
  296.                     pHotspot->rc.top = GetDlgItemInt(hDlg, ID_TOP, &bTranslated, TRUE);
  297.                     pHotspot->rc.right = GetDlgItemInt(hDlg, ID_RIGHT, &bTranslated, TRUE);
  298.                     pHotspot->rc.bottom = GetDlgItemInt(hDlg, ID_BOTTOM, &bTranslated, TRUE);
  299.                     pHotspot->BeginFrame = GetDlgItemInt(hDlg, ID_BEGINFRAME, &bTranslated, TRUE);
  300.                     pHotspot->EndFrame = GetDlgItemInt(hDlg, ID_ENDFRAME, &bTranslated, TRUE);
  301.                     if (IsDlgButtonChecked(hDlg, ID_CONTINUE))
  302.                         pHotspot->OnClick = ID_CONTINUE;
  303.                     else if (IsDlgButtonChecked(hDlg, ID_STOP))
  304.                         pHotspot->OnClick = ID_STOP;
  305.                     else if (IsDlgButtonChecked(hDlg, ID_JUMP))
  306.                         {
  307.                         pHotspot->OnClick = ID_JUMP;
  308.                         pHotspot->ToFrame = GetDlgItemInt(hDlg, ID_TOFRAME, &bTranslated, TRUE);                            
  309.                         }                            
  310.                     else        // impossible case, but...
  311.                         pHotspot->OnClick = ID_CONTINUE;                    
  312.                     if (GetDlgItemText(hDlg, ID_COMMAND, szBuf, sizeof(szBuf) - 1))
  313.                         {
  314.                         if (pHotspot->pszCommand)           // free the old one if there is
  315.                             FREE(pHotspot->pszCommand);                            
  316.                         pHotspot->pszCommand = (LPSTR) ALLOCATE(lstrlen(szBuf) + 1);
  317.                         lstrcpy(pHotspot->pszCommand, szBuf);
  318.                         }
  319.                     if (GetDlgItemText(hDlg, ID_HOTSPOTID, szBuf, sizeof(szBuf) - 1))
  320.                         {
  321.                         if (pHotspot->pszHotspotID)           // free the old one if there is
  322.                             FREE(pHotspot->pszHotspotID);                        
  323.                         pHotspot->pszHotspotID = (LPSTR) ALLOCATE(lstrlen(szBuf) + 1);
  324.                         lstrcpy(pHotspot->pszHotspotID, szBuf);
  325.                         }                        
  326.                     bModified = TRUE;                        
  327.                     EndDialog(hDlg, TRUE);
  328.                     return (TRUE);
  329.  
  330.                 case IDCANCEL:
  331.                     EndDialog(hDlg, FALSE);
  332.                     return (TRUE);                                        
  333.                 }
  334.             break;
  335.     }
  336.     return (FALSE);               /* Didn't process a message    */
  337. }
  338.