d3dxof: Do not expect a separator when there is no element.
[wine/multimedia.git] / dlls / msvfw32 / mciwnd.c
blobff8a0369df00b046ade31b012187253e705de444
1 /*
2 * Copyright 2000 Eric Pouech
3 * Copyright 2003 Dmitry Timoshkov
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 * FIXME:
20 * Add support for all remaining MCI_ commands and MCIWNDM_ messages.
21 * Add support for MCIWNDF_RECORD.
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winternl.h"
32 #include "vfw.h"
33 #include "digitalv.h"
34 #include "commctrl.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mci);
40 extern HMODULE MSVFW32_hModule;
41 static const WCHAR mciWndClassW[] = {'M','C','I','W','n','d','C','l','a','s','s',0};
43 typedef struct
45 DWORD dwStyle;
46 MCIDEVICEID mci;
47 HDRVR hdrv;
48 int alias;
49 UINT dev_type;
50 UINT mode;
51 long position;
52 SIZE size; /* size of the original frame rect */
53 int zoom;
54 LPWSTR lpName;
55 HWND hWnd, hwndOwner;
56 UINT uTimer;
57 MCIERROR lasterror;
58 WCHAR return_string[128];
59 WORD active_timer, inactive_timer;
60 } MCIWndInfo;
62 static LRESULT WINAPI MCIWndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
64 #define CTL_PLAYSTOP 0x3200
65 #define CTL_MENU 0x3201
66 #define CTL_TRACKBAR 0x3202
68 /***********************************************************************
69 * MCIWndRegisterClass [MSVFW32.@]
71 * NOTE: Native always uses its own hInstance
73 BOOL VFWAPIV MCIWndRegisterClass(void)
75 WNDCLASSW wc;
77 /* Since we are going to register a class belonging to MSVFW32
78 * and later we will create windows with a different hInstance
79 * CS_GLOBALCLASS is needed. And because the second attempt
80 * to register a global class will fail we need to test whether
81 * the class was already registered.
83 wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS | CS_OWNDC | CS_GLOBALCLASS;
84 wc.lpfnWndProc = MCIWndProc;
85 wc.cbClsExtra = 0;
86 wc.cbWndExtra = sizeof(MCIWndInfo*);
87 wc.hInstance = MSVFW32_hModule;
88 wc.hIcon = 0;
89 wc.hCursor = LoadCursorW(0, MAKEINTRESOURCEW(IDC_ARROW));
90 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
91 wc.lpszMenuName = NULL;
92 wc.lpszClassName = mciWndClassW;
94 if (RegisterClassW(&wc)) return TRUE;
95 if (GetLastError() == ERROR_CLASS_ALREADY_EXISTS) return TRUE;
97 return FALSE;
100 /***********************************************************************
101 * MCIWndCreateW [MSVFW32.@]
103 HWND VFWAPIV MCIWndCreateW(HWND hwndParent, HINSTANCE hInstance,
104 DWORD dwStyle, LPCWSTR szFile)
106 TRACE("%p %p %x %s\n", hwndParent, hInstance, dwStyle, debugstr_w(szFile));
108 MCIWndRegisterClass();
110 if (!hInstance) hInstance = GetModuleHandleW(0);
112 if (hwndParent)
113 dwStyle |= WS_VISIBLE | WS_BORDER /*| WS_CHILD*/;
114 else
115 dwStyle |= WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
117 return CreateWindowExW(0, mciWndClassW, NULL,
118 dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
119 0, 0, 300, 0,
120 hwndParent, 0, hInstance, (LPVOID)szFile);
123 /***********************************************************************
124 * MCIWndCreate [MSVFW32.@]
125 * MCIWndCreateA [MSVFW32.@]
127 HWND VFWAPIV MCIWndCreateA(HWND hwndParent, HINSTANCE hInstance,
128 DWORD dwStyle, LPCSTR szFile)
130 HWND ret;
131 UNICODE_STRING fileW;
133 if (szFile)
134 RtlCreateUnicodeStringFromAsciiz(&fileW, szFile);
135 else
136 fileW.Buffer = NULL;
138 ret = MCIWndCreateW(hwndParent, hInstance, dwStyle, fileW.Buffer);
140 RtlFreeUnicodeString(&fileW);
141 return ret;
144 static inline void MCIWND_notify_mode(MCIWndInfo *mwi)
146 if (mwi->dwStyle & MCIWNDF_NOTIFYMODE)
148 UINT new_mode = SendMessageW(mwi->hWnd, MCIWNDM_GETMODEW, 0, 0);
149 if (new_mode != mwi->mode)
151 mwi->mode = new_mode;
152 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYMODE, (WPARAM)mwi->hWnd, new_mode);
157 static inline void MCIWND_notify_pos(MCIWndInfo *mwi)
159 if (mwi->dwStyle & MCIWNDF_NOTIFYPOS)
161 long new_pos = SendMessageW(mwi->hWnd, MCIWNDM_GETPOSITIONW, 0, 0);
162 if (new_pos != mwi->position)
164 mwi->position = new_pos;
165 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYPOS, (WPARAM)mwi->hWnd, new_pos);
170 static inline void MCIWND_notify_size(MCIWndInfo *mwi)
172 if (mwi->dwStyle & MCIWNDF_NOTIFYSIZE)
173 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYSIZE, (WPARAM)mwi->hWnd, 0);
176 static inline void MCIWND_notify_error(MCIWndInfo *mwi)
178 if (mwi->dwStyle & MCIWNDF_NOTIFYERROR)
179 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYERROR, (WPARAM)mwi->hWnd, (LPARAM)mwi->lasterror);
182 static void MCIWND_UpdateState(MCIWndInfo *mwi)
184 WCHAR buffer[1024];
186 if (!mwi->mci)
188 /* FIXME: get this from resources */
189 static const WCHAR no_deviceW[] = {'N','o',' ','D','e','v','i','c','e',0};
190 SetWindowTextW(mwi->hWnd, no_deviceW);
191 return;
194 MCIWND_notify_pos(mwi);
196 if (!(mwi->dwStyle & MCIWNDF_NOPLAYBAR))
197 SendDlgItemMessageW(mwi->hWnd, CTL_TRACKBAR, TBM_SETPOS, TRUE, mwi->position);
199 if (!(mwi->dwStyle & MCIWNDF_SHOWALL))
200 return;
202 if ((mwi->dwStyle & MCIWNDF_SHOWNAME) && mwi->lpName)
203 strcpyW(buffer, mwi->lpName);
204 else
205 *buffer = 0;
207 if (mwi->dwStyle & (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE))
209 static const WCHAR spaceW[] = {' ',0};
210 static const WCHAR l_braceW[] = {'(',0};
212 if (*buffer) strcatW(buffer, spaceW);
213 strcatW(buffer, l_braceW);
216 if (mwi->dwStyle & MCIWNDF_SHOWPOS)
218 WCHAR posW[64];
220 posW[0] = 0;
221 SendMessageW(mwi->hWnd, MCIWNDM_GETPOSITIONW, 64, (LPARAM)posW);
222 strcatW(buffer, posW);
225 if ((mwi->dwStyle & (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE)) == (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE))
227 static const WCHAR dashW[] = {' ','-',' ',0};
228 strcatW(buffer, dashW);
231 if (mwi->dwStyle & MCIWNDF_SHOWMODE)
233 WCHAR modeW[64];
235 modeW[0] = 0;
236 SendMessageW(mwi->hWnd, MCIWNDM_GETMODEW, 64, (LPARAM)modeW);
237 strcatW(buffer, modeW);
240 if (mwi->dwStyle & (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE))
242 static const WCHAR r_braceW[] = {')',0};
243 strcatW(buffer, r_braceW);
246 TRACE("=> %s\n", debugstr_w(buffer));
247 SetWindowTextW(mwi->hWnd, buffer);
250 static LRESULT MCIWND_Create(HWND hWnd, LPCREATESTRUCTW cs)
252 HWND hChld;
253 MCIWndInfo *mwi;
254 static const WCHAR buttonW[] = {'b','u','t','t','o','n',0};
256 mwi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*mwi));
257 if (!mwi) return -1;
259 SetWindowLongW(hWnd, 0, (LPARAM)mwi);
261 mwi->dwStyle = cs->style;
262 /* There is no need to show stats if there is no caption */
263 if ((mwi->dwStyle & WS_CAPTION) != WS_CAPTION)
264 mwi->dwStyle &= ~MCIWNDF_SHOWALL;
266 mwi->hWnd = hWnd;
267 mwi->hwndOwner = cs->hwndParent;
268 mwi->active_timer = 500;
269 mwi->inactive_timer = 2000;
270 mwi->mode = MCI_MODE_NOT_READY;
271 mwi->position = -1;
272 mwi->zoom = 100;
274 if (!(mwi->dwStyle & MCIWNDF_NOMENU))
276 static const WCHAR menuW[] = {'M','e','n','u',0};
278 hChld = CreateWindowExW(0, buttonW, menuW, WS_CHILD|WS_VISIBLE, 32, cs->cy, 32, 32,
279 hWnd, (HMENU)CTL_MENU, cs->hInstance, 0L);
280 TRACE("Get Button2: %p\n", hChld);
283 if (!(mwi->dwStyle & MCIWNDF_NOPLAYBAR))
285 INITCOMMONCONTROLSEX init;
286 static const WCHAR playW[] = {'P','l','a','y',0};
288 /* adding the other elements: play/stop button, menu button, status */
289 hChld = CreateWindowExW(0, buttonW, playW, WS_CHILD|WS_VISIBLE, 0, cs->cy, 32, 32,
290 hWnd, (HMENU)CTL_PLAYSTOP, cs->hInstance, 0L);
291 TRACE("Get Button1: %p\n", hChld);
293 init.dwSize = sizeof(init);
294 init.dwICC = ICC_BAR_CLASSES;
295 InitCommonControlsEx(&init);
297 hChld = CreateWindowExW(0, TRACKBAR_CLASSW, NULL, WS_CHILD|WS_VISIBLE, 64, cs->cy, cs->cx - 64, 32,
298 hWnd, (HMENU)CTL_TRACKBAR, cs->hInstance, 0L);
299 TRACE("Get status: %p\n", hChld);
302 /* This sets the default window size */
303 SendMessageW(hWnd, MCI_CLOSE, 0, 0);
305 if (cs->lpCreateParams)
307 LPARAM lParam;
309 /* MCI wnd class is prepared to be embedded as an MDI child window */
310 if (cs->dwExStyle & WS_EX_MDICHILD)
312 MDICREATESTRUCTW *mdics = cs->lpCreateParams;
313 lParam = mdics->lParam;
315 else
316 lParam = (LPARAM)cs->lpCreateParams;
318 /* If it's our internal class pointer, file name is a unicode string */
319 if (cs->lpszClass == mciWndClassW)
320 SendMessageW(hWnd, MCIWNDM_OPENW, 0, lParam);
321 else
323 /* Otherwise let's try to figure out what string format is used */
324 HWND parent = cs->hwndParent;
325 if (!parent) parent = GetWindow(hWnd, GW_OWNER);
327 SendMessageW(hWnd, IsWindowUnicode(parent) ? MCIWNDM_OPENW : MCIWNDM_OPENA, 0, lParam);
331 return 0;
334 static void MCIWND_ToggleState(MCIWndInfo *mwi)
336 switch (SendMessageW(mwi->hWnd, MCIWNDM_GETMODEW, 0, 0))
338 case MCI_MODE_NOT_READY:
339 case MCI_MODE_RECORD:
340 case MCI_MODE_SEEK:
341 case MCI_MODE_OPEN:
342 TRACE("Cannot do much...\n");
343 break;
345 case MCI_MODE_PAUSE:
346 SendMessageW(mwi->hWnd, MCI_RESUME, 0, 0);
347 break;
349 case MCI_MODE_PLAY:
350 SendMessageW(mwi->hWnd, MCI_PAUSE, 0, 0);
351 break;
353 case MCI_MODE_STOP:
354 SendMessageW(mwi->hWnd, MCI_STOP, 0, 0);
355 break;
359 static LRESULT MCIWND_Command(MCIWndInfo *mwi, WPARAM wParam, LPARAM lParam)
361 switch (LOWORD(wParam))
363 case CTL_PLAYSTOP: MCIWND_ToggleState(mwi); break;
364 case CTL_MENU:
365 case CTL_TRACKBAR:
366 default:
367 FIXME("support for command %04x not implement yet\n", LOWORD(wParam));
369 return 0L;
372 static void MCIWND_notify_media(MCIWndInfo *mwi)
374 if (mwi->dwStyle & (MCIWNDF_NOTIFYMEDIAA | MCIWNDF_NOTIFYMEDIAW))
376 if (!mwi->lpName)
378 static const WCHAR empty_str[1];
379 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYMEDIA, (WPARAM)mwi->hWnd, (LPARAM)empty_str);
381 else
383 if (mwi->dwStyle & MCIWNDF_NOTIFYANSI)
385 char *ansi_name;
386 int len;
388 len = WideCharToMultiByte(CP_ACP, 0, mwi->lpName, -1, NULL, 0, NULL, NULL);
389 ansi_name = HeapAlloc(GetProcessHeap(), 0, len);
390 WideCharToMultiByte(CP_ACP, 0, mwi->lpName, -1, ansi_name, len, NULL, NULL);
392 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYMEDIA, (WPARAM)mwi->hWnd, (LPARAM)ansi_name);
394 HeapFree(GetProcessHeap(), 0, ansi_name);
396 else
397 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYMEDIA, (WPARAM)mwi->hWnd, (LPARAM)mwi->lpName);
402 static MCIERROR mci_generic_command(MCIWndInfo *mwi, UINT cmd)
404 MCI_GENERIC_PARMS mci_generic;
406 mci_generic.dwCallback = 0;
407 mwi->lasterror = mciSendCommandW(mwi->mci, cmd, 0, (DWORD_PTR)&mci_generic);
409 if (mwi->lasterror)
410 return mwi->lasterror;
412 MCIWND_notify_mode(mwi);
413 MCIWND_UpdateState(mwi);
414 return 0;
417 static LRESULT mci_get_devcaps(MCIWndInfo *mwi, UINT cap)
419 MCI_GETDEVCAPS_PARMS mci_devcaps;
421 mci_devcaps.dwItem = cap;
422 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_GETDEVCAPS,
423 MCI_GETDEVCAPS_ITEM,
424 (DWORD_PTR)&mci_devcaps);
425 if (mwi->lasterror)
426 return 0;
428 return mci_devcaps.dwReturn;
431 static LRESULT MCIWND_KeyDown(MCIWndInfo *mwi, UINT key)
433 TRACE("%p, key %04x\n", mwi->hWnd, key);
435 switch(key)
437 case VK_ESCAPE:
438 SendMessageW(mwi->hWnd, MCI_STOP, 0, 0);
439 return 0;
441 default:
442 return 0;
446 static LRESULT WINAPI MCIWndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
448 MCIWndInfo *mwi;
450 TRACE("%p %04x %08lx %08lx\n", hWnd, wMsg, wParam, lParam);
452 mwi = (MCIWndInfo*)GetWindowLongPtrW(hWnd, 0);
453 if (!mwi && wMsg != WM_CREATE)
454 return DefWindowProcW(hWnd, wMsg, wParam, lParam);
456 switch (wMsg)
458 case WM_CREATE:
459 MCIWND_Create(hWnd, (CREATESTRUCTW *)lParam);
460 break;
462 case WM_DESTROY:
463 if (mwi->uTimer)
464 KillTimer(hWnd, mwi->uTimer);
466 if (mwi->mci)
467 SendMessageW(hWnd, MCI_CLOSE, 0, 0);
469 HeapFree(GetProcessHeap(), 0, mwi);
471 DestroyWindow(GetDlgItem(hWnd, CTL_MENU));
472 DestroyWindow(GetDlgItem(hWnd, CTL_PLAYSTOP));
473 DestroyWindow(GetDlgItem(hWnd, CTL_TRACKBAR));
474 break;
476 case WM_PAINT:
478 MCI_DGV_UPDATE_PARMS mci_update;
479 PAINTSTRUCT ps;
481 mci_update.hDC = (wParam) ? (HDC)wParam : BeginPaint(hWnd, &ps);
483 mciSendCommandW(mwi->mci, MCI_UPDATE,
484 MCI_DGV_UPDATE_HDC | MCI_DGV_UPDATE_PAINT,
485 (DWORD_PTR)&mci_update);
487 if (!wParam) EndPaint(hWnd, &ps);
488 return 1;
491 case WM_COMMAND:
492 return MCIWND_Command(mwi, wParam, lParam);
494 case WM_KEYDOWN:
495 return MCIWND_KeyDown(mwi, wParam);
497 case WM_NCACTIVATE:
498 if (mwi->uTimer)
500 KillTimer(hWnd, mwi->uTimer);
501 mwi->uTimer = SetTimer(hWnd, 1, wParam ? mwi->active_timer : mwi->inactive_timer, NULL);
503 break;
505 case WM_TIMER:
506 MCIWND_UpdateState(mwi);
507 return 0;
509 case WM_SIZE:
510 SetWindowPos(GetDlgItem(hWnd, CTL_PLAYSTOP), 0, 0, HIWORD(lParam) - 32, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
511 SetWindowPos(GetDlgItem(hWnd, CTL_MENU), 0, 32, HIWORD(lParam) - 32, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
512 SetWindowPos(GetDlgItem(hWnd, CTL_TRACKBAR), 0, 64, HIWORD(lParam) - 32, LOWORD(lParam) - 64, 32, SWP_NOACTIVATE);
514 if (!(mwi->dwStyle & MCIWNDF_NOAUTOSIZEMOVIE))
516 RECT rc;
518 rc.left = rc.top = 0;
519 rc.right = LOWORD(lParam);
520 rc.bottom = HIWORD(lParam);
521 if (!(mwi->dwStyle & MCIWNDF_NOPLAYBAR))
522 rc.bottom -= 32; /* subtract the height of the playbar */
523 SendMessageW(hWnd, MCIWNDM_PUT_DEST, 0, (LPARAM)&rc);
525 MCIWND_notify_size(mwi);
526 break;
528 case MM_MCINOTIFY:
529 MCIWND_notify_mode(mwi);
530 MCIWND_UpdateState(mwi);
531 return 0;
533 case MCIWNDM_OPENA:
535 UNICODE_STRING nameW;
536 TRACE("MCIWNDM_OPENA %s\n", debugstr_a((LPSTR)lParam));
537 RtlCreateUnicodeStringFromAsciiz(&nameW, (LPCSTR)lParam);
538 lParam = (LPARAM)nameW.Buffer;
540 /* fall through */
541 case MCIWNDM_OPENW:
543 RECT rc;
544 HCURSOR hCursor;
545 MCI_OPEN_PARMSW mci_open;
546 MCI_GETDEVCAPS_PARMS mci_devcaps;
547 WCHAR aliasW[64];
548 WCHAR drv_name[MAX_PATH];
549 static const WCHAR formatW[] = {'%','d',0};
550 static const WCHAR mci32W[] = {'m','c','i','3','2',0};
551 static const WCHAR system_iniW[] = {'s','y','s','t','e','m','.','i','n','i',0};
553 TRACE("MCIWNDM_OPENW %s\n", debugstr_w((LPWSTR)lParam));
555 if (wParam == MCIWNDOPENF_NEW)
557 SendMessageW(hWnd, MCIWNDM_NEWW, 0, lParam);
558 goto end_of_mci_open;
561 if (mwi->uTimer)
563 KillTimer(hWnd, mwi->uTimer);
564 mwi->uTimer = 0;
567 hCursor = LoadCursorW(0, (LPWSTR)IDC_WAIT);
568 hCursor = SetCursor(hCursor);
570 mci_open.lpstrElementName = (LPWSTR)lParam;
571 wsprintfW(aliasW, formatW, HandleToLong(hWnd) + 1);
572 mci_open.lpstrAlias = aliasW;
573 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_OPEN,
574 MCI_OPEN_ELEMENT | MCI_OPEN_ALIAS | MCI_WAIT,
575 (DWORD_PTR)&mci_open);
576 SetCursor(hCursor);
578 if (mwi->lasterror && !(mwi->dwStyle & MCIWNDF_NOERRORDLG))
580 /* FIXME: get the caption from resources */
581 static const WCHAR caption[] = {'M','C','I',' ','E','r','r','o','r',0};
582 WCHAR error_str[MAXERRORLENGTH];
584 mciGetErrorStringW(mwi->lasterror, error_str, MAXERRORLENGTH);
585 MessageBoxW(hWnd, error_str, caption, MB_ICONEXCLAMATION | MB_OK);
586 MCIWND_notify_error(mwi);
587 goto end_of_mci_open;
590 mwi->mci = mci_open.wDeviceID;
591 mwi->alias = HandleToLong(hWnd) + 1;
593 mwi->lpName = HeapAlloc(GetProcessHeap(), 0, (strlenW((LPWSTR)lParam) + 1) * sizeof(WCHAR));
594 strcpyW(mwi->lpName, (LPWSTR)lParam);
596 MCIWND_UpdateState(mwi);
598 mci_devcaps.dwItem = MCI_GETDEVCAPS_DEVICE_TYPE;
599 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_GETDEVCAPS,
600 MCI_GETDEVCAPS_ITEM,
601 (DWORD_PTR)&mci_devcaps);
602 if (mwi->lasterror)
604 MCIWND_notify_error(mwi);
605 goto end_of_mci_open;
608 mwi->dev_type = mci_devcaps.dwReturn;
610 drv_name[0] = 0;
611 SendMessageW(hWnd, MCIWNDM_GETDEVICEW, 256, (LPARAM)drv_name);
612 if (drv_name[0] && GetPrivateProfileStringW(mci32W, drv_name, NULL,
613 drv_name, MAX_PATH, system_iniW))
614 mwi->hdrv = OpenDriver(drv_name, NULL, 0);
616 if (mwi->dev_type == MCI_DEVTYPE_DIGITAL_VIDEO)
618 MCI_DGV_WINDOW_PARMSW mci_window;
620 mci_window.hWnd = hWnd;
621 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_WINDOW,
622 MCI_DGV_WINDOW_HWND,
623 (DWORD_PTR)&mci_window);
624 if (mwi->lasterror)
626 MCIWND_notify_error(mwi);
627 goto end_of_mci_open;
631 if (SendMessageW(hWnd, MCIWNDM_GET_DEST, 0, (LPARAM)&rc) == 0)
633 mwi->size.cx = rc.right - rc.left;
634 mwi->size.cy = rc.bottom - rc.top;
636 rc.right = MulDiv(mwi->size.cx, mwi->zoom, 100);
637 rc.bottom = MulDiv(mwi->size.cy, mwi->zoom, 100);
638 SendMessageW(hWnd, MCIWNDM_PUT_DEST, 0, (LPARAM)&rc);
640 else
642 GetClientRect(hWnd, &rc);
643 rc.bottom = rc.top;
646 if (!(mwi->dwStyle & MCIWNDF_NOPLAYBAR))
647 rc.bottom += 32; /* add the height of the playbar */
648 AdjustWindowRect(&rc, GetWindowLongW(hWnd, GWL_STYLE), FALSE);
649 SetWindowPos(hWnd, 0, 0, 0, rc.right - rc.left,
650 rc.bottom - rc.top, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
652 SendDlgItemMessageW(hWnd, CTL_TRACKBAR, TBM_SETRANGEMIN, 0L, 0L);
653 SendDlgItemMessageW(hWnd, CTL_TRACKBAR, TBM_SETRANGEMAX, 1,
654 SendMessageW(hWnd, MCIWNDM_GETLENGTH, 0, 0));
655 mwi->uTimer = SetTimer(hWnd, 1, mwi->active_timer, NULL);
657 MCIWND_notify_media(mwi);
659 end_of_mci_open:
660 if (wMsg == MCIWNDM_OPENA)
661 HeapFree(GetProcessHeap(), 0, (void *)lParam);
662 return mwi->lasterror;
665 case MCIWNDM_GETDEVICEID:
666 TRACE("MCIWNDM_GETDEVICEID\n");
667 return mwi->mci;
669 case MCIWNDM_GETALIAS:
670 TRACE("MCIWNDM_GETALIAS\n");
671 return mwi->alias;
673 case MCIWNDM_GET_SOURCE:
675 MCI_DGV_RECT_PARMS mci_rect;
677 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_WHERE,
678 MCI_DGV_WHERE_SOURCE,
679 (DWORD_PTR)&mci_rect);
680 if (mwi->lasterror)
682 MCIWND_notify_error(mwi);
683 return mwi->lasterror;
685 *(RECT *)lParam = mci_rect.rc;
686 TRACE("MCIWNDM_GET_SOURCE: %s\n", wine_dbgstr_rect(&mci_rect.rc));
687 return 0;
690 case MCIWNDM_GET_DEST:
692 MCI_DGV_RECT_PARMS mci_rect;
694 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_WHERE,
695 MCI_DGV_WHERE_DESTINATION,
696 (DWORD_PTR)&mci_rect);
697 if (mwi->lasterror)
699 MCIWND_notify_error(mwi);
700 return mwi->lasterror;
702 *(RECT *)lParam = mci_rect.rc;
703 TRACE("MCIWNDM_GET_DEST: %s\n", wine_dbgstr_rect(&mci_rect.rc));
704 return 0;
707 case MCIWNDM_PUT_SOURCE:
709 MCI_DGV_PUT_PARMS mci_put;
711 mci_put.rc = *(RECT *)lParam;
712 TRACE("MCIWNDM_PUT_SOURCE: %s\n", wine_dbgstr_rect(&mci_put.rc));
713 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_PUT,
714 MCI_DGV_PUT_SOURCE,
715 (DWORD_PTR)&mci_put);
716 if (mwi->lasterror)
718 MCIWND_notify_error(mwi);
719 return mwi->lasterror;
721 return 0;
724 case MCIWNDM_PUT_DEST:
726 MCI_DGV_PUT_PARMS mci_put;
728 mci_put.rc = *(RECT *)lParam;
729 TRACE("MCIWNDM_PUT_DEST: %s\n", wine_dbgstr_rect(&mci_put.rc));
731 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_PUT,
732 MCI_DGV_PUT_DESTINATION | MCI_DGV_RECT,
733 (DWORD_PTR)&mci_put);
734 if (mwi->lasterror)
736 MCIWND_notify_error(mwi);
737 return mwi->lasterror;
739 return 0;
742 case MCIWNDM_GETLENGTH:
744 MCI_STATUS_PARMS mci_status;
746 mci_status.dwItem = MCI_STATUS_LENGTH;
747 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_STATUS,
748 MCI_STATUS_ITEM,
749 (DWORD_PTR)&mci_status);
750 if (mwi->lasterror)
752 MCIWND_notify_error(mwi);
753 return 0;
755 TRACE("MCIWNDM_GETLENGTH: %ld\n", mci_status.dwReturn);
756 return mci_status.dwReturn;
759 case MCIWNDM_GETSTART:
761 MCI_STATUS_PARMS mci_status;
763 mci_status.dwItem = MCI_STATUS_POSITION;
764 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_STATUS,
765 MCI_STATUS_ITEM | MCI_STATUS_START,
766 (DWORD_PTR)&mci_status);
767 if (mwi->lasterror)
769 MCIWND_notify_error(mwi);
770 return 0;
772 TRACE("MCIWNDM_GETSTART: %ld\n", mci_status.dwReturn);
773 return mci_status.dwReturn;
776 case MCIWNDM_GETEND:
778 LRESULT start, length;
780 start = SendMessageW(hWnd, MCIWNDM_GETSTART, 0, 0);
781 length = SendMessageW(hWnd, MCIWNDM_GETLENGTH, 0, 0);
782 TRACE("MCIWNDM_GETEND: %ld\n", start + length);
783 return (start + length);
786 case MCIWNDM_GETPOSITIONA:
787 case MCIWNDM_GETPOSITIONW:
789 MCI_STATUS_PARMS mci_status;
791 TRACE("MCIWNDM_GETPOSITION\n");
793 /* get position string if requested */
794 if (wParam && lParam)
796 if (wMsg == MCIWNDM_GETPOSITIONA)
798 char cmd[64];
800 wsprintfA(cmd, "status %d position", mwi->alias);
801 mwi->lasterror = mciSendStringA(cmd, (LPSTR)lParam, wParam, 0);
803 else
806 WCHAR cmdW[64];
807 static const WCHAR formatW[] = {'s','t','a','t','u','s',' ','%','d',' ','p','o','s','i','t','i','o','n',0};
809 wsprintfW(cmdW, formatW, mwi->alias);
810 mwi->lasterror = mciSendStringW(cmdW, (LPWSTR)lParam, wParam, 0);
813 if (mwi->lasterror)
814 return 0;
817 mci_status.dwItem = MCI_STATUS_POSITION;
818 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_STATUS,
819 MCI_STATUS_ITEM,
820 (DWORD_PTR)&mci_status);
821 if (mwi->lasterror)
822 return 0;
824 return mci_status.dwReturn;
827 case MCIWNDM_GETMODEA:
828 case MCIWNDM_GETMODEW:
830 MCI_STATUS_PARMS mci_status;
832 TRACE("MCIWNDM_GETMODE\n");
834 if (!mwi->mci)
835 return MCI_MODE_NOT_READY;
837 /* get mode string if requested */
838 if (wParam && lParam)
840 if (wMsg == MCIWNDM_GETMODEA)
842 char cmd[64];
844 wsprintfA(cmd, "status %d mode", mwi->alias);
845 mwi->lasterror = mciSendStringA(cmd, (LPSTR)lParam, wParam, 0);
847 else
850 WCHAR cmdW[64];
851 static const WCHAR formatW[] = {'s','t','a','t','u','s',' ','%','d',' ','m','o','d','e',0};
853 wsprintfW(cmdW, formatW, mwi->alias);
854 mwi->lasterror = mciSendStringW(cmdW, (LPWSTR)lParam, wParam, 0);
857 if (mwi->lasterror)
858 return MCI_MODE_NOT_READY;
861 mci_status.dwItem = MCI_STATUS_MODE;
862 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_STATUS,
863 MCI_STATUS_ITEM,
864 (DWORD_PTR)&mci_status);
865 if (mwi->lasterror)
866 return MCI_MODE_NOT_READY;
868 return mci_status.dwReturn;
871 case MCIWNDM_PLAYFROM:
873 MCI_PLAY_PARMS mci_play;
875 TRACE("MCIWNDM_PLAYFROM %08lx\n", lParam);
877 mci_play.dwCallback = (DWORD_PTR)hWnd;
878 mci_play.dwFrom = lParam;
879 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_PLAY,
880 MCI_FROM | MCI_NOTIFY,
881 (DWORD_PTR)&mci_play);
882 if (mwi->lasterror)
884 MCIWND_notify_error(mwi);
885 return mwi->lasterror;
888 MCIWND_notify_mode(mwi);
889 MCIWND_UpdateState(mwi);
890 return 0;
893 case MCIWNDM_PLAYTO:
895 MCI_PLAY_PARMS mci_play;
897 TRACE("MCIWNDM_PLAYTO %08lx\n", lParam);
899 mci_play.dwCallback = (DWORD_PTR)hWnd;
900 mci_play.dwTo = lParam;
901 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_PLAY,
902 MCI_TO | MCI_NOTIFY,
903 (DWORD_PTR)&mci_play);
904 if (mwi->lasterror)
906 MCIWND_notify_error(mwi);
907 return mwi->lasterror;
910 MCIWND_notify_mode(mwi);
911 MCIWND_UpdateState(mwi);
912 return 0;
915 case MCIWNDM_PLAYREVERSE:
917 MCI_PLAY_PARMS mci_play;
918 DWORD flags = MCI_NOTIFY;
920 TRACE("MCIWNDM_PLAYREVERSE %08lx\n", lParam);
922 mci_play.dwCallback = (DWORD_PTR)hWnd;
923 mci_play.dwFrom = lParam;
924 switch (mwi->dev_type)
926 default:
927 case MCI_DEVTYPE_ANIMATION:
928 flags |= MCI_ANIM_PLAY_REVERSE;
929 break;
931 case MCI_DEVTYPE_DIGITAL_VIDEO:
932 flags |= MCI_DGV_PLAY_REVERSE;
933 break;
935 #ifdef MCI_VCR_PLAY_REVERSE
936 case MCI_DEVTYPE_VCR:
937 flags |= MCI_VCR_PLAY_REVERSE;
938 break;
939 #endif
941 case MCI_DEVTYPE_VIDEODISC:
942 flags |= MCI_VD_PLAY_REVERSE;
943 break;
946 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_PLAY,
947 flags, (DWORD_PTR)&mci_play);
948 if (mwi->lasterror)
950 MCIWND_notify_error(mwi);
951 return mwi->lasterror;
954 MCIWND_notify_mode(mwi);
955 MCIWND_UpdateState(mwi);
956 return 0;
959 case MCIWNDM_GETERRORA:
960 mciGetErrorStringA(mwi->lasterror, (LPSTR)lParam, wParam);
961 TRACE("MCIWNDM_GETERRORA: %s\n", debugstr_an((LPSTR)lParam, wParam));
962 return mwi->lasterror;
964 case MCIWNDM_GETERRORW:
965 mciGetErrorStringW(mwi->lasterror, (LPWSTR)lParam, wParam);
966 TRACE("MCIWNDM_GETERRORW: %s\n", debugstr_wn((LPWSTR)lParam, wParam));
967 return mwi->lasterror;
969 case MCIWNDM_SETOWNER:
970 TRACE("MCIWNDM_SETOWNER %p\n", (HWND)wParam);
971 mwi->hwndOwner = (HWND)wParam;
972 return 0;
974 case MCIWNDM_SENDSTRINGA:
976 UNICODE_STRING stringW;
978 TRACE("MCIWNDM_SENDSTRINGA %s\n", debugstr_a((LPCSTR)lParam));
980 RtlCreateUnicodeStringFromAsciiz(&stringW, (LPCSTR)lParam);
981 lParam = (LPARAM)stringW.Buffer;
983 /* fall through */
984 case MCIWNDM_SENDSTRINGW:
986 WCHAR *cmdW, *p;
988 TRACE("MCIWNDM_SENDSTRINGW %s\n", debugstr_w((LPCWSTR)lParam));
990 p = strchrW((LPCWSTR)lParam, ' ');
991 if (p)
993 static const WCHAR formatW[] = {'%','d',' ',0};
994 int len, pos;
996 pos = p - (WCHAR *)lParam + 1;
997 len = lstrlenW((LPCWSTR)lParam) + 64;
999 cmdW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1001 memcpy(cmdW, (void *)lParam, pos * sizeof(WCHAR));
1002 wsprintfW(cmdW + pos, formatW, mwi->alias);
1003 strcatW(cmdW, (WCHAR *)lParam + pos);
1005 else
1006 cmdW = (LPWSTR)lParam;
1008 mwi->lasterror = mciSendStringW(cmdW, mwi->return_string,
1009 sizeof(mwi->return_string)/sizeof(mwi->return_string[0]),
1011 if (mwi->lasterror)
1012 MCIWND_notify_error(mwi);
1014 if (cmdW != (LPWSTR)lParam)
1015 HeapFree(GetProcessHeap(), 0, cmdW);
1017 if (wMsg == MCIWNDM_SENDSTRINGA)
1018 HeapFree(GetProcessHeap(), 0, (void *)lParam);
1020 MCIWND_UpdateState(mwi);
1021 return mwi->lasterror;
1024 case MCIWNDM_RETURNSTRINGA:
1025 WideCharToMultiByte(CP_ACP, 0, mwi->return_string, -1, (LPSTR)lParam, wParam, NULL, NULL);
1026 TRACE("MCIWNDM_RETURNTRINGA %s\n", debugstr_an((LPSTR)lParam, wParam));
1027 return mwi->lasterror;
1029 case MCIWNDM_RETURNSTRINGW:
1030 lstrcpynW((LPWSTR)lParam, mwi->return_string, wParam);
1031 TRACE("MCIWNDM_RETURNTRINGW %s\n", debugstr_wn((LPWSTR)lParam, wParam));
1032 return mwi->lasterror;
1034 case MCIWNDM_SETTIMERS:
1035 TRACE("MCIWNDM_SETTIMERS active %d ms, inactive %d ms\n", (int)wParam, (int)lParam);
1036 mwi->active_timer = (WORD)wParam;
1037 mwi->inactive_timer = (WORD)lParam;
1038 return 0;
1040 case MCIWNDM_SETACTIVETIMER:
1041 TRACE("MCIWNDM_SETACTIVETIMER %d ms\n", (int)wParam);
1042 mwi->active_timer = (WORD)wParam;
1043 return 0;
1045 case MCIWNDM_SETINACTIVETIMER:
1046 TRACE("MCIWNDM_SETINACTIVETIMER %d ms\n", (int)wParam);
1047 mwi->inactive_timer = (WORD)wParam;
1048 return 0;
1050 case MCIWNDM_GETACTIVETIMER:
1051 TRACE("MCIWNDM_GETACTIVETIMER: %d ms\n", mwi->active_timer);
1052 return mwi->active_timer;
1054 case MCIWNDM_GETINACTIVETIMER:
1055 TRACE("MCIWNDM_GETINACTIVETIMER: %d ms\n", mwi->inactive_timer);
1056 return mwi->inactive_timer;
1058 case MCIWNDM_CHANGESTYLES:
1059 TRACE("MCIWNDM_CHANGESTYLES mask %08lx, set %08lx\n", wParam, lParam);
1060 /* FIXME: update the visual window state as well:
1061 * add/remove trackbar, autosize, etc.
1063 mwi->dwStyle &= ~wParam;
1064 mwi->dwStyle |= lParam & wParam;
1065 return 0;
1067 case MCIWNDM_GETSTYLES:
1068 TRACE("MCIWNDM_GETSTYLES: %08x\n", mwi->dwStyle & 0xffff);
1069 return mwi->dwStyle & 0xffff;
1071 case MCIWNDM_GETDEVICEA:
1073 MCI_SYSINFO_PARMSA mci_sysinfo;
1075 mci_sysinfo.lpstrReturn = (LPSTR)lParam;
1076 mci_sysinfo.dwRetSize = wParam;
1077 mwi->lasterror = mciSendCommandA(mwi->mci, MCI_SYSINFO,
1078 MCI_SYSINFO_INSTALLNAME,
1079 (DWORD_PTR)&mci_sysinfo);
1080 TRACE("MCIWNDM_GETDEVICEA: %s\n", debugstr_an((LPSTR)lParam, wParam));
1081 return 0;
1084 case MCIWNDM_GETDEVICEW:
1086 MCI_SYSINFO_PARMSW mci_sysinfo;
1088 mci_sysinfo.lpstrReturn = (LPWSTR)lParam;
1089 mci_sysinfo.dwRetSize = wParam;
1090 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_SYSINFO,
1091 MCI_SYSINFO_INSTALLNAME,
1092 (DWORD_PTR)&mci_sysinfo);
1093 TRACE("MCIWNDM_GETDEVICEW: %s\n", debugstr_wn((LPWSTR)lParam, wParam));
1094 return 0;
1097 case MCIWNDM_VALIDATEMEDIA:
1098 TRACE("MCIWNDM_VALIDATEMEDIA\n");
1099 if (mwi->mci)
1101 SendMessageW(hWnd, MCIWNDM_GETSTART, 0, 0);
1102 SendMessageW(hWnd, MCIWNDM_GETLENGTH, 0, 0);
1104 return 0;
1106 case MCIWNDM_GETFILENAMEA:
1107 TRACE("MCIWNDM_GETFILENAMEA: %s\n", debugstr_w(mwi->lpName));
1108 if (mwi->lpName)
1109 WideCharToMultiByte(CP_ACP, 0, mwi->lpName, -1, (LPSTR)lParam, wParam, NULL, NULL);
1110 return 0;
1112 case MCIWNDM_GETFILENAMEW:
1113 TRACE("MCIWNDM_GETFILENAMEW: %s\n", debugstr_w(mwi->lpName));
1114 if (mwi->lpName)
1115 lstrcpynW((LPWSTR)lParam, mwi->lpName, wParam);
1116 return 0;
1118 case MCIWNDM_GETTIMEFORMATA:
1119 case MCIWNDM_GETTIMEFORMATW:
1121 MCI_STATUS_PARMS mci_status;
1123 TRACE("MCIWNDM_GETTIMEFORMAT %08lx %08lx\n", wParam, lParam);
1125 /* get format string if requested */
1126 if (wParam && lParam)
1128 if (wMsg == MCIWNDM_GETTIMEFORMATA)
1130 char cmd[64];
1132 wsprintfA(cmd, "status %d time format", mwi->alias);
1133 mwi->lasterror = mciSendStringA(cmd, (LPSTR)lParam, wParam, 0);
1134 if (mwi->lasterror)
1135 return 0;
1137 else
1139 WCHAR cmdW[64];
1140 static const WCHAR formatW[] = {'s','t','a','t','u','s',' ','%','d',' ','t','i','m','e',' ','f','o','r','m','a','t',0};
1142 wsprintfW(cmdW, formatW, mwi->alias);
1143 mwi->lasterror = mciSendStringW(cmdW, (LPWSTR)lParam, wParam, 0);
1144 if (mwi->lasterror)
1145 return 0;
1149 mci_status.dwItem = MCI_STATUS_TIME_FORMAT ;
1150 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_STATUS,
1151 MCI_STATUS_ITEM,
1152 (DWORD_PTR)&mci_status);
1153 if (mwi->lasterror)
1154 return 0;
1156 return mci_status.dwReturn;
1159 case MCIWNDM_SETTIMEFORMATA:
1161 UNICODE_STRING stringW;
1163 TRACE("MCIWNDM_SETTIMEFORMATA %s\n", debugstr_a((LPSTR)lParam));
1165 RtlCreateUnicodeStringFromAsciiz(&stringW, (LPCSTR)lParam);
1166 lParam = (LPARAM)stringW.Buffer;
1168 /* fall through */
1169 case MCIWNDM_SETTIMEFORMATW:
1171 static const WCHAR formatW[] = {'s','e','t',' ','%','d',' ','t','i','m','e',' ','f','o','r','m','a','t',' ',0};
1172 WCHAR *cmdW;
1174 TRACE("MCIWNDM_SETTIMEFORMATW %s\n", debugstr_w((LPWSTR)lParam));
1176 if (mwi->mci)
1178 cmdW = HeapAlloc(GetProcessHeap(), 0, (lstrlenW((LPCWSTR)lParam) + 64) * sizeof(WCHAR));
1179 wsprintfW(cmdW, formatW, mwi->alias);
1180 strcatW(cmdW, (WCHAR *)lParam);
1182 mwi->lasterror = mciSendStringW(cmdW, NULL, 0, 0);
1184 /* fix the range tracking according to the new time format */
1185 if (!mwi->lasterror)
1186 SendDlgItemMessageW(hWnd, CTL_TRACKBAR, TBM_SETRANGEMAX, 1,
1187 SendMessageW(hWnd, MCIWNDM_GETLENGTH, 0, 0));
1189 HeapFree(GetProcessHeap(), 0, cmdW);
1192 if (wMsg == MCIWNDM_SETTIMEFORMATA)
1193 HeapFree(GetProcessHeap(), 0, (void *)lParam);
1195 return 0;
1198 case MCIWNDM_CAN_PLAY:
1199 TRACE("MCIWNDM_CAN_PLAY\n");
1200 if (mwi->mci)
1201 return mci_get_devcaps(mwi, MCI_GETDEVCAPS_CAN_PLAY);
1202 return 0;
1204 case MCIWNDM_CAN_RECORD:
1205 TRACE("MCIWNDM_CAN_RECORD\n");
1206 if (mwi->mci)
1207 return mci_get_devcaps(mwi, MCI_GETDEVCAPS_CAN_RECORD);
1208 return 0;
1210 case MCIWNDM_CAN_SAVE:
1211 TRACE("MCIWNDM_CAN_SAVE\n");
1212 if (mwi->mci)
1213 return mci_get_devcaps(mwi, MCI_GETDEVCAPS_CAN_SAVE);
1214 return 0;
1216 case MCIWNDM_CAN_EJECT:
1217 TRACE("MCIWNDM_CAN_EJECT\n");
1218 if (mwi->mci)
1219 return mci_get_devcaps(mwi, MCI_GETDEVCAPS_CAN_EJECT);
1220 return 0;
1222 case MCIWNDM_CAN_WINDOW:
1223 TRACE("MCIWNDM_CAN_WINDOW\n");
1224 switch (mwi->dev_type)
1226 case MCI_DEVTYPE_ANIMATION:
1227 case MCI_DEVTYPE_DIGITAL_VIDEO:
1228 case MCI_DEVTYPE_OVERLAY:
1229 return 1;
1231 return 0;
1233 case MCIWNDM_CAN_CONFIG:
1234 TRACE("MCIWNDM_CAN_CONFIG\n");
1235 if (mwi->hdrv)
1236 return SendDriverMessage(mwi->hdrv, DRV_QUERYCONFIGURE, 0, 0);
1237 return 0;
1239 case MCIWNDM_SETZOOM:
1240 TRACE("MCIWNDM_SETZOOM %ld\n", lParam);
1241 mwi->zoom = lParam;
1243 if (mwi->mci && !(mwi->dwStyle & MCIWNDF_NOAUTOSIZEWINDOW))
1245 RECT rc;
1247 rc.left = rc.top = 0;
1248 rc.right = MulDiv(mwi->size.cx, mwi->zoom, 100);
1249 rc.bottom = MulDiv(mwi->size.cy, mwi->zoom, 100);
1251 if (!(mwi->dwStyle & MCIWNDF_NOPLAYBAR))
1252 rc.bottom += 32; /* add the height of the playbar */
1253 AdjustWindowRect(&rc, GetWindowLongW(hWnd, GWL_STYLE), FALSE);
1254 SetWindowPos(hWnd, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
1255 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
1257 return 0;
1259 case MCIWNDM_GETZOOM:
1260 TRACE("MCIWNDM_GETZOOM: %d\n", mwi->zoom);
1261 return mwi->zoom;
1263 case MCIWNDM_EJECT:
1265 MCI_SET_PARMS mci_set;
1267 TRACE("MCIWNDM_EJECT\n");
1269 mci_set.dwCallback = (DWORD_PTR)hWnd;
1270 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_SET,
1271 MCI_SET_DOOR_OPEN | MCI_NOTIFY,
1272 (DWORD_PTR)&mci_set);
1273 MCIWND_notify_mode(mwi);
1274 MCIWND_UpdateState(mwi);
1275 return mwi->lasterror;
1278 case MCIWNDM_SETVOLUME:
1279 case MCIWNDM_GETVOLUME:
1280 case MCIWNDM_SETSPEED:
1281 case MCIWNDM_GETSPEED:
1282 case MCIWNDM_SETREPEAT:
1283 case MCIWNDM_GETREPEAT:
1284 case MCIWNDM_REALIZE:
1285 case MCIWNDM_GETPALETTE:
1286 case MCIWNDM_SETPALETTE:
1287 case MCIWNDM_NEWA:
1288 case MCIWNDM_NEWW:
1289 case MCIWNDM_PALETTEKICK:
1290 case MCIWNDM_OPENINTERFACE:
1291 FIXME("support for MCIWNDM_ message WM_USER+%d not implemented\n", wMsg - WM_USER);
1292 return 0;
1294 case MCI_PLAY:
1296 LRESULT end = SendMessageW(hWnd, MCIWNDM_GETEND, 0, 0);
1297 return SendMessageW(hWnd, MCIWNDM_PLAYTO, 0, end);
1300 case MCI_SEEK:
1302 MCI_SEEK_PARMS mci_seek;
1304 switch (lParam)
1306 case MCIWND_START:
1307 lParam = SendMessageW(hWnd, MCIWNDM_GETSTART, 0, 0);
1308 break;
1310 case MCIWND_END:
1311 lParam = SendMessageW(hWnd, MCIWNDM_GETEND, 0, 0);
1312 break;
1315 mci_seek.dwTo = lParam;
1316 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_SEEK,
1317 MCI_TO, (DWORD_PTR)&mci_seek);
1318 if (mwi->lasterror)
1320 MCIWND_notify_error(mwi);
1321 return mwi->lasterror;
1323 /* update window to reflect the state */
1324 InvalidateRect(hWnd, NULL, TRUE);
1325 return 0;
1328 case MCI_CLOSE:
1330 RECT rc;
1331 MCI_GENERIC_PARMS mci_generic;
1333 if (mwi->hdrv)
1335 CloseDriver(mwi->hdrv, 0, 0);
1336 mwi->hdrv = 0;
1339 if (mwi->mci)
1341 mci_generic.dwCallback = 0;
1342 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_CLOSE,
1343 0, (DWORD_PTR)&mci_generic);
1344 mwi->mci = 0;
1347 mwi->mode = MCI_MODE_NOT_READY;
1348 mwi->position = -1;
1350 HeapFree(GetProcessHeap(), 0, mwi->lpName);
1351 mwi->lpName = NULL;
1352 MCIWND_UpdateState(mwi);
1354 GetClientRect(hWnd, &rc);
1355 rc.bottom = rc.top;
1356 if (!(mwi->dwStyle & MCIWNDF_NOPLAYBAR))
1357 rc.bottom += 32; /* add the height of the playbar */
1358 AdjustWindowRect(&rc, GetWindowLongW(hWnd, GWL_STYLE), FALSE);
1359 SetWindowPos(hWnd, 0, 0, 0, rc.right - rc.left,
1360 rc.bottom - rc.top, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
1362 MCIWND_notify_media(mwi);
1363 return 0;
1366 case MCI_PAUSE:
1367 case MCI_STEP:
1368 case MCI_STOP:
1369 case MCI_RESUME:
1370 mci_generic_command(mwi, wMsg);
1371 if (wMsg == MCI_STEP && !mwi->lasterror)
1373 /* update window to reflect the state */
1374 InvalidateRect(hWnd, NULL, TRUE);
1376 return mwi->lasterror;
1378 case MCI_CONFIGURE:
1379 if (mwi->hdrv)
1380 SendDriverMessage(mwi->hdrv, DRV_CONFIGURE, (LPARAM)hWnd, 0);
1381 return 0;
1383 case MCI_BREAK:
1384 case MCI_CAPTURE:
1385 case MCI_COPY:
1386 case MCI_CUE:
1387 case MCI_CUT:
1388 case MCI_DELETE:
1389 case MCI_ESCAPE:
1390 case MCI_FREEZE:
1391 case MCI_GETDEVCAPS:
1392 /*case MCI_INDEX:*/
1393 case MCI_INFO:
1394 case MCI_LIST:
1395 case MCI_LOAD:
1396 /*case MCI_MARK:*/
1397 case MCI_MONITOR:
1398 case MCI_OPEN:
1399 case MCI_PASTE:
1400 case MCI_PUT:
1401 case MCI_QUALITY:
1402 case MCI_REALIZE:
1403 case MCI_RECORD:
1404 case MCI_RESERVE:
1405 case MCI_RESTORE:
1406 case MCI_SAVE:
1407 case MCI_SET:
1408 case MCI_SETAUDIO:
1409 /*case MCI_SETTIMECODE:*/
1410 /*case MCI_SETTUNER:*/
1411 case MCI_SETVIDEO:
1412 case MCI_SIGNAL:
1413 case MCI_SPIN:
1414 case MCI_STATUS:
1415 case MCI_SYSINFO:
1416 case MCI_UNDO:
1417 case MCI_UNFREEZE:
1418 case MCI_UPDATE:
1419 case MCI_WHERE:
1420 case MCI_WINDOW:
1421 FIXME("support for MCI_ command %04x not implemented\n", wMsg);
1422 return 0;
1425 if (wMsg >= WM_USER)
1427 FIXME("support for MCIWNDM_ message WM_USER+%d not implemented\n", wMsg - WM_USER);
1428 return 0;
1431 if (GetWindowLongW(hWnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1432 return DefMDIChildProcW(hWnd, wMsg, wParam, lParam);
1434 return DefWindowProcW(hWnd, wMsg, wParam, lParam);