/* hspPlayAVI -- allocates a movieinfo structure, stores the window handle you gave it in the hwndParent entry in the movieinfo, and stores the callback you provide in the movieinfo -- these will be used by the subclassproc. It next calls InitHotspots to get a hotspot list, and fileOpenMovie which will open the AVI file and create a child window (a child of the window that you pass in to this function). The window is returned in the movieinfo. It then subclasses the window fileOpenMovie made, by changing the pointer to its WindowProc to ours (via SetWindowLong). It uses SetProp to hook this movieinfo up to both windows. The subclassed wndproc will get the movieinfo from the child window when a button is clicked, and the parent windowproc will get the movieinfo from the parent when Viewer wants to know the pane size. Finally, playMovie is called to start the movie. */ LONG CALLBACK __export hspPlayAVI(HWND hwnd, LPSTR szAVIFile, LPSTR szIniFile, FARPROC lpfnhspAVICallback) { HGLOBAL hglb; PMOVIEINFO pMovieInfo; hglb = GlobalAlloc(GHND, sizeof(MOVIEINFO)); pMovieInfo = (PMOVIEINFO)GlobalLock(hglb); if (!pMovieInfo) return (0L); pMovieInfo->hwndParent = hwnd; pMovieInfo->lpfnhspAVICallback = lpfnhspAVICallback; if (!hwnd) { Message("Invalid window specified for playing AVI file."); return 0L; } InitHotspots(pMovieInfo, szIniFile); OutputDebugString("calling fileOpenMovie\n"); fileOpenMovie(pMovieInfo, szAVIFile); GlobalUnlock(hglb); pMovieInfo->lpfnOldProc = (FARPROC) GetWindowLong (pMovieInfo->hwndMovie, GWL_WNDPROC); SetWindowLong (pMovieInfo->hwndMovie, GWL_WNDPROC, (LONG) SbClsProc); SetProp(pMovieInfo->hwndMovie, (LPSTR) szMovieInfo, hglb); SetProp(hwnd, (LPSTR) szMovieInfo, hglb); OutputDebugString("calling positionMovie\n"); positionMovie(pMovieInfo); OutputDebugString("calling playMovie\n"); { MCI_DGV_SETVIDEO_PARMS dgv; UINT uDevice; dgv.dwValue = (DWORD) ICAVIDrawProc; //MakeProcInstance((FARPROC) ICAVIDrawProc,hInstApp); dgv.dwItem = MCI_AVI_SETVIDEO_DRAW_PROCEDURE; uDevice = pMovieInfo->wMCIDeviceID; if (uDevice) { DWORD dw; dw = mciSendCommand(uDevice, MCI_SETVIDEO, MCI_DGV_SETVIDEO_ITEM | MCI_DGV_SETVIDEO_VALUE, (DWORD) (MCI_DGV_SETVIDEO_PARMS FAR *)&dgv); OutputDebugString("set draw proc!\n"); if (dw != 0) { MessageBox(GetFocus(), "The currently installed MCIAVI does not " "support the MCI_AVI_SETVIDEO_DRAW_PROCEDURE " "command during play.","MCI Problem", MB_OK | MB_ICONHAND); } } else { MessageBox(GetFocus(),"movie info has no device id", "real bummer",MB_OK); } playMovie(pMovieInfo, 1); } return (0L); }
/* fileOpenMovie -- uses MCI_OPEN to open the AVI file. Saves the device ID so we can do stuff like find the frame size. uses MCI_WINDOW to show the playback window uses MCI_DGV_STATUS_HWND to get a handle to the window gets the movie length with GetMovieLength, and positions the movie with positionMovie. Uses InvalidateRect to get window repainted (which will show the first frame) Gives user an annoying messagebox if this doesn't work. */ void fileOpenMovie(PMOVIEINFO pMovieInfo, LPSTR szFilename) { if (pMovieInfo == NULL) { OutputDebugString("No MOVIEINFO for specified movie when trying to open AVI file."); return; } if (lstrlen(szFilename)){ MCI_DGV_OPEN_PARMS mciOpen; MCI_DGV_WINDOW_PARMS mciWindow; MCI_DGV_STATUS_PARMS mciStatus; /* we got a filename, now close any old movie and open */ /* the new one. */ if (pMovieInfo->fMovieOpen) fileCloseMovie(pMovieInfo, TRUE); /* we have a .AVI movie to open, use MCI */ /* set up the open parameters */ mciOpen.dwCallback = NULL; mciOpen.wDeviceID = mciOpen.wReserved0 = mciOpen.wReserved1 = 0; mciOpen.lpstrDeviceType = NULL; mciOpen.lpstrElementName = szFilename; mciOpen.lpstrAlias = NULL; mciOpen.dwStyle = NULL; // WS_CHILD; mciOpen.hWndParent = NULL; //pMovieInfo->hwndParent; /* try to open the file */ if (mciSendCommand(0, MCI_OPEN, (DWORD)(MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_DGV_OPEN_WS), (DWORD)(LPMCI_DGV_OPEN_PARMS)&mciOpen) == 0){ /* we opened the file o.k., now set up to */ /* play it. */ pMovieInfo->wMCIDeviceID = mciOpen.wDeviceID; /* save ID */ pMovieInfo->fMovieOpen = TRUE; /* a movie was opened */ /* show the playback window */ mciWindow.dwCallback = NULL; mciWindow.hWnd = pMovieInfo->hwndParent;// NULL; mciWindow.wReserved1 = mciWindow.wReserved2 = 0; mciWindow.nCmdShow = SW_SHOW; mciWindow.lpstrText = (LPSTR)NULL; mciSendCommand(pMovieInfo->wMCIDeviceID, MCI_WINDOW, MCI_DGV_WINDOW_STATE | MCI_DGV_WINDOW_HWND, (DWORD)(LPMCI_DGV_WINDOW_PARMS)&mciWindow); /* get the window handle */ mciStatus.dwItem = MCI_DGV_STATUS_HWND; mciSendCommand(pMovieInfo->wMCIDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD)(LPMCI_STATUS_PARMS)&mciStatus); pMovieInfo->hwndMovie = pMovieInfo->hwndParent; //(HWND)mciStatus.dwReturn; /* get movie length */ pMovieInfo->dwMovieLength = GetMovieLength(pMovieInfo); pMovieInfo->dwCurrentFrame = 0; /* now get the movie centered */ positionMovie(pMovieInfo); } else { /* generic error for open */ MessageBox(pMovieInfo->hwndParent, "Unable to open Movie", NULL, MB_ICONEXCLAMATION|MB_OK); pMovieInfo->fMovieOpen = FALSE; } } /* cause an update to occur */ InvalidateRect(pMovieInfo->hwndParent, NULL, FALSE); UpdateWindow(pMovieInfo->hwndParent); pMovieInfo->lLastSeek = 0; }