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
20 * Add support for all remaining MCI_ commands and MCIWNDM_ messages.
21 * Add support for MCIWNDF_RECORD.
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mci);
41 extern HMODULE MSVFW32_hModule;
42 static const WCHAR mciWndClassW[] = {'M','C','I','W','n','d','C','l','a','s','s',0};
53 SIZE size; /* size of the original frame rect */
59 WCHAR return_string[128];
60 WORD active_timer, inactive_timer;
63 static LRESULT WINAPI MCIWndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
65 #define CTL_PLAYSTOP 0x3200
66 #define CTL_MENU 0x3201
67 #define CTL_TRACKBAR 0x3202
69 /***********************************************************************
70 * MCIWndRegisterClass [MSVFW32.@]
72 * NOTE: Native always uses its own hInstance
74 BOOL VFWAPIV MCIWndRegisterClass(void)
78 /* Since we are going to register a class belonging to MSVFW32
79 * and later we will create windows with a different hInstance
80 * CS_GLOBALCLASS is needed. And because the second attempt
81 * to register a global class will fail we need to test whether
82 * the class was already registered.
84 wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS | CS_OWNDC | CS_GLOBALCLASS;
85 wc.lpfnWndProc = MCIWndProc;
87 wc.cbWndExtra = sizeof(MCIWndInfo*);
88 wc.hInstance = MSVFW32_hModule;
90 wc.hCursor = LoadCursorW(0, MAKEINTRESOURCEW(IDC_ARROW));
91 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
92 wc.lpszMenuName = NULL;
93 wc.lpszClassName = mciWndClassW;
95 if (RegisterClassW(&wc)) return TRUE;
96 if (GetLastError() == ERROR_CLASS_ALREADY_EXISTS) return TRUE;
101 /***********************************************************************
102 * MCIWndCreateW [MSVFW32.@]
104 HWND VFWAPIV MCIWndCreateW(HWND hwndParent, HINSTANCE hInstance,
105 DWORD dwStyle, LPCWSTR szFile)
107 TRACE("%p %p %x %s\n", hwndParent, hInstance, dwStyle, debugstr_w(szFile));
109 MCIWndRegisterClass();
111 if (!hInstance) hInstance = GetModuleHandleW(0);
114 dwStyle |= WS_VISIBLE | WS_BORDER /*| WS_CHILD*/;
116 dwStyle |= WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
118 return CreateWindowExW(0, mciWndClassW, NULL,
119 dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
121 hwndParent, 0, hInstance, (LPVOID)szFile);
124 /***********************************************************************
125 * MCIWndCreate [MSVFW32.@]
126 * MCIWndCreateA [MSVFW32.@]
128 HWND VFWAPIV MCIWndCreateA(HWND hwndParent, HINSTANCE hInstance,
129 DWORD dwStyle, LPCSTR szFile)
132 UNICODE_STRING fileW;
135 RtlCreateUnicodeStringFromAsciiz(&fileW, szFile);
139 ret = MCIWndCreateW(hwndParent, hInstance, dwStyle, fileW.Buffer);
141 RtlFreeUnicodeString(&fileW);
145 static inline void MCIWND_notify_mode(MCIWndInfo *mwi)
147 if (mwi->dwStyle & MCIWNDF_NOTIFYMODE)
149 UINT new_mode = SendMessageW(mwi->hWnd, MCIWNDM_GETMODEW, 0, 0);
150 if (new_mode != mwi->mode)
152 mwi->mode = new_mode;
153 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYMODE, (WPARAM)mwi->hWnd, new_mode);
158 static inline void MCIWND_notify_pos(MCIWndInfo *mwi)
160 if (mwi->dwStyle & MCIWNDF_NOTIFYPOS)
162 long new_pos = SendMessageW(mwi->hWnd, MCIWNDM_GETPOSITIONW, 0, 0);
163 if (new_pos != mwi->position)
165 mwi->position = new_pos;
166 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYPOS, (WPARAM)mwi->hWnd, new_pos);
171 static inline void MCIWND_notify_size(MCIWndInfo *mwi)
173 if (mwi->dwStyle & MCIWNDF_NOTIFYSIZE)
174 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYSIZE, (WPARAM)mwi->hWnd, 0);
177 static inline void MCIWND_notify_error(MCIWndInfo *mwi)
179 if (mwi->dwStyle & MCIWNDF_NOTIFYERROR)
180 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYERROR, (WPARAM)mwi->hWnd, (LPARAM)mwi->lasterror);
183 static void MCIWND_UpdateState(MCIWndInfo *mwi)
189 /* FIXME: get this from resources */
190 static const WCHAR no_deviceW[] = {'N','o',' ','D','e','v','i','c','e',0};
191 SetWindowTextW(mwi->hWnd, no_deviceW);
195 MCIWND_notify_pos(mwi);
197 if (!(mwi->dwStyle & MCIWNDF_NOPLAYBAR))
198 SendDlgItemMessageW(mwi->hWnd, CTL_TRACKBAR, TBM_SETPOS, TRUE, mwi->position);
200 if (!(mwi->dwStyle & MCIWNDF_SHOWALL))
203 if ((mwi->dwStyle & MCIWNDF_SHOWNAME) && mwi->lpName)
204 strcpyW(buffer, mwi->lpName);
208 if (mwi->dwStyle & (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE))
210 static const WCHAR spaceW[] = {' ',0};
211 static const WCHAR l_braceW[] = {'(',0};
213 if (*buffer) strcatW(buffer, spaceW);
214 strcatW(buffer, l_braceW);
217 if (mwi->dwStyle & MCIWNDF_SHOWPOS)
222 SendMessageW(mwi->hWnd, MCIWNDM_GETPOSITIONW, 64, (LPARAM)posW);
223 strcatW(buffer, posW);
226 if ((mwi->dwStyle & (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE)) == (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE))
228 static const WCHAR dashW[] = {' ','-',' ',0};
229 strcatW(buffer, dashW);
232 if (mwi->dwStyle & MCIWNDF_SHOWMODE)
237 SendMessageW(mwi->hWnd, MCIWNDM_GETMODEW, 64, (LPARAM)modeW);
238 strcatW(buffer, modeW);
241 if (mwi->dwStyle & (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE))
243 static const WCHAR r_braceW[] = {')',0};
244 strcatW(buffer, r_braceW);
247 TRACE("=> '%s'\n", debugstr_w(buffer));
248 SetWindowTextW(mwi->hWnd, buffer);
251 static LRESULT MCIWND_Create(HWND hWnd, LPCREATESTRUCTW cs)
255 static const WCHAR buttonW[] = {'b','u','t','t','o','n',0};
257 mwi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*mwi));
260 SetWindowLongW(hWnd, 0, (LPARAM)mwi);
262 mwi->dwStyle = cs->style;
263 /* There is no need to show stats if there is no caption */
264 if ((mwi->dwStyle & WS_CAPTION) != WS_CAPTION)
265 mwi->dwStyle &= ~MCIWNDF_SHOWALL;
268 mwi->hwndOwner = cs->hwndParent;
269 mwi->active_timer = 500;
270 mwi->inactive_timer = 2000;
271 mwi->mode = MCI_MODE_NOT_READY;
275 if (!(mwi->dwStyle & MCIWNDF_NOMENU))
277 static const WCHAR menuW[] = {'M','e','n','u',0};
279 hChld = CreateWindowExW(0, buttonW, menuW, WS_CHILD|WS_VISIBLE, 32, cs->cy, 32, 32,
280 hWnd, (HMENU)CTL_MENU, cs->hInstance, 0L);
281 TRACE("Get Button2: %p\n", hChld);
284 if (!(mwi->dwStyle & MCIWNDF_NOPLAYBAR))
286 INITCOMMONCONTROLSEX init;
287 static const WCHAR playW[] = {'P','l','a','y',0};
289 /* adding the other elements: play/stop button, menu button, status */
290 hChld = CreateWindowExW(0, buttonW, playW, WS_CHILD|WS_VISIBLE, 0, cs->cy, 32, 32,
291 hWnd, (HMENU)CTL_PLAYSTOP, cs->hInstance, 0L);
292 TRACE("Get Button1: %p\n", hChld);
294 init.dwSize = sizeof(init);
295 init.dwICC = ICC_BAR_CLASSES;
296 InitCommonControlsEx(&init);
298 hChld = CreateWindowExW(0, TRACKBAR_CLASSW, NULL, WS_CHILD|WS_VISIBLE, 64, cs->cy, cs->cx - 64, 32,
299 hWnd, (HMENU)CTL_TRACKBAR, cs->hInstance, 0L);
300 TRACE("Get status: %p\n", hChld);
303 /* This sets the default window size */
304 SendMessageW(hWnd, MCI_CLOSE, 0, 0);
306 if (cs->lpCreateParams)
310 /* MCI wnd class is prepared to be embedded as an MDI child window */
311 if (cs->dwExStyle & WS_EX_MDICHILD)
313 MDICREATESTRUCTW *mdics = (MDICREATESTRUCTW *)cs->lpCreateParams;
314 lParam = mdics->lParam;
317 lParam = (LPARAM)cs->lpCreateParams;
319 /* If it's our internal class pointer, file name is a unicode string */
320 if (cs->lpszClass == mciWndClassW)
321 SendMessageW(hWnd, MCIWNDM_OPENW, 0, lParam);
324 /* Otherwise let's try to figure out what string format is used */
325 HWND parent = cs->hwndParent;
326 if (!parent) parent = GetWindow(hWnd, GW_OWNER);
328 SendMessageW(hWnd, IsWindowUnicode(parent) ? MCIWNDM_OPENW : MCIWNDM_OPENA, 0, lParam);
335 static void MCIWND_ToggleState(MCIWndInfo *mwi)
337 switch (SendMessageW(mwi->hWnd, MCIWNDM_GETMODEW, 0, 0))
339 case MCI_MODE_NOT_READY:
340 case MCI_MODE_RECORD:
343 TRACE("Cannot do much...\n");
347 SendMessageW(mwi->hWnd, MCI_RESUME, 0, 0);
351 SendMessageW(mwi->hWnd, MCI_PAUSE, 0, 0);
355 SendMessageW(mwi->hWnd, MCI_STOP, 0, 0);
360 static LRESULT MCIWND_Command(MCIWndInfo *mwi, WPARAM wParam, LPARAM lParam)
362 switch (LOWORD(wParam))
364 case CTL_PLAYSTOP: MCIWND_ToggleState(mwi); break;
368 FIXME("support for command %04x not implement yet\n", LOWORD(wParam));
373 static void MCIWND_notify_media(MCIWndInfo *mwi)
375 if (mwi->dwStyle & (MCIWNDF_NOTIFYMEDIAA | MCIWNDF_NOTIFYMEDIAW))
379 static const WCHAR empty_str[1];
380 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYMEDIA, (WPARAM)mwi->hWnd, (LPARAM)empty_str);
384 if (mwi->dwStyle & MCIWNDF_NOTIFYANSI)
389 len = WideCharToMultiByte(CP_ACP, 0, mwi->lpName, -1, NULL, 0, NULL, NULL);
390 ansi_name = HeapAlloc(GetProcessHeap(), 0, len);
391 WideCharToMultiByte(CP_ACP, 0, mwi->lpName, -1, ansi_name, len, NULL, NULL);
393 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYMEDIA, (WPARAM)mwi->hWnd, (LPARAM)ansi_name);
395 HeapFree(GetProcessHeap(), 0, ansi_name);
398 SendMessageW(mwi->hwndOwner, MCIWNDM_NOTIFYMEDIA, (WPARAM)mwi->hWnd, (LPARAM)mwi->lpName);
403 static MCIERROR mci_generic_command(MCIWndInfo *mwi, UINT cmd)
405 MCI_GENERIC_PARMS mci_generic;
407 mci_generic.dwCallback = 0;
408 mwi->lasterror = mciSendCommandW(mwi->mci, cmd, 0, (DWORD_PTR)&mci_generic);
411 return mwi->lasterror;
413 MCIWND_notify_mode(mwi);
414 MCIWND_UpdateState(mwi);
418 static LRESULT mci_get_devcaps(MCIWndInfo *mwi, UINT cap)
420 MCI_GETDEVCAPS_PARMS mci_devcaps;
422 mci_devcaps.dwItem = cap;
423 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_GETDEVCAPS,
425 (DWORD_PTR)&mci_devcaps);
429 return mci_devcaps.dwReturn;
432 static LRESULT MCIWND_KeyDown(MCIWndInfo *mwi, UINT key)
434 TRACE("%p, key %04x\n", mwi->hWnd, key);
439 SendMessageW(mwi->hWnd, MCI_STOP, 0, 0);
447 static LRESULT WINAPI MCIWndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
451 TRACE("%p %04x %08x %08lx\n", hWnd, wMsg, wParam, lParam);
453 mwi = (MCIWndInfo*)GetWindowLongW(hWnd, 0);
454 if (!mwi && wMsg != WM_CREATE)
455 return DefWindowProcW(hWnd, wMsg, wParam, lParam);
460 MCIWND_Create(hWnd, (CREATESTRUCTW *)lParam);
465 KillTimer(hWnd, mwi->uTimer);
468 SendMessageW(hWnd, MCI_CLOSE, 0, 0);
470 HeapFree(GetProcessHeap(), 0, mwi);
472 DestroyWindow(GetDlgItem(hWnd, CTL_MENU));
473 DestroyWindow(GetDlgItem(hWnd, CTL_PLAYSTOP));
474 DestroyWindow(GetDlgItem(hWnd, CTL_TRACKBAR));
479 MCI_DGV_UPDATE_PARMS mci_update;
482 mci_update.hDC = (wParam) ? (HDC)wParam : BeginPaint(hWnd, &ps);
484 mciSendCommandW(mwi->mci, MCI_UPDATE,
485 MCI_DGV_UPDATE_HDC | MCI_DGV_UPDATE_PAINT,
486 (DWORD_PTR)&mci_update);
488 if (!wParam) EndPaint(hWnd, &ps);
493 return MCIWND_Command(mwi, wParam, lParam);
496 return MCIWND_KeyDown(mwi, wParam);
501 KillTimer(hWnd, mwi->uTimer);
502 mwi->uTimer = SetTimer(hWnd, 1, wParam ? mwi->active_timer : mwi->inactive_timer, NULL);
507 MCIWND_UpdateState(mwi);
511 SetWindowPos(GetDlgItem(hWnd, CTL_PLAYSTOP), 0, 0, HIWORD(lParam) - 32, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
512 SetWindowPos(GetDlgItem(hWnd, CTL_MENU), 0, 32, HIWORD(lParam) - 32, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
513 SetWindowPos(GetDlgItem(hWnd, CTL_TRACKBAR), 0, 64, HIWORD(lParam) - 32, LOWORD(lParam) - 64, 32, SWP_NOACTIVATE);
515 if (!(mwi->dwStyle & MCIWNDF_NOAUTOSIZEMOVIE))
519 rc.left = rc.top = 0;
520 rc.right = LOWORD(lParam);
521 rc.bottom = HIWORD(lParam);
522 if (!(mwi->dwStyle & MCIWNDF_NOPLAYBAR))
523 rc.bottom -= 32; /* subtract the height of the playbar */
524 SendMessageW(hWnd, MCIWNDM_PUT_DEST, 0, (LPARAM)&rc);
526 MCIWND_notify_size(mwi);
530 MCIWND_notify_mode(mwi);
531 MCIWND_UpdateState(mwi);
536 UNICODE_STRING nameW;
537 TRACE("MCIWNDM_OPENA %s\n", debugstr_a((LPSTR)lParam));
538 RtlCreateUnicodeStringFromAsciiz(&nameW, (LPCSTR)lParam);
539 lParam = (LPARAM)nameW.Buffer;
546 MCI_OPEN_PARMSW mci_open;
547 MCI_GETDEVCAPS_PARMS mci_devcaps;
549 WCHAR drv_name[MAX_PATH];
550 static const WCHAR formatW[] = {'%','d',0};
551 static const WCHAR mci32W[] = {'m','c','i','3','2',0};
552 static const WCHAR system_iniW[] = {'s','y','s','t','e','m','.','i','n','i',0};
554 TRACE("MCIWNDM_OPENW %s\n", debugstr_w((LPWSTR)lParam));
556 if (wParam == MCIWNDOPENF_NEW)
558 SendMessageW(hWnd, MCIWNDM_NEWW, 0, lParam);
559 goto end_of_mci_open;
564 KillTimer(hWnd, mwi->uTimer);
568 hCursor = LoadCursorW(0, (LPWSTR)IDC_WAIT);
569 hCursor = SetCursor(hCursor);
571 mci_open.lpstrElementName = (LPWSTR)lParam;
572 wsprintfW(aliasW, formatW, (int)hWnd + 1);
573 mci_open.lpstrAlias = aliasW;
574 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_OPEN,
575 MCI_OPEN_ELEMENT | MCI_OPEN_ALIAS | MCI_WAIT,
576 (DWORD_PTR)&mci_open);
579 if (mwi->lasterror && !(mwi->dwStyle & MCIWNDF_NOERRORDLG))
581 /* FIXME: get the caption from resources */
582 static const WCHAR caption[] = {'M','C','I',' ','E','r','r','o','r',0};
583 WCHAR error_str[MAXERRORLENGTH];
585 mciGetErrorStringW(mwi->lasterror, error_str, MAXERRORLENGTH);
586 MessageBoxW(hWnd, error_str, caption, MB_ICONEXCLAMATION | MB_OK);
587 MCIWND_notify_error(mwi);
588 goto end_of_mci_open;
591 mwi->mci = mci_open.wDeviceID;
592 mwi->alias = (int)hWnd + 1;
594 mwi->lpName = HeapAlloc(GetProcessHeap(), 0, (strlenW((LPWSTR)lParam) + 1) * sizeof(WCHAR));
595 strcpyW(mwi->lpName, (LPWSTR)lParam);
597 MCIWND_UpdateState(mwi);
599 mci_devcaps.dwItem = MCI_GETDEVCAPS_DEVICE_TYPE;
600 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_GETDEVCAPS,
602 (DWORD_PTR)&mci_devcaps);
605 MCIWND_notify_error(mwi);
606 goto end_of_mci_open;
609 mwi->dev_type = mci_devcaps.dwReturn;
612 SendMessageW(hWnd, MCIWNDM_GETDEVICEW, 256, (LPARAM)drv_name);
613 if (drv_name[0] && GetPrivateProfileStringW(mci32W, drv_name, NULL,
614 drv_name, MAX_PATH, system_iniW))
615 mwi->hdrv = OpenDriver(drv_name, NULL, 0);
617 if (mwi->dev_type == MCI_DEVTYPE_DIGITAL_VIDEO)
619 MCI_DGV_WINDOW_PARMSW mci_window;
621 mci_window.hWnd = hWnd;
622 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_WINDOW,
624 (DWORD_PTR)&mci_window);
627 MCIWND_notify_error(mwi);
628 goto end_of_mci_open;
632 if (SendMessageW(hWnd, MCIWNDM_GET_DEST, 0, (LPARAM)&rc) == 0)
634 mwi->size.cx = rc.right - rc.left;
635 mwi->size.cy = rc.bottom - rc.top;
637 rc.right = MulDiv(mwi->size.cx, mwi->zoom, 100);
638 rc.bottom = MulDiv(mwi->size.cy, mwi->zoom, 100);
639 SendMessageW(hWnd, MCIWNDM_PUT_DEST, 0, (LPARAM)&rc);
643 GetClientRect(hWnd, &rc);
647 if (!(mwi->dwStyle & MCIWNDF_NOPLAYBAR))
648 rc.bottom += 32; /* add the height of the playbar */
649 AdjustWindowRect(&rc, GetWindowLongW(hWnd, GWL_STYLE), FALSE);
650 SetWindowPos(hWnd, 0, 0, 0, rc.right - rc.left,
651 rc.bottom - rc.top, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
653 SendDlgItemMessageW(hWnd, CTL_TRACKBAR, TBM_SETRANGEMIN, 0L, 0L);
654 SendDlgItemMessageW(hWnd, CTL_TRACKBAR, TBM_SETRANGEMAX, 1,
655 SendMessageW(hWnd, MCIWNDM_GETLENGTH, 0, 0));
656 mwi->uTimer = SetTimer(hWnd, 1, mwi->active_timer, NULL);
658 MCIWND_notify_media(mwi);
661 if (wMsg == MCIWNDM_OPENA)
662 HeapFree(GetProcessHeap(), 0, (void *)lParam);
663 return mwi->lasterror;
666 case MCIWNDM_GETDEVICEID:
667 TRACE("MCIWNDM_GETDEVICEID\n");
670 case MCIWNDM_GETALIAS:
671 TRACE("MCIWNDM_GETALIAS\n");
674 case MCIWNDM_GET_SOURCE:
676 MCI_DGV_RECT_PARMS mci_rect;
678 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_WHERE,
679 MCI_DGV_WHERE_SOURCE,
680 (DWORD_PTR)&mci_rect);
683 MCIWND_notify_error(mwi);
684 return mwi->lasterror;
686 *(RECT *)lParam = mci_rect.rc;
687 TRACE("MCIWNDM_GET_SOURCE: %s\n", wine_dbgstr_rect(&mci_rect.rc));
691 case MCIWNDM_GET_DEST:
693 MCI_DGV_RECT_PARMS mci_rect;
695 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_WHERE,
696 MCI_DGV_WHERE_DESTINATION,
697 (DWORD_PTR)&mci_rect);
700 MCIWND_notify_error(mwi);
701 return mwi->lasterror;
703 *(RECT *)lParam = mci_rect.rc;
704 TRACE("MCIWNDM_GET_DEST: %s\n", wine_dbgstr_rect(&mci_rect.rc));
708 case MCIWNDM_PUT_SOURCE:
710 MCI_DGV_PUT_PARMS mci_put;
712 mci_put.rc = *(RECT *)lParam;
713 TRACE("MCIWNDM_PUT_SOURCE: %s\n", wine_dbgstr_rect(&mci_put.rc));
714 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_PUT,
716 (DWORD_PTR)&mci_put);
719 MCIWND_notify_error(mwi);
720 return mwi->lasterror;
725 case MCIWNDM_PUT_DEST:
727 MCI_DGV_PUT_PARMS mci_put;
729 mci_put.rc = *(RECT *)lParam;
730 TRACE("MCIWNDM_PUT_DEST: %s\n", wine_dbgstr_rect(&mci_put.rc));
732 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_PUT,
733 MCI_DGV_PUT_DESTINATION | MCI_DGV_RECT,
734 (DWORD_PTR)&mci_put);
737 MCIWND_notify_error(mwi);
738 return mwi->lasterror;
743 case MCIWNDM_GETLENGTH:
745 MCI_STATUS_PARMS mci_status;
747 mci_status.dwItem = MCI_STATUS_LENGTH;
748 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_STATUS,
750 (DWORD_PTR)&mci_status);
753 MCIWND_notify_error(mwi);
756 TRACE("MCIWNDM_GETLENGTH: %d\n", mci_status.dwReturn);
757 return mci_status.dwReturn;
760 case MCIWNDM_GETSTART:
762 MCI_STATUS_PARMS mci_status;
764 mci_status.dwItem = MCI_STATUS_POSITION;
765 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_STATUS,
766 MCI_STATUS_ITEM | MCI_STATUS_START,
767 (DWORD_PTR)&mci_status);
770 MCIWND_notify_error(mwi);
773 TRACE("MCIWNDM_GETSTART: %d\n", mci_status.dwReturn);
774 return mci_status.dwReturn;
779 LRESULT start, length;
781 start = SendMessageW(hWnd, MCIWNDM_GETSTART, 0, 0);
782 length = SendMessageW(hWnd, MCIWNDM_GETLENGTH, 0, 0);
783 TRACE("MCIWNDM_GETEND: %ld\n", start + length);
784 return (start + length);
787 case MCIWNDM_GETPOSITIONA:
788 case MCIWNDM_GETPOSITIONW:
790 MCI_STATUS_PARMS mci_status;
792 TRACE("MCIWNDM_GETPOSITION\n");
794 /* get position string if requested */
795 if (wParam && lParam)
797 if (wMsg == MCIWNDM_GETPOSITIONA)
801 wsprintfA(cmd, "status %d position", mwi->alias);
802 mwi->lasterror = mciSendStringA(cmd, (LPSTR)lParam, wParam, 0);
808 static const WCHAR formatW[] = {'s','t','a','t','u','s',' ','%','d',' ','p','o','s','i','t','i','o','n',0};
810 wsprintfW(cmdW, formatW, mwi->alias);
811 mwi->lasterror = mciSendStringW(cmdW, (LPWSTR)lParam, wParam, 0);
818 mci_status.dwItem = MCI_STATUS_POSITION;
819 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_STATUS,
821 (DWORD_PTR)&mci_status);
825 return mci_status.dwReturn;
828 case MCIWNDM_GETMODEA:
829 case MCIWNDM_GETMODEW:
831 MCI_STATUS_PARMS mci_status;
833 TRACE("MCIWNDM_GETMODE\n");
836 return MCI_MODE_NOT_READY;
838 /* get mode string if requested */
839 if (wParam && lParam)
841 if (wMsg == MCIWNDM_GETMODEA)
845 wsprintfA(cmd, "status %d mode", mwi->alias);
846 mwi->lasterror = mciSendStringA(cmd, (LPSTR)lParam, wParam, 0);
852 static const WCHAR formatW[] = {'s','t','a','t','u','s',' ','%','d',' ','m','o','d','e',0};
854 wsprintfW(cmdW, formatW, mwi->alias);
855 mwi->lasterror = mciSendStringW(cmdW, (LPWSTR)lParam, wParam, 0);
859 return MCI_MODE_NOT_READY;
862 mci_status.dwItem = MCI_STATUS_MODE;
863 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_STATUS,
865 (DWORD_PTR)&mci_status);
867 return MCI_MODE_NOT_READY;
869 return mci_status.dwReturn;
872 case MCIWNDM_PLAYFROM:
874 MCI_PLAY_PARMS mci_play;
876 TRACE("MCIWNDM_PLAYFROM %08lx\n", lParam);
878 mci_play.dwCallback = (DWORD_PTR)hWnd;
879 mci_play.dwFrom = lParam;
880 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_PLAY,
881 MCI_FROM | MCI_NOTIFY,
882 (DWORD_PTR)&mci_play);
885 MCIWND_notify_error(mwi);
886 return mwi->lasterror;
889 MCIWND_notify_mode(mwi);
890 MCIWND_UpdateState(mwi);
896 MCI_PLAY_PARMS mci_play;
898 TRACE("MCIWNDM_PLAYTO %08lx\n", lParam);
900 mci_play.dwCallback = (DWORD_PTR)hWnd;
901 mci_play.dwTo = lParam;
902 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_PLAY,
904 (DWORD_PTR)&mci_play);
907 MCIWND_notify_error(mwi);
908 return mwi->lasterror;
911 MCIWND_notify_mode(mwi);
912 MCIWND_UpdateState(mwi);
916 case MCIWNDM_PLAYREVERSE:
918 MCI_PLAY_PARMS mci_play;
919 DWORD flags = MCI_NOTIFY;
921 TRACE("MCIWNDM_PLAYREVERSE %08lx\n", lParam);
923 mci_play.dwCallback = (DWORD_PTR)hWnd;
924 mci_play.dwFrom = lParam;
925 switch (mwi->dev_type)
928 case MCI_DEVTYPE_ANIMATION:
929 flags |= MCI_ANIM_PLAY_REVERSE;
932 case MCI_DEVTYPE_DIGITAL_VIDEO:
933 flags |= MCI_DGV_PLAY_REVERSE;
936 #ifdef MCI_VCR_PLAY_REVERSE
937 case MCI_DEVTYPE_VCR:
938 flags |= MCI_VCR_PLAY_REVERSE;
942 case MCI_DEVTYPE_VIDEODISC:
943 flags |= MCI_VD_PLAY_REVERSE;
947 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_PLAY,
948 flags, (DWORD_PTR)&mci_play);
951 MCIWND_notify_error(mwi);
952 return mwi->lasterror;
955 MCIWND_notify_mode(mwi);
956 MCIWND_UpdateState(mwi);
960 case MCIWNDM_GETERRORA:
961 mciGetErrorStringA(mwi->lasterror, (LPSTR)lParam, wParam);
962 TRACE("MCIWNDM_GETERRORA: %s\n", debugstr_an((LPSTR)lParam, wParam));
963 return mwi->lasterror;
965 case MCIWNDM_GETERRORW:
966 mciGetErrorStringW(mwi->lasterror, (LPWSTR)lParam, wParam);
967 TRACE("MCIWNDM_GETERRORW: %s\n", debugstr_wn((LPWSTR)lParam, wParam));
968 return mwi->lasterror;
970 case MCIWNDM_SETOWNER:
971 TRACE("MCIWNDM_SETOWNER %p\n", (HWND)wParam);
972 mwi->hwndOwner = (HWND)wParam;
975 case MCIWNDM_SENDSTRINGA:
977 UNICODE_STRING stringW;
979 TRACE("MCIWNDM_SENDSTRINGA %s\n", debugstr_a((LPCSTR)lParam));
981 RtlCreateUnicodeStringFromAsciiz(&stringW, (LPCSTR)lParam);
982 lParam = (LPARAM)stringW.Buffer;
985 case MCIWNDM_SENDSTRINGW:
989 TRACE("MCIWNDM_SENDSTRINGW %s\n", debugstr_w((LPCWSTR)lParam));
991 p = strchrW((LPCWSTR)lParam, ' ');
994 static const WCHAR formatW[] = {'%','d',' ',0};
997 pos = p - (WCHAR *)lParam + 1;
998 len = lstrlenW((LPCWSTR)lParam) + 64;
1000 cmdW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1002 memcpy(cmdW, (void *)lParam, pos * sizeof(WCHAR));
1003 wsprintfW(cmdW + pos, formatW, mwi->alias);
1004 strcatW(cmdW, (WCHAR *)lParam + pos);
1007 cmdW = (LPWSTR)lParam;
1009 mwi->lasterror = mciSendStringW(cmdW, mwi->return_string,
1010 sizeof(mwi->return_string)/sizeof(mwi->return_string[0]),
1013 MCIWND_notify_error(mwi);
1015 if (cmdW != (LPWSTR)lParam)
1016 HeapFree(GetProcessHeap(), 0, cmdW);
1018 if (wMsg == MCIWNDM_SENDSTRINGA)
1019 HeapFree(GetProcessHeap(), 0, (void *)lParam);
1021 MCIWND_UpdateState(mwi);
1022 return mwi->lasterror;
1025 case MCIWNDM_RETURNSTRINGA:
1026 WideCharToMultiByte(CP_ACP, 0, mwi->return_string, -1, (LPSTR)lParam, wParam, NULL, NULL);
1027 TRACE("MCIWNDM_RETURNTRINGA %s\n", debugstr_an((LPSTR)lParam, wParam));
1028 return mwi->lasterror;
1030 case MCIWNDM_RETURNSTRINGW:
1031 lstrcpynW((LPWSTR)lParam, mwi->return_string, wParam);
1032 TRACE("MCIWNDM_RETURNTRINGW %s\n", debugstr_wn((LPWSTR)lParam, wParam));
1033 return mwi->lasterror;
1035 case MCIWNDM_SETTIMERS:
1036 TRACE("MCIWNDM_SETTIMERS active %d ms, inactive %d ms\n", (int)wParam, (int)lParam);
1037 mwi->active_timer = (WORD)wParam;
1038 mwi->inactive_timer = (WORD)lParam;
1041 case MCIWNDM_SETACTIVETIMER:
1042 TRACE("MCIWNDM_SETACTIVETIMER %d ms\n", (int)wParam);
1043 mwi->active_timer = (WORD)wParam;
1046 case MCIWNDM_SETINACTIVETIMER:
1047 TRACE("MCIWNDM_SETINACTIVETIMER %d ms\n", (int)wParam);
1048 mwi->inactive_timer = (WORD)wParam;
1051 case MCIWNDM_GETACTIVETIMER:
1052 TRACE("MCIWNDM_GETACTIVETIMER: %d ms\n", mwi->active_timer);
1053 return mwi->active_timer;
1055 case MCIWNDM_GETINACTIVETIMER:
1056 TRACE("MCIWNDM_GETINACTIVETIMER: %d ms\n", mwi->inactive_timer);
1057 return mwi->inactive_timer;
1059 case MCIWNDM_CHANGESTYLES:
1060 TRACE("MCIWNDM_CHANGESTYLES mask %08x, set %08lx\n", wParam, lParam);
1061 /* FIXME: update the visual window state as well:
1062 * add/remove trackbar, autosize, etc.
1064 mwi->dwStyle &= ~wParam;
1065 mwi->dwStyle |= lParam & wParam;
1068 case MCIWNDM_GETSTYLES:
1069 TRACE("MCIWNDM_GETSTYLES: %08x\n", mwi->dwStyle & 0xffff);
1070 return mwi->dwStyle & 0xffff;
1072 case MCIWNDM_GETDEVICEA:
1074 MCI_SYSINFO_PARMSA mci_sysinfo;
1076 mci_sysinfo.lpstrReturn = (LPSTR)lParam;
1077 mci_sysinfo.dwRetSize = wParam;
1078 mwi->lasterror = mciSendCommandA(mwi->mci, MCI_SYSINFO,
1079 MCI_SYSINFO_INSTALLNAME,
1080 (DWORD_PTR)&mci_sysinfo);
1081 TRACE("MCIWNDM_GETDEVICEA: %s\n", debugstr_an((LPSTR)lParam, wParam));
1085 case MCIWNDM_GETDEVICEW:
1087 MCI_SYSINFO_PARMSW mci_sysinfo;
1089 mci_sysinfo.lpstrReturn = (LPWSTR)lParam;
1090 mci_sysinfo.dwRetSize = wParam;
1091 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_SYSINFO,
1092 MCI_SYSINFO_INSTALLNAME,
1093 (DWORD_PTR)&mci_sysinfo);
1094 TRACE("MCIWNDM_GETDEVICEW: %s\n", debugstr_wn((LPWSTR)lParam, wParam));
1098 case MCIWNDM_VALIDATEMEDIA:
1099 TRACE("MCIWNDM_VALIDATEMEDIA\n");
1102 SendMessageW(hWnd, MCIWNDM_GETSTART, 0, 0);
1103 SendMessageW(hWnd, MCIWNDM_GETLENGTH, 0, 0);
1107 case MCIWNDM_GETFILENAMEA:
1108 TRACE("MCIWNDM_GETFILENAMEA: %s\n", debugstr_w(mwi->lpName));
1110 WideCharToMultiByte(CP_ACP, 0, mwi->lpName, -1, (LPSTR)lParam, wParam, NULL, NULL);
1113 case MCIWNDM_GETFILENAMEW:
1114 TRACE("MCIWNDM_GETFILENAMEW: %s\n", debugstr_w(mwi->lpName));
1116 lstrcpynW((LPWSTR)lParam, mwi->lpName, wParam);
1119 case MCIWNDM_GETTIMEFORMATA:
1120 case MCIWNDM_GETTIMEFORMATW:
1122 MCI_STATUS_PARMS mci_status;
1124 TRACE("MCIWNDM_GETTIMEFORMAT %08x %08lx\n", wParam, lParam);
1126 /* get format string if requested */
1127 if (wParam && lParam)
1129 if (wMsg == MCIWNDM_GETTIMEFORMATA)
1133 wsprintfA(cmd, "status %d time format", mwi->alias);
1134 mwi->lasterror = mciSendStringA(cmd, (LPSTR)lParam, wParam, 0);
1141 static const WCHAR formatW[] = {'s','t','a','t','u','s',' ','%','d',' ','t','i','m','e',' ','f','o','r','m','a','t',0};
1143 wsprintfW(cmdW, formatW, mwi->alias);
1144 mwi->lasterror = mciSendStringW(cmdW, (LPWSTR)lParam, wParam, 0);
1150 mci_status.dwItem = MCI_STATUS_TIME_FORMAT ;
1151 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_STATUS,
1153 (DWORD_PTR)&mci_status);
1157 return mci_status.dwReturn;
1160 case MCIWNDM_SETTIMEFORMATA:
1162 UNICODE_STRING stringW;
1164 TRACE("MCIWNDM_SETTIMEFORMATA %s\n", debugstr_a((LPSTR)lParam));
1166 RtlCreateUnicodeStringFromAsciiz(&stringW, (LPCSTR)lParam);
1167 lParam = (LPARAM)stringW.Buffer;
1170 case MCIWNDM_SETTIMEFORMATW:
1172 static const WCHAR formatW[] = {'s','e','t',' ','%','d',' ','t','i','m','e',' ','f','o','r','m','a','t',' ',0};
1175 TRACE("MCIWNDM_SETTIMEFORMATW %s\n", debugstr_w((LPWSTR)lParam));
1179 cmdW = HeapAlloc(GetProcessHeap(), 0, (lstrlenW((LPCWSTR)lParam) + 64) * sizeof(WCHAR));
1180 wsprintfW(cmdW, formatW, mwi->alias);
1181 strcatW(cmdW, (WCHAR *)lParam);
1183 mwi->lasterror = mciSendStringW(cmdW, NULL, 0, 0);
1185 /* fix the range tracking according to the new time format */
1186 if (!mwi->lasterror)
1187 SendDlgItemMessageW(hWnd, CTL_TRACKBAR, TBM_SETRANGEMAX, 1,
1188 SendMessageW(hWnd, MCIWNDM_GETLENGTH, 0, 0));
1191 if (wMsg == MCIWNDM_SETTIMEFORMATA)
1192 HeapFree(GetProcessHeap(), 0, (void *)lParam);
1197 case MCIWNDM_CAN_PLAY:
1198 TRACE("MCIWNDM_CAN_PLAY\n");
1200 return mci_get_devcaps(mwi, MCI_GETDEVCAPS_CAN_PLAY);
1203 case MCIWNDM_CAN_RECORD:
1204 TRACE("MCIWNDM_CAN_RECORD\n");
1206 return mci_get_devcaps(mwi, MCI_GETDEVCAPS_CAN_RECORD);
1209 case MCIWNDM_CAN_SAVE:
1210 TRACE("MCIWNDM_CAN_SAVE\n");
1212 return mci_get_devcaps(mwi, MCI_GETDEVCAPS_CAN_SAVE);
1215 case MCIWNDM_CAN_EJECT:
1216 TRACE("MCIWNDM_CAN_EJECT\n");
1218 return mci_get_devcaps(mwi, MCI_GETDEVCAPS_CAN_EJECT);
1221 case MCIWNDM_CAN_WINDOW:
1222 TRACE("MCIWNDM_CAN_WINDOW\n");
1223 switch (mwi->dev_type)
1225 case MCI_DEVTYPE_ANIMATION:
1226 case MCI_DEVTYPE_DIGITAL_VIDEO:
1227 case MCI_DEVTYPE_OVERLAY:
1232 case MCIWNDM_CAN_CONFIG:
1233 TRACE("MCIWNDM_CAN_CONFIG\n");
1235 return SendDriverMessage(mwi->hdrv, DRV_QUERYCONFIGURE, 0, 0);
1238 case MCIWNDM_SETZOOM:
1239 TRACE("MCIWNDM_SETZOOM %ld\n", lParam);
1242 if (mwi->mci && !(mwi->dwStyle & MCIWNDF_NOAUTOSIZEWINDOW))
1246 rc.left = rc.top = 0;
1247 rc.right = MulDiv(mwi->size.cx, mwi->zoom, 100);
1248 rc.bottom = MulDiv(mwi->size.cy, mwi->zoom, 100);
1250 if (!(mwi->dwStyle & MCIWNDF_NOPLAYBAR))
1251 rc.bottom += 32; /* add the height of the playbar */
1252 AdjustWindowRect(&rc, GetWindowLongW(hWnd, GWL_STYLE), FALSE);
1253 SetWindowPos(hWnd, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
1254 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
1258 case MCIWNDM_GETZOOM:
1259 TRACE("MCIWNDM_GETZOOM: %d\n", mwi->zoom);
1264 MCI_SET_PARMS mci_set;
1266 TRACE("MCIWNDM_EJECT\n");
1268 mci_set.dwCallback = (DWORD_PTR)hWnd;
1269 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_SET,
1270 MCI_SET_DOOR_OPEN | MCI_NOTIFY,
1271 (DWORD_PTR)&mci_set);
1272 MCIWND_notify_mode(mwi);
1273 MCIWND_UpdateState(mwi);
1274 return mwi->lasterror;
1277 case MCIWNDM_SETVOLUME:
1278 case MCIWNDM_GETVOLUME:
1279 case MCIWNDM_SETSPEED:
1280 case MCIWNDM_GETSPEED:
1281 case MCIWNDM_SETREPEAT:
1282 case MCIWNDM_GETREPEAT:
1283 case MCIWNDM_REALIZE:
1284 case MCIWNDM_GETPALETTE:
1285 case MCIWNDM_SETPALETTE:
1288 case MCIWNDM_PALETTEKICK:
1289 case MCIWNDM_OPENINTERFACE:
1290 FIXME("support for MCIWNDM_ message WM_USER+%d not implemented\n", wMsg - WM_USER);
1295 LRESULT end = SendMessageW(hWnd, MCIWNDM_GETEND, 0, 0);
1296 return SendMessageW(hWnd, MCIWNDM_PLAYTO, 0, end);
1301 MCI_SEEK_PARMS mci_seek;
1306 lParam = SendMessageW(hWnd, MCIWNDM_GETSTART, 0, 0);
1310 lParam = SendMessageW(hWnd, MCIWNDM_GETEND, 0, 0);
1314 mci_seek.dwTo = lParam;
1315 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_SEEK,
1316 MCI_TO, (DWORD_PTR)&mci_seek);
1319 MCIWND_notify_error(mwi);
1320 return mwi->lasterror;
1322 /* update window to reflect the state */
1323 InvalidateRect(hWnd, NULL, TRUE);
1330 MCI_GENERIC_PARMS mci_generic;
1334 CloseDriver(mwi->hdrv, 0, 0);
1340 mci_generic.dwCallback = 0;
1341 mwi->lasterror = mciSendCommandW(mwi->mci, MCI_CLOSE,
1342 0, (DWORD_PTR)&mci_generic);
1346 mwi->mode = MCI_MODE_NOT_READY;
1349 HeapFree(GetProcessHeap(), 0, mwi->lpName);
1351 MCIWND_UpdateState(mwi);
1353 GetClientRect(hWnd, &rc);
1355 if (!(mwi->dwStyle & MCIWNDF_NOPLAYBAR))
1356 rc.bottom += 32; /* add the height of the playbar */
1357 AdjustWindowRect(&rc, GetWindowLongW(hWnd, GWL_STYLE), FALSE);
1358 SetWindowPos(hWnd, 0, 0, 0, rc.right - rc.left,
1359 rc.bottom - rc.top, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
1361 MCIWND_notify_media(mwi);
1369 mci_generic_command(mwi, wMsg);
1370 if (wMsg == MCI_STEP && !mwi->lasterror)
1372 /* update window to reflect the state */
1373 InvalidateRect(hWnd, NULL, TRUE);
1375 return mwi->lasterror;
1379 SendDriverMessage(mwi->hdrv, DRV_CONFIGURE, (LPARAM)hWnd, 0);
1390 case MCI_GETDEVCAPS:
1408 /*case MCI_SETTIMECODE:*/
1409 /*case MCI_SETTUNER:*/
1420 FIXME("support for MCI_ command %04x not implemented\n", wMsg);
1424 if (wMsg >= WM_USER)
1426 FIXME("support for MCIWNDM_ message WM_USER+%d not implemented\n", wMsg - WM_USER);
1430 if (GetWindowLongW(hWnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1431 return DefMDIChildProcW(hWnd, wMsg, wParam, lParam);
1433 return DefWindowProcW(hWnd, wMsg, wParam, lParam);