Removed unnecessary HANDLE typecasts.
[wine/hacks.git] / dlls / msvideo / mciwnd.c
blobfded32419e3b907984dabfa6c3249c5ab965446c
1 /*
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 #include <stdio.h>
21 #include <string.h>
23 #include "winbase.h"
24 #include "windef.h"
25 #include "winnls.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "vfw.h"
29 #include "digitalv.h"
30 #include "commctrl.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mci);
35 typedef struct {
36 DWORD dwStyle;
37 MCIDEVICEID mci;
38 LPSTR lpName;
39 HWND hWnd;
40 UINT uTimer;
41 } MCIWndInfo;
43 static LRESULT WINAPI MCIWndProc(HWND hWnd, UINT wMsg, WPARAM lParam1, LPARAM lParam2);
45 #define CTL_PLAYSTOP 0x3200
46 #define CTL_MENU 0x3201
47 #define CTL_TRACKBAR 0x3202
49 /***********************************************************************
50 * MCIWndRegisterClass [MSVFW32.@]
52 BOOL WINAPI MCIWndRegisterClass(HINSTANCE hInst)
54 WNDCLASSA wc;
56 /* since window creation will also require some common controls, init them */
57 InitCommonControls();
59 wc.style = 0;
60 wc.lpfnWndProc = MCIWndProc;
61 wc.cbClsExtra = 0;
62 wc.cbWndExtra = sizeof(MCIWndInfo*);
63 wc.hInstance = hInst;
64 wc.hIcon = 0;
65 wc.hCursor = 0;
66 wc.hbrBackground = 0;
67 wc.lpszMenuName = NULL;
68 wc.lpszClassName = "MCIWndClass";
70 return RegisterClassA(&wc);
74 /***********************************************************************
75 * MCIWndCreate [MSVFW32.@]
76 * MCIWndCreateA [MSVFW32.@]
78 HWND VFWAPIV MCIWndCreateA(HWND hwndParent, HINSTANCE hInstance,
79 DWORD dwStyle, LPCSTR szFile)
81 DWORD wndStyle;
82 MCIWndInfo* mwi;
84 TRACE("%p %p %lx %s\n", hwndParent, hInstance, dwStyle, szFile);
86 MCIWndRegisterClass(hInstance);
88 mwi = HeapAlloc(GetProcessHeap(), 0, sizeof(*mwi));
89 if (!mwi) return 0;
91 mwi->dwStyle = dwStyle;
92 if (szFile)
93 mwi->lpName = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(szFile) + 1), szFile);
94 else
95 mwi->lpName = NULL;
96 mwi->uTimer = 0;
98 wndStyle = ((hwndParent) ? (WS_CHILD|WS_BORDER) : WS_OVERLAPPEDWINDOW) |
99 WS_VISIBLE | (dwStyle & 0xFFFF0000);
101 if (CreateWindowExA(0, "MCIWndClass", NULL, wndStyle,
102 CW_USEDEFAULT, CW_USEDEFAULT,
103 CW_USEDEFAULT, CW_USEDEFAULT,
104 hwndParent, NULL, hInstance, mwi))
105 return mwi->hWnd;
107 if(mwi->lpName) HeapFree(GetProcessHeap(), 0, mwi->lpName);
108 HeapFree(GetProcessHeap(), 0, mwi);
109 return 0;
112 /***********************************************************************
113 * MCIWndCreateW [MSVFW32.@]
115 HWND VFWAPIV MCIWndCreateW(HWND hwndParent, HINSTANCE hInstance,
116 DWORD dwStyle, LPCWSTR szFile)
118 FIXME("%p %p %lx %s\n", hwndParent, hInstance, dwStyle, debugstr_w(szFile));
120 MCIWndRegisterClass(hInstance);
122 return 0;
125 static DWORD MCIWND_GetStatus(MCIWndInfo* mwi)
127 MCI_DGV_STATUS_PARMSA mdsp;
129 memset(&mdsp, 0, sizeof(mdsp));
130 mdsp.dwItem = MCI_STATUS_MODE;
131 if (mciSendCommandA(mwi->mci, MCI_STATUS, MCI_WAIT|MCI_STATUS_ITEM, (DWORD)&mdsp))
132 return MCI_MODE_NOT_READY;
133 if (mdsp.dwReturn == MCI_MODE_STOP && mwi->uTimer) {
134 TRACE("Killing timer\n");
135 KillTimer(mwi->hWnd, 0);
136 mwi->uTimer = 0;
138 return mdsp.dwReturn;
141 static DWORD MCIWND_Get(MCIWndInfo* mwi, DWORD what)
143 MCI_DGV_STATUS_PARMSA mdsp;
145 memset(&mdsp, 0, sizeof(mdsp));
146 mdsp.dwItem = what;
147 if (mciSendCommandA(mwi->mci, MCI_STATUS, MCI_WAIT|MCI_STATUS_ITEM, (DWORD)&mdsp))
148 return 0;
149 return mdsp.dwReturn;
152 static void MCIWND_SetText(MCIWndInfo* mwi)
154 char buffer[1024];
156 if (mwi->dwStyle & MCIWNDF_SHOWNAME) {
157 strcpy(buffer, mwi->lpName);
158 } else {
159 *buffer = 0;
162 if (mwi->dwStyle & (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE)) {
163 if (*buffer) strcat(buffer, " ");
164 strcat(buffer, "(");
167 if (mwi->dwStyle & MCIWNDF_SHOWPOS) {
168 sprintf(buffer + strlen(buffer), "%ld", MCIWND_Get(mwi, MCI_STATUS_POSITION));
171 if ((mwi->dwStyle & (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE)) == (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE)) {
172 strcat(buffer, " - ");
175 if (mwi->dwStyle & MCIWNDF_SHOWMODE) {
176 switch (MCIWND_GetStatus(mwi)) {
177 case MCI_MODE_NOT_READY: strcat(buffer, "not ready"); break;
178 case MCI_MODE_PAUSE: strcat(buffer, "paused"); break;
179 case MCI_MODE_PLAY: strcat(buffer, "playing"); break;
180 case MCI_MODE_STOP: strcat(buffer, "stopped"); break;
181 case MCI_MODE_OPEN: strcat(buffer, "open"); break;
182 case MCI_MODE_RECORD: strcat(buffer, "recording"); break;
183 case MCI_MODE_SEEK: strcat(buffer, "seeking"); break;
184 default: strcat(buffer, "???"); break;
187 if (mwi->dwStyle & (MCIWNDF_SHOWPOS|MCIWNDF_SHOWMODE)) {
188 strcat(buffer, " )");
190 TRACE("=> '%s'\n", buffer);
191 SetWindowTextA(mwi->hWnd, buffer);
194 static void MCIWND_Create(HWND hWnd, LPCREATESTRUCTA cs)
196 MCI_DGV_OPEN_PARMSA mdopn;
197 MCI_DGV_RECT_PARMS mdrct;
198 MMRESULT mmr;
199 int cx, cy;
200 HWND hChld;
201 MCIWndInfo* mwi = (MCIWndInfo*)cs->lpCreateParams;
203 SetWindowLongA(hWnd, 0, (LPARAM)mwi);
204 mwi->hWnd = hWnd;
206 /* now open MCI player for AVI file */
207 memset(&mdopn, 0, sizeof(mdopn));
208 mdopn.lpstrElementName = mwi->lpName;
209 mdopn.dwStyle = WS_VISIBLE|WS_CHILD;
210 mdopn.hWndParent = hWnd;
212 mmr = mciSendCommandA(0, MCI_OPEN, MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_DGV_OPEN_WS, (LPARAM)&mdopn);
213 if (mmr) {
214 MessageBoxA(GetTopWindow(hWnd), "Cannot open file", "MciWnd", MB_OK);
215 return;
217 mwi->mci = mdopn.wDeviceID;
219 /* grab AVI window size */
220 memset(&mdrct, 0, sizeof(mdrct));
221 mmr = mciSendCommandA(mwi->mci, MCI_WHERE, MCI_DGV_WHERE_DESTINATION, (LPARAM)&mdrct);
222 if (mmr) {
223 WARN("Cannot get window rect\n");
224 return;
226 cx = mdrct.rc.right - mdrct.rc.left;
227 cy = mdrct.rc.bottom - mdrct.rc.top;
229 AdjustWindowRect(&mdrct.rc, GetWindowLongA(hWnd, GWL_STYLE), FALSE);
230 SetWindowPos(hWnd, 0, 0, 0, mdrct.rc.right - mdrct.rc.left,
231 mdrct.rc.bottom - mdrct.rc.top + 32, SWP_NOMOVE|SWP_NOZORDER);
233 /* adding the other elements: play/stop button, menu button, status */
234 hChld = CreateWindowExA(0, "BUTTON", "Play", WS_CHILD|WS_VISIBLE, 0, cy, 32, 32,
235 hWnd, (HMENU)CTL_PLAYSTOP,
236 (HINSTANCE)GetWindowLongA(hWnd, GWL_HINSTANCE), 0L);
237 TRACE("Get Button1: %p\n", hChld);
238 hChld = CreateWindowExA(0, "BUTTON", "Menu", WS_CHILD|WS_VISIBLE, 32, cy, 32, 32,
239 hWnd, (HMENU)CTL_MENU,
240 (HINSTANCE)GetWindowLongA(hWnd, GWL_HINSTANCE), 0L);
241 TRACE("Get Button2: %p\n", hChld);
242 hChld = CreateWindowExA(0, TRACKBAR_CLASSA, "", WS_CHILD|WS_VISIBLE, 64, cy, cx - 64, 32,
243 hWnd, (HMENU)CTL_TRACKBAR,
244 (HINSTANCE)GetWindowLongA(hWnd, GWL_HINSTANCE), 0L);
245 TRACE("Get status: %p\n", hChld);
246 SendMessageA(hChld, TBM_SETRANGEMIN, 0L, 0L);
247 SendMessageA(hChld, TBM_SETRANGEMAX, 1L, MCIWND_Get(mwi, MCI_STATUS_LENGTH));
249 /* FIXME: no need to set it if child window */
250 MCIWND_SetText(mwi);
253 static void MCIWND_Paint(MCIWndInfo* mwi, WPARAM wParam)
255 HDC hdc;
256 PAINTSTRUCT ps;
258 hdc = (wParam) ? (HDC)wParam : BeginPaint(mwi->hWnd, &ps);
259 /* something to do ? */
260 if (!wParam) EndPaint(mwi->hWnd, &ps);
263 static void MCIWND_ToggleState(MCIWndInfo* mwi)
265 MCI_GENERIC_PARMS mgp;
266 MCI_DGV_PLAY_PARMS mdply;
268 memset(&mgp, 0, sizeof(mgp));
269 memset(&mdply, 0, sizeof(mdply));
271 switch (MCIWND_GetStatus(mwi)) {
272 case MCI_MODE_NOT_READY:
273 case MCI_MODE_RECORD:
274 case MCI_MODE_SEEK:
275 case MCI_MODE_OPEN:
276 TRACE("Cannot do much...\n");
277 break;
278 case MCI_MODE_PAUSE:
279 mciSendCommandA(mwi->mci, MCI_RESUME, MCI_WAIT, (LPARAM)&mgp);
280 break;
281 case MCI_MODE_PLAY:
282 mciSendCommandA(mwi->mci, MCI_PAUSE, MCI_WAIT, (LPARAM)&mgp);
283 break;
284 case MCI_MODE_STOP:
285 mdply.dwFrom = 0L;
286 mciSendCommandA(mwi->mci, MCI_PLAY, MCI_FROM, (LPARAM)&mdply);
287 mwi->uTimer = SetTimer(mwi->hWnd, 0, 333, 0L);
288 TRACE("Timer=%u\n", mwi->uTimer);
289 break;
293 static LRESULT MCIWND_Command(MCIWndInfo* mwi, WPARAM wParam, LPARAM lParam)
295 switch (LOWORD(wParam)) {
296 case CTL_PLAYSTOP: MCIWND_ToggleState(mwi); break;
297 case CTL_MENU:
298 case CTL_TRACKBAR:
299 default:
300 MessageBoxA(0, "ooch", "NIY", MB_OK);
302 return 0L;
305 static void MCIWND_Timer(MCIWndInfo* mwi, WPARAM wParam, LPARAM lParam)
307 TRACE("%ld\n", MCIWND_Get(mwi, MCI_STATUS_POSITION));
308 SendDlgItemMessageA(mwi->hWnd, CTL_TRACKBAR, TBM_SETPOS, 1, MCIWND_Get(mwi, MCI_STATUS_POSITION));
309 MCIWND_SetText(mwi);
312 static void MCIWND_Close(MCIWndInfo* mwi)
314 MCI_GENERIC_PARMS mgp;
316 memset(&mgp, 0, sizeof(mgp));
318 mciSendCommandA(mwi->mci, MCI_CLOSE, 0, (LPARAM)&mgp);
321 static LRESULT WINAPI MCIWndProc(HWND hWnd, UINT wMsg, WPARAM lParam1, LPARAM lParam2)
323 MCIWndInfo* mwi = (MCIWndInfo*)GetWindowLongA(hWnd, 0);
325 if (mwi || wMsg == WM_CREATE) {
326 switch (wMsg) {
327 case WM_CREATE:
328 MCIWND_Create(hWnd, (CREATESTRUCTA*)lParam2);
329 return 0;
330 case WM_DESTROY:
331 MCIWND_Close(mwi);
332 HeapFree(GetProcessHeap(), 0, mwi->lpName);
333 HeapFree(GetProcessHeap(), 0, mwi);
334 break;
335 case WM_PAINT:
336 MCIWND_Paint(mwi, lParam1);
337 break;
338 case WM_COMMAND:
339 return MCIWND_Command(mwi, lParam1, lParam2);
340 case WM_TIMER:
341 MCIWND_Timer(mwi, lParam1, lParam2);
342 return TRUE;
346 return DefWindowProcA(hWnd, wMsg, lParam1, lParam2);