2 * Copyright 2000 Eric Pouech
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mci);
43 static LRESULT WINAPI MCIWndProc(HWND hWnd, UINT wMsg, WPARAM lParam1, LPARAM lParam2);
45 #define CTL_PLAYSTOP 0x3200
46 #define CTL_MENU 0x3201
47 #define CTL_TRACKBAR 0x3202
49 /***********************************************************************
50 * MCIWndRegisterClass [MSVFW32.@]
52 BOOL WINAPI MCIWndRegisterClass(HINSTANCE hInst)
56 /* since window creation will also require some common controls, init them */
60 wc.lpfnWndProc = MCIWndProc;
62 wc.cbWndExtra = sizeof(MCIWndInfo*);
67 wc.lpszMenuName = NULL;
68 wc.lpszClassName = "MCIWndClass";
70 return RegisterClassA(&wc);
74 /***********************************************************************
75 * MCIWndCreate [MSVFW32.@]
76 * MCIWndCreateA [MSVFW32.@]
78 HWND VFWAPIV MCIWndCreateA(HWND hwndParent, HINSTANCE hInstance,
79 DWORD dwStyle, LPCSTR szFile)
84 TRACE("%p %p %lx %s\n", hwndParent, hInstance, dwStyle, szFile);
86 MCIWndRegisterClass(hInstance);
88 mwi = HeapAlloc(GetProcessHeap(), 0, sizeof(*mwi));
91 mwi->dwStyle = dwStyle;
93 mwi->lpName = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(szFile) + 1), szFile);
98 wndStyle = ((hwndParent) ? (WS_CHILD|WS_BORDER) : WS_OVERLAPPEDWINDOW) |
99 WS_VISIBLE | (dwStyle & 0xFFFF0000);
101 if (CreateWindowExA(0, "MCIWndClass", NULL, wndStyle,
102 CW_USEDEFAULT, CW_USEDEFAULT,
103 CW_USEDEFAULT, CW_USEDEFAULT,
104 hwndParent, NULL, hInstance, mwi))
107 if(mwi->lpName) HeapFree(GetProcessHeap(), 0, mwi->lpName);
108 HeapFree(GetProcessHeap(), 0, mwi);
112 /***********************************************************************
113 * MCIWndCreateW [MSVFW32.@]
115 HWND VFWAPIV MCIWndCreateW(HWND hwndParent, HINSTANCE hInstance,
116 DWORD dwStyle, LPCWSTR szFile)
118 FIXME("%p %p %lx %s\n", hwndParent, hInstance, dwStyle, debugstr_w(szFile));
120 MCIWndRegisterClass(hInstance);
125 static DWORD MCIWND_GetStatus(MCIWndInfo* mwi)
127 MCI_DGV_STATUS_PARMSA mdsp;
129 memset(&mdsp, 0, sizeof(mdsp));
130 mdsp.dwItem = MCI_STATUS_MODE;
131 if (mciSendCommandA(mwi->mci, MCI_STATUS, MCI_WAIT|MCI_STATUS_ITEM, (DWORD)&mdsp))
132 return MCI_MODE_NOT_READY;
133 if (mdsp.dwReturn == MCI_MODE_STOP && mwi->uTimer) {
134 TRACE("Killing timer\n");
135 KillTimer(mwi->hWnd, 0);
138 return mdsp.dwReturn;
141 static DWORD MCIWND_Get(MCIWndInfo* mwi, DWORD what)
143 MCI_DGV_STATUS_PARMSA mdsp;
145 memset(&mdsp, 0, sizeof(mdsp));
147 if (mciSendCommandA(mwi->mci, MCI_STATUS, MCI_WAIT|MCI_STATUS_ITEM, (DWORD)&mdsp))
149 return mdsp.dwReturn;
152 static void MCIWND_SetText(MCIWndInfo* mwi)
156 if (mwi->dwStyle & MCIWNDF_SHOWNAME) {
157 strcpy(buffer, mwi->lpName);
162 if (mwi->dwStyle & (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE)) {
163 if (*buffer) strcat(buffer, " ");
167 if (mwi->dwStyle & MCIWNDF_SHOWPOS) {
168 sprintf(buffer + strlen(buffer), "%ld", MCIWND_Get(mwi, MCI_STATUS_POSITION));
171 if ((mwi->dwStyle & (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE)) == (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE)) {
172 strcat(buffer, " - ");
175 if (mwi->dwStyle & MCIWNDF_SHOWMODE) {
176 switch (MCIWND_GetStatus(mwi)) {
177 case MCI_MODE_NOT_READY: strcat(buffer, "not ready"); break;
178 case MCI_MODE_PAUSE: strcat(buffer, "paused"); break;
179 case MCI_MODE_PLAY: strcat(buffer, "playing"); break;
180 case MCI_MODE_STOP: strcat(buffer, "stopped"); break;
181 case MCI_MODE_OPEN: strcat(buffer, "open"); break;
182 case MCI_MODE_RECORD: strcat(buffer, "recording"); break;
183 case MCI_MODE_SEEK: strcat(buffer, "seeking"); break;
184 default: strcat(buffer, "???"); break;
187 if (mwi->dwStyle & (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE)) {
188 strcat(buffer, " )");
190 TRACE("=> '%s'\n", buffer);
191 SetWindowTextA(mwi->hWnd, buffer);
194 static void MCIWND_Create(HWND hWnd, LPCREATESTRUCTA cs)
196 MCI_DGV_OPEN_PARMSA mdopn;
197 MCI_DGV_RECT_PARMS mdrct;
201 MCIWndInfo* mwi = (MCIWndInfo*)cs->lpCreateParams;
203 SetWindowLongA(hWnd, 0, (LPARAM)mwi);
206 /* now open MCI player for AVI file */
207 memset(&mdopn, 0, sizeof(mdopn));
208 mdopn.lpstrElementName = mwi->lpName;
209 mdopn.dwStyle = WS_VISIBLE|WS_CHILD;
210 mdopn.hWndParent = hWnd;
212 mmr = mciSendCommandA(0, MCI_OPEN, MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_DGV_OPEN_WS, (LPARAM)&mdopn);
214 MessageBoxA(GetTopWindow(hWnd), "Cannot open file", "MciWnd", MB_OK);
217 mwi->mci = mdopn.wDeviceID;
219 /* grab AVI window size */
220 memset(&mdrct, 0, sizeof(mdrct));
221 mmr = mciSendCommandA(mwi->mci, MCI_WHERE, MCI_DGV_WHERE_DESTINATION, (LPARAM)&mdrct);
223 WARN("Cannot get window rect\n");
226 cx = mdrct.rc.right - mdrct.rc.left;
227 cy = mdrct.rc.bottom - mdrct.rc.top;
229 AdjustWindowRect(&mdrct.rc, GetWindowLongA(hWnd, GWL_STYLE), FALSE);
230 SetWindowPos(hWnd, 0, 0, 0, mdrct.rc.right - mdrct.rc.left,
231 mdrct.rc.bottom - mdrct.rc.top + 32, SWP_NOMOVE|SWP_NOZORDER);
233 /* adding the other elements: play/stop button, menu button, status */
234 hChld = CreateWindowExA(0, "BUTTON", "Play", WS_CHILD|WS_VISIBLE, 0, cy, 32, 32,
235 hWnd, (HMENU)CTL_PLAYSTOP,
236 (HINSTANCE)GetWindowLongA(hWnd, GWL_HINSTANCE), 0L);
237 TRACE("Get Button1: %p\n", hChld);
238 hChld = CreateWindowExA(0, "BUTTON", "Menu", WS_CHILD|WS_VISIBLE, 32, cy, 32, 32,
239 hWnd, (HMENU)CTL_MENU,
240 (HINSTANCE)GetWindowLongA(hWnd, GWL_HINSTANCE), 0L);
241 TRACE("Get Button2: %p\n", hChld);
242 hChld = CreateWindowExA(0, TRACKBAR_CLASSA, "", WS_CHILD|WS_VISIBLE, 64, cy, cx - 64, 32,
243 hWnd, (HMENU)CTL_TRACKBAR,
244 (HINSTANCE)GetWindowLongA(hWnd, GWL_HINSTANCE), 0L);
245 TRACE("Get status: %p\n", hChld);
246 SendMessageA(hChld, TBM_SETRANGEMIN, 0L, 0L);
247 SendMessageA(hChld, TBM_SETRANGEMAX, 1L, MCIWND_Get(mwi, MCI_STATUS_LENGTH));
249 /* FIXME: no need to set it if child window */
253 static void MCIWND_Paint(MCIWndInfo* mwi, WPARAM wParam)
258 hdc = (wParam) ? (HDC)wParam : BeginPaint(mwi->hWnd, &ps);
259 /* something to do ? */
260 if (!wParam) EndPaint(mwi->hWnd, &ps);
263 static void MCIWND_ToggleState(MCIWndInfo* mwi)
265 MCI_GENERIC_PARMS mgp;
266 MCI_DGV_PLAY_PARMS mdply;
268 memset(&mgp, 0, sizeof(mgp));
269 memset(&mdply, 0, sizeof(mdply));
271 switch (MCIWND_GetStatus(mwi)) {
272 case MCI_MODE_NOT_READY:
273 case MCI_MODE_RECORD:
276 TRACE("Cannot do much...\n");
279 mciSendCommandA(mwi->mci, MCI_RESUME, MCI_WAIT, (LPARAM)&mgp);
282 mciSendCommandA(mwi->mci, MCI_PAUSE, MCI_WAIT, (LPARAM)&mgp);
286 mciSendCommandA(mwi->mci, MCI_PLAY, MCI_FROM, (LPARAM)&mdply);
287 mwi->uTimer = SetTimer(mwi->hWnd, 0, 333, 0L);
288 TRACE("Timer=%u\n", mwi->uTimer);
293 static LRESULT MCIWND_Command(MCIWndInfo* mwi, WPARAM wParam, LPARAM lParam)
295 switch (LOWORD(wParam)) {
296 case CTL_PLAYSTOP: MCIWND_ToggleState(mwi); break;
300 MessageBoxA(0, "ooch", "NIY", MB_OK);
305 static void MCIWND_Timer(MCIWndInfo* mwi, WPARAM wParam, LPARAM lParam)
307 TRACE("%ld\n", MCIWND_Get(mwi, MCI_STATUS_POSITION));
308 SendDlgItemMessageA(mwi->hWnd, CTL_TRACKBAR, TBM_SETPOS, 1, MCIWND_Get(mwi, MCI_STATUS_POSITION));
312 static void MCIWND_Close(MCIWndInfo* mwi)
314 MCI_GENERIC_PARMS mgp;
316 memset(&mgp, 0, sizeof(mgp));
318 mciSendCommandA(mwi->mci, MCI_CLOSE, 0, (LPARAM)&mgp);
321 static LRESULT WINAPI MCIWndProc(HWND hWnd, UINT wMsg, WPARAM lParam1, LPARAM lParam2)
323 MCIWndInfo* mwi = (MCIWndInfo*)GetWindowLongA(hWnd, 0);
325 if (mwi || wMsg == WM_CREATE) {
328 MCIWND_Create(hWnd, (CREATESTRUCTA*)lParam2);
332 HeapFree(GetProcessHeap(), 0, mwi->lpName);
333 HeapFree(GetProcessHeap(), 0, mwi);
336 MCIWND_Paint(mwi, lParam1);
339 return MCIWND_Command(mwi, lParam1, lParam2);
341 MCIWND_Timer(mwi, lParam1, lParam2);
346 return DefWindowProcA(hWnd, wMsg, lParam1, lParam2);