1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
#include "GlobalFunc.h"
#include "T2BitImage.h"
#include "T2DlgItemMovie.h"
#include "T2ImageObj.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// love how this is obviously based off player/playfile/playfile.cpp
// from the DirectX SDK
#define WM_GRAPHNOTIFY WM_USER+13
#define HELPER_RELEASE(x) { if (x) x->Release(); x = NULL; }
T2DlgItemMovie::T2DlgItemMovie(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette)
: T2DlgItem(inDoc, inImageObj, inPalette)
{
mImage = NULL;
mImageObj = NULL;
mPlaying = false;
mUnusedInterface = NULL;
mGraph = NULL;
mMediaControl = NULL;
mMediaEvent = NULL;
mVideoWindow = NULL;
mMediaPosition = NULL;
}
/*virtual*/ T2DlgItemMovie::~T2DlgItemMovie() {
if (mImage)
delete mImage;
if (mImageObj)
delete mImageObj;
}
/*virtual*/ int T2DlgItemMovie::OnT2DlgItemCreate(CREATESTRUCT* cs) {
return T2DlgItem::OnT2DlgItemCreate(cs);
}
/*virtual*/ BOOL T2DlgItemMovie::OnT2DlgItemEraseBkgnd(CDC* pDC) {
CRect rect;
GetClientRect(rect);
int save = pDC->SaveDC();
pDC->SelectPalette(mPalette, false);
pDC->RealizePalette();
if (mImageObj) {
int objectID = mImageObj->FindObject("STIL");
mImageObj->DrawObject(pDC, objectID, rect);
}
pDC->RestoreDC(save);
return true;
}
void T2DlgItemMovie::SetStillScreenID(const char* inName, int inResID) {
if (mPlaying)
CloseMovie();
mPlaying = false;
if (mImage)
delete mImage;
if (mImageObj)
delete mImageObj;
InvalidateRect(NULL);
#line 76
mImage = new T2BitImage(inName, inResID, true);
mImageObj = new T2ImageObj;
mImageObj->AddObject("STIL", -1, *mImage, NULL, false, false);
}
void T2DlgItemMovie::SetQTMovieName(CString& inName) {
CString dirName = "MOVIE";
if (inName.GetLength()) {
CString str = "";
if (str == "") {
#pragma var_order(path, ofStruct, towerDir)
char towerDir[512];
GetTowerDirectory(towerDir);
CString path = towerDir;
path = path + dirName + "\\" + inName;
OFSTRUCT ofStruct;
if (OpenFile(path, &ofStruct, OF_EXIST) != HFILE_ERROR)
str = path;
}
if (str == "") {
#pragma var_order(volName, root, fsFlags)
CString root = GetInstallSourceDrive();
root += ":\\";
char volName[256];
volName[0] = 0;
DWORD fsFlags;
GetVolumeInformation(root, volName, 256, NULL, 0, &fsFlags, NULL, 0);
if (!strcmp(volName, "TheTower2")) {
CString path = root + dirName + "\\" + inName;
OFSTRUCT ofStruct;
if (OpenFile(path, &ofStruct, OF_EXIST) != HFILE_ERROR)
str = path;
}
}
if (str != "")
PlayMovie(str);
}
}
void T2DlgItemMovie::PlayMovie(const char* inName) {
if (mPlaying)
CloseMovie();
WCHAR *wFile = (WCHAR *) malloc(1024);
// bug: this passes 1024 and not 512 as cchWideChar
MultiByteToWideChar(CP_ACP, 0, inName, -1, wFile, 1024);
HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **) &mGraph);
if (SUCCEEDED(hr)) {
mGraph->QueryInterface(IID_IMediaControl, (void **) &mMediaControl);
mGraph->QueryInterface(IID_IMediaEventEx, (void **) &mMediaEvent);
mGraph->QueryInterface(IID_IVideoWindow, (void **) &mVideoWindow);
mGraph->QueryInterface(IID_IMediaPosition, (void **) &mMediaPosition);
hr = mGraph->RenderFile(wFile, NULL);
mVideoWindow->put_Owner((OAHWND) m_hWnd);
mVideoWindow->put_WindowStyle(WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD);
mMediaEvent->SetNotifyWindow((OAHWND) m_hWnd, WM_GRAPHNOTIFY, 0);
mVideoWindow->put_BackgroundPalette(-1);
CRect videoRect;
mVideoWindow->GetWindowPosition(&videoRect.left, &videoRect.top, &videoRect.right, &videoRect.bottom);
videoRect.left = 0;
videoRect.top = 0;
CRect clientRect;
GetClientRect(clientRect);
SIZE sz;
sz.cy = videoRect.Height();
videoRect.top = (clientRect.Height() - sz.cy) / 2;
videoRect.bottom = videoRect.top + sz.cy;
sz.cx = videoRect.Width();
videoRect.left = (clientRect.Width() - sz.cx) / 2;
videoRect.right = videoRect.left + sz.cx;
mVideoWindow->SetWindowPosition(videoRect.left, videoRect.top, videoRect.Width(), videoRect.Height());
if (SUCCEEDED(hr)) {
mMediaControl->Run();
mPlaying = true;
}
}
if (FAILED(hr)) {
// "Active Movieの初期化に失敗しました。" - Failed to initialize Active Movie.
MessageBox(
"Active Movie\x82\xCC\x8F\x89\x8A\xFA\x89\xBB\x82\xC9\x8E\xB8\x94\x73\x82\xB5\x82\xDC\x82\xB5\x82\xBD\x81\x42");
}
free(wFile);
}
void T2DlgItemMovie::CloseMovie() {
if (mMediaControl)
mMediaControl->Stop();
if (mVideoWindow) {
mVideoWindow->put_Visible(0);
mVideoWindow->put_Owner(NULL);
HELPER_RELEASE(mVideoWindow);
}
HELPER_RELEASE(mUnusedInterface);
HELPER_RELEASE(mGraph);
HELPER_RELEASE(mMediaControl);
HELPER_RELEASE(mMediaEvent);
HELPER_RELEASE(mMediaPosition);
}
/*virtual*/ LRESULT T2DlgItemMovie::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_GRAPHNOTIFY:
{
HRESULT hr;
LONG evCode;
LONG evParam1;
LONG evParam2;
while (SUCCEEDED(mMediaEvent->GetEvent(&evCode, &evParam1, &evParam2, 0))) {
hr = mMediaEvent->FreeEventParams(evCode, evParam1, evParam2);
if (evCode == EC_COMPLETE && mVideoWindow) {
mMediaPosition->put_CurrentPosition(0);
mMediaControl->Run();
}
}
break;
}
case WM_DESTROY:
CloseMovie();
break;
}
return CWnd::WindowProc(message, wParam, lParam);
}
/*virtual*/ void T2DlgItemMovie::OnT2Close() {
}
|