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
29 #include "wine/mmsystem16.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mci
);
44 static LRESULT WINAPI
MCIWndProc(HWND hWnd
, UINT wMsg
, WPARAM lParam1
, LPARAM lParam2
);
46 #define CTL_PLAYSTOP 0x3200
47 #define CTL_MENU 0x3201
48 #define CTL_TRACKBAR 0x3202
50 /***********************************************************************
51 * MCIWndRegisterClass [MSVFW32.@]
53 BOOL WINAPI
MCIWndRegisterClass(HINSTANCE hInst
)
57 /* since window creation will also require some common controls, init them */
61 wc
.lpfnWndProc
= MCIWndProc
;
63 wc
.cbWndExtra
= sizeof(MCIWndInfo
*);
68 wc
.lpszMenuName
= NULL
;
69 wc
.lpszClassName
= "MCIWndClass";
71 return RegisterClassA(&wc
);
75 /***********************************************************************
76 * MCIWndCreate [MSVFW32.@]
77 * MCIWndCreateA [MSVFW32.@]
79 HWND VFWAPIV
MCIWndCreateA(HWND hwndParent
, HINSTANCE hInstance
,
80 DWORD dwStyle
, LPCSTR szFile
)
85 TRACE("%p %p %lx %s\n", hwndParent
, hInstance
, dwStyle
, szFile
);
87 MCIWndRegisterClass(hInstance
);
89 mwi
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mwi
));
92 mwi
->dwStyle
= dwStyle
;
94 mwi
->lpName
= strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(szFile
) + 1), szFile
);
99 wndStyle
= ((hwndParent
) ? (WS_CHILD
|WS_BORDER
) : WS_OVERLAPPEDWINDOW
) |
100 WS_VISIBLE
| (dwStyle
& 0xFFFF0000);
102 if (CreateWindowExA(0, "MCIWndClass", NULL
, wndStyle
,
103 CW_USEDEFAULT
, CW_USEDEFAULT
,
104 CW_USEDEFAULT
, CW_USEDEFAULT
,
105 hwndParent
, (HMENU
)0, hInstance
, mwi
))
108 if(mwi
->lpName
) HeapFree(GetProcessHeap(), 0, mwi
->lpName
);
109 HeapFree(GetProcessHeap(), 0, mwi
);
113 /***********************************************************************
114 * MCIWndCreateW [MSVFW32.@]
116 HWND VFWAPIV
MCIWndCreateW(HWND hwndParent
, HINSTANCE hInstance
,
117 DWORD dwStyle
, LPCWSTR szFile
)
119 FIXME("%p %p %lx %s\n", hwndParent
, hInstance
, dwStyle
, debugstr_w(szFile
));
121 MCIWndRegisterClass(hInstance
);
126 static DWORD
MCIWND_GetStatus(MCIWndInfo
* mwi
)
128 MCI_DGV_STATUS_PARMSA mdsp
;
130 memset(&mdsp
, 0, sizeof(mdsp
));
131 mdsp
.dwItem
= MCI_STATUS_MODE
;
132 if (mciSendCommandA(mwi
->mci
, MCI_STATUS
, MCI_WAIT
|MCI_STATUS_ITEM
, (DWORD
)&mdsp
))
133 return MCI_MODE_NOT_READY
;
134 if (mdsp
.dwReturn
== MCI_MODE_STOP
&& mwi
->uTimer
) {
135 TRACE("Killing timer\n");
136 KillTimer(mwi
->hWnd
, 0);
139 return mdsp
.dwReturn
;
142 static DWORD
MCIWND_Get(MCIWndInfo
* mwi
, DWORD what
)
144 MCI_DGV_STATUS_PARMSA mdsp
;
146 memset(&mdsp
, 0, sizeof(mdsp
));
148 if (mciSendCommandA(mwi
->mci
, MCI_STATUS
, MCI_WAIT
|MCI_STATUS_ITEM
, (DWORD
)&mdsp
))
150 return mdsp
.dwReturn
;
153 static void MCIWND_SetText(MCIWndInfo
* mwi
)
157 if (mwi
->dwStyle
& MCIWNDF_SHOWNAME
) {
158 strcpy(buffer
, mwi
->lpName
);
163 if (mwi
->dwStyle
& (MCIWNDF_SHOWPOS
|MCIWNDF_SHOWMODE
)) {
164 if (*buffer
) strcat(buffer
, " ");
168 if (mwi
->dwStyle
& MCIWNDF_SHOWPOS
) {
169 sprintf(buffer
+ strlen(buffer
), "%ld", MCIWND_Get(mwi
, MCI_STATUS_POSITION
));
172 if ((mwi
->dwStyle
& (MCIWNDF_SHOWPOS
|MCIWNDF_SHOWMODE
)) == (MCIWNDF_SHOWPOS
|MCIWNDF_SHOWMODE
)) {
173 strcat(buffer
, " - ");
176 if (mwi
->dwStyle
& MCIWNDF_SHOWMODE
) {
177 switch (MCIWND_GetStatus(mwi
)) {
178 case MCI_MODE_NOT_READY
: strcat(buffer
, "not ready"); break;
179 case MCI_MODE_PAUSE
: strcat(buffer
, "paused"); break;
180 case MCI_MODE_PLAY
: strcat(buffer
, "playing"); break;
181 case MCI_MODE_STOP
: strcat(buffer
, "stopped"); break;
182 case MCI_MODE_OPEN
: strcat(buffer
, "open"); break;
183 case MCI_MODE_RECORD
: strcat(buffer
, "recording"); break;
184 case MCI_MODE_SEEK
: strcat(buffer
, "seeking"); break;
185 default: strcat(buffer
, "???"); break;
188 if (mwi
->dwStyle
& (MCIWNDF_SHOWPOS
|MCIWNDF_SHOWMODE
)) {
189 strcat(buffer
, " )");
191 TRACE("=> '%s'\n", buffer
);
192 SetWindowTextA(mwi
->hWnd
, buffer
);
195 static void MCIWND_Create(HWND hWnd
, LPCREATESTRUCTA cs
)
197 MCI_DGV_OPEN_PARMSA mdopn
;
198 MCI_DGV_RECT_PARMS mdrct
;
202 MCIWndInfo
* mwi
= (MCIWndInfo
*)cs
->lpCreateParams
;
204 SetWindowLongA(hWnd
, 0, (LPARAM
)mwi
);
207 /* now open MCI player for AVI file */
208 memset(&mdopn
, 0, sizeof(mdopn
));
209 mdopn
.lpstrElementName
= mwi
->lpName
;
210 mdopn
.dwStyle
= WS_VISIBLE
|WS_CHILD
;
211 mdopn
.hWndParent
= hWnd
;
213 mmr
= mciSendCommandA(0, MCI_OPEN
, MCI_OPEN_ELEMENT
|MCI_DGV_OPEN_PARENT
|MCI_DGV_OPEN_WS
, (LPARAM
)&mdopn
);
215 MessageBoxA(GetTopWindow(hWnd
), "Cannot open file", "MciWnd", MB_OK
);
218 mwi
->mci
= mdopn
.wDeviceID
;
220 /* grab AVI window size */
221 memset(&mdrct
, 0, sizeof(mdrct
));
222 mmr
= mciSendCommandA(mwi
->mci
, MCI_WHERE
, MCI_DGV_WHERE_DESTINATION
, (LPARAM
)&mdrct
);
224 WARN("Cannot get window rect\n");
227 cx
= mdrct
.rc
.right
- mdrct
.rc
.left
;
228 cy
= mdrct
.rc
.bottom
- mdrct
.rc
.top
;
230 AdjustWindowRect(&mdrct
.rc
, GetWindowLongA(hWnd
, GWL_STYLE
), FALSE
);
231 SetWindowPos(hWnd
, 0, 0, 0, mdrct
.rc
.right
- mdrct
.rc
.left
,
232 mdrct
.rc
.bottom
- mdrct
.rc
.top
+ 32, SWP_NOMOVE
|SWP_NOZORDER
);
234 /* adding the other elements: play/stop button, menu button, status */
235 hChld
= CreateWindowExA(0, "BUTTON", "Play", WS_CHILD
|WS_VISIBLE
, 0, cy
, 32, 32,
236 hWnd
, (HMENU
)CTL_PLAYSTOP
,
237 (HINSTANCE
)GetWindowLongA(hWnd
, GWL_HINSTANCE
), 0L);
238 TRACE("Get Button1: %p\n", hChld
);
239 hChld
= CreateWindowExA(0, "BUTTON", "Menu", WS_CHILD
|WS_VISIBLE
, 32, cy
, 32, 32,
240 hWnd
, (HMENU
)CTL_MENU
,
241 (HINSTANCE
)GetWindowLongA(hWnd
, GWL_HINSTANCE
), 0L);
242 TRACE("Get Button2: %p\n", hChld
);
243 hChld
= CreateWindowExA(0, TRACKBAR_CLASSA
, "", WS_CHILD
|WS_VISIBLE
, 64, cy
, cx
- 64, 32,
244 hWnd
, (HMENU
)CTL_TRACKBAR
,
245 (HINSTANCE
)GetWindowLongA(hWnd
, GWL_HINSTANCE
), 0L);
246 TRACE("Get status: %p\n", hChld
);
247 SendMessageA(hChld
, TBM_SETRANGEMIN
, 0L, 0L);
248 SendMessageA(hChld
, TBM_SETRANGEMAX
, 1L, MCIWND_Get(mwi
, MCI_STATUS_LENGTH
));
250 /* FIXME: no need to set it if child window */
254 static void MCIWND_Paint(MCIWndInfo
* mwi
, WPARAM wParam
)
259 hdc
= (wParam
) ? (HDC
)wParam
: BeginPaint(mwi
->hWnd
, &ps
);
260 /* something to do ? */
261 if (!wParam
) EndPaint(mwi
->hWnd
, &ps
);
264 static void MCIWND_ToggleState(MCIWndInfo
* mwi
)
266 MCI_GENERIC_PARMS mgp
;
267 MCI_DGV_PLAY_PARMS mdply
;
269 memset(&mgp
, 0, sizeof(mgp
));
270 memset(&mdply
, 0, sizeof(mdply
));
272 switch (MCIWND_GetStatus(mwi
)) {
273 case MCI_MODE_NOT_READY
:
274 case MCI_MODE_RECORD
:
277 TRACE("Cannot do much...\n");
280 mciSendCommandA(mwi
->mci
, MCI_RESUME
, MCI_WAIT
, (LPARAM
)&mgp
);
283 mciSendCommandA(mwi
->mci
, MCI_PAUSE
, MCI_WAIT
, (LPARAM
)&mgp
);
287 mciSendCommandA(mwi
->mci
, MCI_PLAY
, MCI_FROM
, (LPARAM
)&mdply
);
288 mwi
->uTimer
= SetTimer(mwi
->hWnd
, 0, 333, 0L);
289 TRACE("Timer=%u\n", mwi
->uTimer
);
294 static LRESULT
MCIWND_Command(MCIWndInfo
* mwi
, WPARAM wParam
, LPARAM lParam
)
296 switch (LOWORD(wParam
)) {
297 case CTL_PLAYSTOP
: MCIWND_ToggleState(mwi
); break;
301 MessageBoxA(0, "ooch", "NIY", MB_OK
);
306 static void MCIWND_Timer(MCIWndInfo
* mwi
, WPARAM wParam
, LPARAM lParam
)
308 TRACE("%ld\n", MCIWND_Get(mwi
, MCI_STATUS_POSITION
));
309 SendDlgItemMessageA(mwi
->hWnd
, CTL_TRACKBAR
, TBM_SETPOS
, 1, MCIWND_Get(mwi
, MCI_STATUS_POSITION
));
313 static void MCIWND_Close(MCIWndInfo
* mwi
)
315 MCI_GENERIC_PARMS mgp
;
317 memset(&mgp
, 0, sizeof(mgp
));
319 mciSendCommandA(mwi
->mci
, MCI_CLOSE
, 0, (LPARAM
)&mgp
);
322 static LRESULT WINAPI
MCIWndProc(HWND hWnd
, UINT wMsg
, WPARAM lParam1
, LPARAM lParam2
)
324 MCIWndInfo
* mwi
= (MCIWndInfo
*)GetWindowLongA(hWnd
, 0);
326 if (mwi
|| wMsg
== WM_CREATE
) {
329 MCIWND_Create(hWnd
, (CREATESTRUCTA
*)lParam2
);
333 HeapFree(GetProcessHeap(), 0, mwi
->lpName
);
334 HeapFree(GetProcessHeap(), 0, mwi
);
337 MCIWND_Paint(mwi
, lParam1
);
340 return MCIWND_Command(mwi
, lParam1
, lParam2
);
342 MCIWND_Timer(mwi
, lParam1
, lParam2
);
347 return DefWindowProcA(hWnd
, wMsg
, lParam1
, lParam2
);