2 * Digital video MCI Wine Driver
4 * Copyright 1999, 2000 Eric POUECH
5 * Copyright 2003 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "private_mciavi.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(mciavi
);
28 static LRESULT WINAPI
MCIAVI_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
30 TRACE("hwnd=%p msg=%x wparam=%Ix lparam=%Ix\n", hWnd
, uMsg
, wParam
, lParam
);
34 SetWindowLongW(hWnd
, 0, (LPARAM
)((CREATESTRUCTW
*)lParam
)->lpCreateParams
);
35 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
38 MCIAVI_mciClose(GetWindowLongW(hWnd
, 0), MCI_WAIT
, NULL
);
39 SetWindowLongW(hWnd
, 0, 0);
40 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
45 GetClientRect(hWnd
, &rect
);
46 FillRect((HDC
)wParam
, &rect
, GetStockObject(BLACK_BRUSH
));
52 WINE_MCIAVI
*wma
= (WINE_MCIAVI
*)mciGetDriverData(GetWindowLongW(hWnd
, 0));
55 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
57 EnterCriticalSection(&wma
->cs
);
59 /* the animation isn't playing, don't paint */
60 if (wma
->dwStatus
== MCI_MODE_NOT_READY
)
62 LeaveCriticalSection(&wma
->cs
);
63 /* default paint handling */
64 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
68 MCIAVI_PaintFrame(wma
, (HDC
)wParam
);
72 BeginPaint(hWnd
, &ps
);
73 MCIAVI_PaintFrame(wma
, ps
.hdc
);
77 LeaveCriticalSection(&wma
->cs
);
82 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
86 BOOL
MCIAVI_UnregisterClass(void)
88 return UnregisterClassW(L
"MCIAVI", MCIAVI_hInstance
);
91 BOOL
MCIAVI_RegisterClass(void)
95 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
96 wndClass
.style
= CS_DBLCLKS
;
97 wndClass
.lpfnWndProc
= MCIAVI_WindowProc
;
98 wndClass
.cbWndExtra
= sizeof(MCIDEVICEID
);
99 wndClass
.hInstance
= MCIAVI_hInstance
;
100 wndClass
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
101 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_3DFACE
+ 1);
102 wndClass
.lpszClassName
= L
"MCIAVI";
104 if (RegisterClassW(&wndClass
)) return TRUE
;
105 if (GetLastError() == ERROR_CLASS_ALREADY_EXISTS
) return TRUE
;
110 BOOL
MCIAVI_CreateWindow(WINE_MCIAVI
* wma
, DWORD dwFlags
, LPMCI_DGV_OPEN_PARMSW lpParms
)
113 DWORD dwStyle
= WS_OVERLAPPEDWINDOW
;
116 /* what should be done ? */
117 if (wma
->hWnd
) return TRUE
;
119 if (dwFlags
& MCI_DGV_OPEN_PARENT
) hParent
= lpParms
->hWndParent
;
120 if (dwFlags
& MCI_DGV_OPEN_WS
) dwStyle
= lpParms
->dwStyle
;
123 SetRect(&rc
, 0, 0, wma
->outbih
->biWidth
, wma
->outbih
->biHeight
);
125 SetRect(&rc
, 0, 0, wma
->inbih
->biWidth
, wma
->inbih
->biHeight
);
127 AdjustWindowRect(&rc
, dwStyle
, FALSE
);
128 if (!(dwStyle
& (WS_CHILD
|WS_POPUP
))) /* overlapped window ? */
132 rc
.left
= rc
.top
= CW_USEDEFAULT
;
135 wma
->hWnd
= CreateWindowW(L
"MCIAVI", L
"Wine MCI-AVI player", dwStyle
, rc
.left
, rc
.top
,
136 rc
.right
, rc
.bottom
, hParent
, 0, MCIAVI_hInstance
,
137 ULongToPtr(wma
->wDevID
));
138 wma
->hWndPaint
= wma
->hWnd
;
140 TRACE("(%04x, %08lX, %p, style %lx, parent %p, dimensions %ldx%ld, hwnd %p)\n", wma
->wDevID
,
141 dwFlags
, lpParms
, dwStyle
, hParent
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, wma
->hWnd
);
142 return wma
->hWnd
!= 0;
145 /***************************************************************************
146 * MCIAVI_mciPut [internal]
148 DWORD
MCIAVI_mciPut(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_PUT_PARMS lpParms
)
150 WINE_MCIAVI
* wma
= MCIAVI_mciGetOpenDev(wDevID
);
153 TRACE("(%04x, %08lX, %p)\n", wDevID
, dwFlags
, lpParms
);
155 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
156 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
157 if (dwFlags
& MCI_TEST
) return 0;
159 EnterCriticalSection(&wma
->cs
);
161 if (dwFlags
& MCI_DGV_RECT
) {
162 /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
163 * So convert input MCI RECT into a normal RECT */
164 SetRect(&rc
, lpParms
->rc
.left
, lpParms
->rc
.top
, lpParms
->rc
.left
+ lpParms
->rc
.right
,
165 lpParms
->rc
.top
+ lpParms
->rc
.bottom
);
167 GetClientRect(wma
->hWndPaint
, &rc
);
170 if (dwFlags
& MCI_DGV_PUT_CLIENT
) {
171 FIXME("PUT_CLIENT %s\n", wine_dbgstr_rect(&rc
));
172 LeaveCriticalSection(&wma
->cs
);
173 return MCIERR_UNRECOGNIZED_COMMAND
;
175 if (dwFlags
& MCI_DGV_PUT_DESTINATION
) {
176 TRACE("PUT_DESTINATION %s\n", wine_dbgstr_rect(&rc
));
179 if (dwFlags
& MCI_DGV_PUT_FRAME
) {
180 FIXME("PUT_FRAME %s\n", wine_dbgstr_rect(&rc
));
181 LeaveCriticalSection(&wma
->cs
);
182 return MCIERR_UNRECOGNIZED_COMMAND
;
184 if (dwFlags
& MCI_DGV_PUT_SOURCE
) {
185 TRACE("PUT_SOURCE %s\n", wine_dbgstr_rect(&rc
));
188 if (dwFlags
& MCI_DGV_PUT_VIDEO
) {
189 FIXME("PUT_VIDEO %s\n", wine_dbgstr_rect(&rc
));
190 LeaveCriticalSection(&wma
->cs
);
191 return MCIERR_UNRECOGNIZED_COMMAND
;
193 if (dwFlags
& MCI_DGV_PUT_WINDOW
) {
194 TRACE("PUT_WINDOW %s\n", wine_dbgstr_rect(&rc
));
195 SetWindowPos(wma
->hWndPaint
, NULL
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, SWP_NOZORDER
);
197 LeaveCriticalSection(&wma
->cs
);
201 /******************************************************************************
202 * MCIAVI_mciWhere [internal]
204 DWORD
MCIAVI_mciWhere(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_RECT_PARMS lpParms
)
206 WINE_MCIAVI
* wma
= MCIAVI_mciGetOpenDev(wDevID
);
209 TRACE("(%04x, %08lx, %p)\n", wDevID
, dwFlags
, lpParms
);
211 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
212 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
213 /* Ignore MCI_TEST flag. */
215 EnterCriticalSection(&wma
->cs
);
217 if (dwFlags
& MCI_DGV_WHERE_DESTINATION
) {
218 if (dwFlags
& MCI_DGV_WHERE_MAX
) {
219 GetClientRect(wma
->hWndPaint
, &rc
);
220 TRACE("WHERE_DESTINATION_MAX %s\n", wine_dbgstr_rect(&rc
));
222 TRACE("WHERE_DESTINATION %s\n", wine_dbgstr_rect(&wma
->dest
));
226 if (dwFlags
& MCI_DGV_WHERE_FRAME
) {
227 if (dwFlags
& MCI_DGV_WHERE_MAX
)
228 FIXME("MCI_DGV_WHERE_FRAME_MAX\n");
230 FIXME("MCI_DGV_WHERE_FRAME\n");
231 LeaveCriticalSection(&wma
->cs
);
232 return MCIERR_UNRECOGNIZED_COMMAND
;
234 if (dwFlags
& MCI_DGV_WHERE_SOURCE
) {
235 if (dwFlags
& MCI_DGV_WHERE_MAX
) {
236 SetRect(&rc
, 0, 0, wma
->inbih
->biWidth
, wma
->inbih
->biHeight
);
237 TRACE("WHERE_SOURCE_MAX %s\n", wine_dbgstr_rect(&rc
));
239 TRACE("WHERE_SOURCE %s\n", wine_dbgstr_rect(&wma
->source
));
243 if (dwFlags
& MCI_DGV_WHERE_VIDEO
) {
244 if (dwFlags
& MCI_DGV_WHERE_MAX
)
245 FIXME("WHERE_VIDEO_MAX\n");
247 FIXME("WHERE_VIDEO\n");
248 LeaveCriticalSection(&wma
->cs
);
249 return MCIERR_UNRECOGNIZED_COMMAND
;
251 if (dwFlags
& MCI_DGV_WHERE_WINDOW
) {
252 if (dwFlags
& MCI_DGV_WHERE_MAX
) {
253 GetWindowRect(GetDesktopWindow(), &rc
);
254 TRACE("WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&rc
));
256 GetWindowRect(wma
->hWndPaint
, &rc
);
257 TRACE("WHERE_WINDOW %s\n", wine_dbgstr_rect(&rc
));
261 /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
262 * So convert the normal RECT into a MCI RECT before returning */
263 SetRect(&lpParms
->rc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
265 LeaveCriticalSection(&wma
->cs
);
269 /***************************************************************************
270 * MCIAVI_mciWindow [internal]
272 DWORD
MCIAVI_mciWindow(UINT wDevID
, DWORD dwFlags
, LPMCI_DGV_WINDOW_PARMSW lpParms
)
274 WINE_MCIAVI
* wma
= MCIAVI_mciGetOpenDev(wDevID
);
276 TRACE("(%04x, %08lX, %p)\n", wDevID
, dwFlags
, lpParms
);
278 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
279 if (wma
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
280 if (dwFlags
& MCI_TEST
) return 0;
282 EnterCriticalSection(&wma
->cs
);
284 if (dwFlags
& MCI_DGV_WINDOW_HWND
) {
285 if (IsWindow(lpParms
->hWnd
))
287 TRACE("Setting hWnd to %p\n", lpParms
->hWnd
);
288 if (wma
->hWnd
) ShowWindow(wma
->hWnd
, SW_HIDE
);
289 wma
->hWndPaint
= (lpParms
->hWnd
== MCI_DGV_WINDOW_DEFAULT
) ? wma
->hWnd
: lpParms
->hWnd
;
292 if (dwFlags
& MCI_DGV_WINDOW_STATE
) {
293 TRACE("Setting nCmdShow to %d\n", lpParms
->nCmdShow
);
294 ShowWindow(wma
->hWndPaint
, lpParms
->nCmdShow
);
296 if (dwFlags
& MCI_DGV_WINDOW_TEXT
) {
297 TRACE("Setting caption to %s\n", debugstr_w(lpParms
->lpstrText
));
298 SetWindowTextW(wma
->hWndPaint
, lpParms
->lpstrText
);
301 LeaveCriticalSection(&wma
->cs
);