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
20 #define COM_NO_WINDOWS_H
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mci
);
45 static LRESULT WINAPI
MCIWndProc(HWND hWnd
, UINT wMsg
, WPARAM lParam1
, LPARAM lParam2
);
47 #define CTL_PLAYSTOP 0x3200
48 #define CTL_MENU 0x3201
49 #define CTL_TRACKBAR 0x3202
51 /***********************************************************************
52 * MCIWndRegisterClass [MSVFW32.@]
54 BOOL WINAPI
MCIWndRegisterClass(HINSTANCE hInst
)
58 /* since window creation will also require some common controls, init them */
62 wc
.lpfnWndProc
= MCIWndProc
;
64 wc
.cbWndExtra
= sizeof(MCIWndInfo
*);
69 wc
.lpszMenuName
= NULL
;
70 wc
.lpszClassName
= "MCIWndClass";
72 return RegisterClassA(&wc
);
76 /***********************************************************************
77 * MCIWndCreate [MSVFW32.@]
78 * MCIWndCreateA [MSVFW32.@]
80 HWND VFWAPIV
MCIWndCreateA(HWND hwndParent
, HINSTANCE hInstance
,
81 DWORD dwStyle
, LPCSTR szFile
)
86 TRACE("%p %p %lx %s\n", hwndParent
, hInstance
, dwStyle
, szFile
);
88 MCIWndRegisterClass(hInstance
);
90 mwi
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mwi
));
93 mwi
->dwStyle
= dwStyle
;
95 mwi
->lpName
= strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(szFile
) + 1), szFile
);
100 wndStyle
= ((hwndParent
) ? (WS_CHILD
|WS_BORDER
) : WS_OVERLAPPEDWINDOW
) |
101 WS_VISIBLE
| (dwStyle
& 0xFFFF0000);
103 if (CreateWindowExA(0, "MCIWndClass", NULL
, wndStyle
,
104 CW_USEDEFAULT
, CW_USEDEFAULT
,
105 CW_USEDEFAULT
, CW_USEDEFAULT
,
106 hwndParent
, NULL
, hInstance
, mwi
))
109 if(mwi
->lpName
) HeapFree(GetProcessHeap(), 0, mwi
->lpName
);
110 HeapFree(GetProcessHeap(), 0, mwi
);
114 /***********************************************************************
115 * MCIWndCreateW [MSVFW32.@]
117 HWND VFWAPIV
MCIWndCreateW(HWND hwndParent
, HINSTANCE hInstance
,
118 DWORD dwStyle
, LPCWSTR szFile
)
120 FIXME("%p %p %lx %s\n", hwndParent
, hInstance
, dwStyle
, debugstr_w(szFile
));
122 MCIWndRegisterClass(hInstance
);
127 static DWORD
MCIWND_GetStatus(MCIWndInfo
* mwi
)
129 MCI_DGV_STATUS_PARMSA mdsp
;
131 memset(&mdsp
, 0, sizeof(mdsp
));
132 mdsp
.dwItem
= MCI_STATUS_MODE
;
133 if (mciSendCommandA(mwi
->mci
, MCI_STATUS
, MCI_WAIT
|MCI_STATUS_ITEM
, (DWORD
)&mdsp
))
134 return MCI_MODE_NOT_READY
;
135 if (mdsp
.dwReturn
== MCI_MODE_STOP
&& mwi
->uTimer
) {
136 TRACE("Killing timer\n");
137 KillTimer(mwi
->hWnd
, 0);
140 return mdsp
.dwReturn
;
143 static DWORD
MCIWND_Get(MCIWndInfo
* mwi
, DWORD what
)
145 MCI_DGV_STATUS_PARMSA mdsp
;
147 memset(&mdsp
, 0, sizeof(mdsp
));
149 if (mciSendCommandA(mwi
->mci
, MCI_STATUS
, MCI_WAIT
|MCI_STATUS_ITEM
, (DWORD
)&mdsp
))
151 return mdsp
.dwReturn
;
154 static void MCIWND_SetText(MCIWndInfo
* mwi
)
158 if (mwi
->dwStyle
& MCIWNDF_SHOWNAME
) {
159 strcpy(buffer
, mwi
->lpName
);
164 if (mwi
->dwStyle
& (MCIWNDF_SHOWPOS
|MCIWNDF_SHOWMODE
)) {
165 if (*buffer
) strcat(buffer
, " ");
169 if (mwi
->dwStyle
& MCIWNDF_SHOWPOS
) {
170 sprintf(buffer
+ strlen(buffer
), "%ld", MCIWND_Get(mwi
, MCI_STATUS_POSITION
));
173 if ((mwi
->dwStyle
& (MCIWNDF_SHOWPOS
|MCIWNDF_SHOWMODE
)) == (MCIWNDF_SHOWPOS
|MCIWNDF_SHOWMODE
)) {
174 strcat(buffer
, " - ");
177 if (mwi
->dwStyle
& MCIWNDF_SHOWMODE
) {
178 switch (MCIWND_GetStatus(mwi
)) {
179 case MCI_MODE_NOT_READY
: strcat(buffer
, "not ready"); break;
180 case MCI_MODE_PAUSE
: strcat(buffer
, "paused"); break;
181 case MCI_MODE_PLAY
: strcat(buffer
, "playing"); break;
182 case MCI_MODE_STOP
: strcat(buffer
, "stopped"); break;
183 case MCI_MODE_OPEN
: strcat(buffer
, "open"); break;
184 case MCI_MODE_RECORD
: strcat(buffer
, "recording"); break;
185 case MCI_MODE_SEEK
: strcat(buffer
, "seeking"); break;
186 default: strcat(buffer
, "???"); break;
189 if (mwi
->dwStyle
& (MCIWNDF_SHOWPOS
|MCIWNDF_SHOWMODE
)) {
190 strcat(buffer
, " )");
192 TRACE("=> '%s'\n", buffer
);
193 SetWindowTextA(mwi
->hWnd
, buffer
);
196 static void MCIWND_Create(HWND hWnd
, LPCREATESTRUCTA cs
)
198 MCI_DGV_OPEN_PARMSA mdopn
;
199 MCI_DGV_RECT_PARMS mdrct
;
203 MCIWndInfo
* mwi
= (MCIWndInfo
*)cs
->lpCreateParams
;
205 SetWindowLongA(hWnd
, 0, (LPARAM
)mwi
);
208 /* now open MCI player for AVI file */
209 memset(&mdopn
, 0, sizeof(mdopn
));
210 mdopn
.lpstrElementName
= mwi
->lpName
;
211 mdopn
.dwStyle
= WS_VISIBLE
|WS_CHILD
;
212 mdopn
.hWndParent
= hWnd
;
214 mmr
= mciSendCommandA(0, MCI_OPEN
, MCI_OPEN_ELEMENT
|MCI_DGV_OPEN_PARENT
|MCI_DGV_OPEN_WS
, (LPARAM
)&mdopn
);
216 MessageBoxA(GetTopWindow(hWnd
), "Cannot open file", "MciWnd", MB_OK
);
219 mwi
->mci
= mdopn
.wDeviceID
;
221 /* grab AVI window size */
222 memset(&mdrct
, 0, sizeof(mdrct
));
223 mmr
= mciSendCommandA(mwi
->mci
, MCI_WHERE
, MCI_DGV_WHERE_DESTINATION
, (LPARAM
)&mdrct
);
225 WARN("Cannot get window rect\n");
228 cx
= mdrct
.rc
.right
- mdrct
.rc
.left
;
229 cy
= mdrct
.rc
.bottom
- mdrct
.rc
.top
;
231 AdjustWindowRect(&mdrct
.rc
, GetWindowLongA(hWnd
, GWL_STYLE
), FALSE
);
232 SetWindowPos(hWnd
, 0, 0, 0, mdrct
.rc
.right
- mdrct
.rc
.left
,
233 mdrct
.rc
.bottom
- mdrct
.rc
.top
+ 32, SWP_NOMOVE
|SWP_NOZORDER
);
235 /* adding the other elements: play/stop button, menu button, status */
236 hChld
= CreateWindowExA(0, "BUTTON", "Play", WS_CHILD
|WS_VISIBLE
, 0, cy
, 32, 32,
237 hWnd
, (HMENU
)CTL_PLAYSTOP
,
238 (HINSTANCE
)GetWindowLongA(hWnd
, GWL_HINSTANCE
), 0L);
239 TRACE("Get Button1: %p\n", hChld
);
240 hChld
= CreateWindowExA(0, "BUTTON", "Menu", WS_CHILD
|WS_VISIBLE
, 32, cy
, 32, 32,
241 hWnd
, (HMENU
)CTL_MENU
,
242 (HINSTANCE
)GetWindowLongA(hWnd
, GWL_HINSTANCE
), 0L);
243 TRACE("Get Button2: %p\n", hChld
);
244 hChld
= CreateWindowExA(0, TRACKBAR_CLASSA
, "", WS_CHILD
|WS_VISIBLE
, 64, cy
, cx
- 64, 32,
245 hWnd
, (HMENU
)CTL_TRACKBAR
,
246 (HINSTANCE
)GetWindowLongA(hWnd
, GWL_HINSTANCE
), 0L);
247 TRACE("Get status: %p\n", hChld
);
248 SendMessageA(hChld
, TBM_SETRANGEMIN
, 0L, 0L);
249 SendMessageA(hChld
, TBM_SETRANGEMAX
, 1L, MCIWND_Get(mwi
, MCI_STATUS_LENGTH
));
251 /* FIXME: no need to set it if child window */
255 static void MCIWND_Paint(MCIWndInfo
* mwi
, WPARAM wParam
)
260 hdc
= (wParam
) ? (HDC
)wParam
: BeginPaint(mwi
->hWnd
, &ps
);
261 /* something to do ? */
262 if (!wParam
) EndPaint(mwi
->hWnd
, &ps
);
265 static void MCIWND_ToggleState(MCIWndInfo
* mwi
)
267 MCI_GENERIC_PARMS mgp
;
268 MCI_DGV_PLAY_PARMS mdply
;
270 memset(&mgp
, 0, sizeof(mgp
));
271 memset(&mdply
, 0, sizeof(mdply
));
273 switch (MCIWND_GetStatus(mwi
)) {
274 case MCI_MODE_NOT_READY
:
275 case MCI_MODE_RECORD
:
278 TRACE("Cannot do much...\n");
281 mciSendCommandA(mwi
->mci
, MCI_RESUME
, MCI_WAIT
, (LPARAM
)&mgp
);
284 mciSendCommandA(mwi
->mci
, MCI_PAUSE
, MCI_WAIT
, (LPARAM
)&mgp
);
288 mciSendCommandA(mwi
->mci
, MCI_PLAY
, MCI_FROM
, (LPARAM
)&mdply
);
289 mwi
->uTimer
= SetTimer(mwi
->hWnd
, 0, 333, 0L);
290 TRACE("Timer=%u\n", mwi
->uTimer
);
295 static LRESULT
MCIWND_Command(MCIWndInfo
* mwi
, WPARAM wParam
, LPARAM lParam
)
297 switch (LOWORD(wParam
)) {
298 case CTL_PLAYSTOP
: MCIWND_ToggleState(mwi
); break;
302 MessageBoxA(0, "ooch", "NIY", MB_OK
);
307 static void MCIWND_Timer(MCIWndInfo
* mwi
, WPARAM wParam
, LPARAM lParam
)
309 TRACE("%ld\n", MCIWND_Get(mwi
, MCI_STATUS_POSITION
));
310 SendDlgItemMessageA(mwi
->hWnd
, CTL_TRACKBAR
, TBM_SETPOS
, 1, MCIWND_Get(mwi
, MCI_STATUS_POSITION
));
314 static void MCIWND_Close(MCIWndInfo
* mwi
)
316 MCI_GENERIC_PARMS mgp
;
318 memset(&mgp
, 0, sizeof(mgp
));
320 mciSendCommandA(mwi
->mci
, MCI_CLOSE
, 0, (LPARAM
)&mgp
);
323 static LRESULT WINAPI
MCIWndProc(HWND hWnd
, UINT wMsg
, WPARAM lParam1
, LPARAM lParam2
)
325 MCIWndInfo
* mwi
= (MCIWndInfo
*)GetWindowLongA(hWnd
, 0);
327 if (mwi
|| wMsg
== WM_CREATE
) {
330 MCIWND_Create(hWnd
, (CREATESTRUCTA
*)lParam2
);
334 HeapFree(GetProcessHeap(), 0, mwi
->lpName
);
335 HeapFree(GetProcessHeap(), 0, mwi
);
338 MCIWND_Paint(mwi
, lParam1
);
341 return MCIWND_Command(mwi
, lParam1
, lParam2
);
343 MCIWND_Timer(mwi
, lParam1
, lParam2
);
348 return DefWindowProcA(hWnd
, wMsg
, lParam1
, lParam2
);