* Sync up to trunk HEAD (r62286).
[reactos.git] / base / applications / mplay32 / mplay32.c
1 /*
2 * PROJECT: ReactOS Multimedia Player
3 * FILE: base\applications\mplay32\mplay32.c
4 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
5 */
6
7 #include "mplay32.h"
8
9 #define MAIN_WINDOW_HEIGHT 125
10 #define MAIN_WINDOW_MIN_WIDTH 250
11
12 HINSTANCE hInstance = NULL;
13 HWND hTrackBar = NULL;
14 HWND hToolBar = NULL;
15 HMENU hMainMenu = NULL;
16 TCHAR szAppTitle[256] = _T("");
17 TCHAR szPrevFile[MAX_PATH] = _T("\0");
18 WORD wDeviceId;
19 BOOL bIsOpened = FALSE;
20 BOOL bIsPaused = FALSE;
21 UINT MaxFilePos = 0;
22
23
24 /* ToolBar Buttons */
25 static const TBBUTTON Buttons[] =
26 { /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
27 {TBICON_PLAY, IDC_PLAY, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
28 {TBICON_STOP, IDC_STOP, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
29 {TBICON_EJECT, IDC_EJECT, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
30 {15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0},
31 {TBICON_BACKWARD, IDC_BACKWARD, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
32 {TBICON_SEEKBACK, IDC_SEEKBACK, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
33 {TBICON_SEEKFORW, IDC_SEEKFORW, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
34 {TBICON_FORWARD, IDC_FORWARD, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}
35 };
36
37 void EnableMenuItems(void)
38 {
39 MCI_GENERIC_PARMS mciGeneric;
40 DWORD dwError;
41
42 EnableMenuItem(hMainMenu, IDM_CLOSE_FILE, MF_BYCOMMAND | MF_ENABLED);
43
44 dwError = mciSendCommand(wDeviceId, MCI_CONFIGURE, MCI_TEST, (DWORD_PTR)&mciGeneric);
45 if (dwError == 0)
46 {
47 EnableMenuItem(hMainMenu, IDM_DEVPROPS, MF_BYCOMMAND | MF_ENABLED);
48 }
49 }
50
51 void DisableMenuItems(void)
52 {
53 EnableMenuItem(hMainMenu, IDM_CLOSE_FILE, MF_BYCOMMAND | MF_GRAYED);
54 EnableMenuItem(hMainMenu, IDM_DEVPROPS, MF_BYCOMMAND | MF_GRAYED);
55 }
56
57 static VOID
58 SetImageList(HWND hwnd)
59 {
60 HIMAGELIST hImageList;
61
62 hImageList = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR24, 1, 1);
63
64 if (!hImageList)
65 {
66 MessageBox(hwnd, _T("ImageList it is not created!"), NULL, MB_OK);
67 return;
68 }
69
70 ImageList_AddMasked(hImageList,
71 LoadImage(hInstance, MAKEINTRESOURCE(IDB_PLAYICON), IMAGE_BITMAP, 16, 16, LR_DEFAULTCOLOR),
72 RGB(255, 255, 255));
73
74 ImageList_AddMasked(hImageList,
75 LoadImage(hInstance, MAKEINTRESOURCE(IDB_STOPICON), IMAGE_BITMAP, 16, 16, LR_DEFAULTCOLOR),
76 RGB(255, 255, 255));
77
78 ImageList_AddMasked(hImageList,
79 LoadImage(hInstance, MAKEINTRESOURCE(IDB_EJECTICON), IMAGE_BITMAP, 16, 16, LR_DEFAULTCOLOR),
80 RGB(255, 255, 255));
81
82 ImageList_AddMasked(hImageList,
83 LoadImage(hInstance, MAKEINTRESOURCE(IDB_BACKWARDICON), IMAGE_BITMAP, 16, 16, LR_DEFAULTCOLOR),
84 RGB(255, 255, 255));
85
86 ImageList_AddMasked(hImageList,
87 LoadImage(hInstance, MAKEINTRESOURCE(IDB_SEEKBACKICON), IMAGE_BITMAP, 16, 16, LR_DEFAULTCOLOR),
88 RGB(255, 255, 255));
89
90 ImageList_AddMasked(hImageList,
91 LoadImage(hInstance, MAKEINTRESOURCE(IDB_SEEKFORWICON), IMAGE_BITMAP, 16, 16, LR_DEFAULTCOLOR),
92 RGB(255, 255, 255));
93
94 ImageList_AddMasked(hImageList,
95 LoadImage(hInstance, MAKEINTRESOURCE(IDB_FORWARDICON), IMAGE_BITMAP, 16, 16, LR_DEFAULTCOLOR),
96 RGB(255, 255, 255));
97
98 ImageList_Destroy((HIMAGELIST)SendMessage(hToolBar,
99 TB_SETIMAGELIST,
100 0,
101 (LPARAM)hImageList));
102 }
103
104 static VOID
105 ShowMCIError(HWND hwnd, DWORD dwError)
106 {
107 TCHAR szErrorMessage[256];
108 TCHAR szTempMessage[300];
109
110 if (mciGetErrorString(dwError, szErrorMessage, sizeof(szErrorMessage) / sizeof(TCHAR)) == FALSE)
111 {
112 LoadString(hInstance, IDS_DEFAULTMCIERRMSG, szErrorMessage, sizeof(szErrorMessage) / sizeof(TCHAR));
113 }
114
115 _stprintf(szTempMessage, _T("MMSYS%u: %s"), dwError, szErrorMessage);
116 MessageBox(hwnd, szTempMessage, szAppTitle, MB_OK | MB_ICONEXCLAMATION);
117 }
118
119 static VOID
120 InitControls(HWND hwnd)
121 {
122 INT NumButtons = sizeof(Buttons) / sizeof(Buttons[0]);
123
124 InitCommonControls();
125
126 /* Create trackbar */
127 hTrackBar = CreateWindowEx(0,
128 TRACKBAR_CLASS,
129 NULL,
130 TBS_ENABLESELRANGE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS,
131 0,
132 0,
133 340,
134 20,
135 hwnd,
136 NULL,
137 hInstance,
138 NULL);
139 if (!hTrackBar)
140 {
141 MessageBox(hwnd, _T("TrackBar it is not created!"), NULL, MB_OK);
142 return;
143 }
144
145 /* Create toolbar */
146 hToolBar = CreateWindowEx(0,
147 TOOLBARCLASSNAME,
148 NULL,
149 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS |
150 TBSTYLE_FLAT | CCS_BOTTOM | TBSTYLE_TOOLTIPS,
151 0,
152 40,
153 340,
154 30,
155 hwnd,
156 NULL,
157 hInstance,
158 NULL);
159 if (!hToolBar)
160 {
161 MessageBox(hwnd, _T("ToolBar it is not created!"), NULL, MB_OK);
162 return;
163 }
164
165 SetImageList(hwnd);
166 SendMessage(hToolBar, TB_ADDBUTTONS, NumButtons, (LPARAM)Buttons);
167 }
168
169 static BOOL
170 IsSupportedFileExtension(LPTSTR lpFileName, LPTSTR lpDeviceName, LPDWORD dwSize)
171 {
172 HKEY hKey;
173 DWORD dwType;
174 TCHAR *pathend;
175
176 pathend = _tcsrchr(lpFileName, '.');
177
178 if (pathend == NULL)
179 {
180 return FALSE;
181 }
182
183 pathend++;
184
185 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\MCI Extensions"), 0, KEY_READ, &hKey) == ERROR_SUCCESS)
186 {
187 if (RegQueryValueEx(hKey, pathend, NULL, &dwType, (LPBYTE)lpDeviceName, dwSize) == ERROR_SUCCESS)
188 {
189 RegCloseKey(hKey);
190 if (dwType != REG_SZ)
191 {
192 return FALSE;
193 }
194
195 return TRUE;
196 }
197
198 RegCloseKey(hKey);
199 }
200
201 return FALSE;
202 }
203
204 static DWORD
205 CloseMciDevice(VOID)
206 {
207 MCI_GENERIC_PARMS mciGeneric;
208 DWORD dwError;
209
210 if (bIsOpened)
211 {
212 dwError = mciSendCommand(wDeviceId, MCI_CLOSE, MCI_WAIT, (DWORD_PTR)&mciGeneric);
213 if (dwError) return dwError;
214 bIsOpened = FALSE;
215 }
216
217 DisableMenuItems();
218
219 return 0;
220 }
221
222 static DWORD
223 OpenMciDevice(HWND hwnd, LPTSTR lpType, LPTSTR lpFileName)
224 {
225 MCI_STATUS_PARMS mciStatus;
226 MCI_OPEN_PARMS mciOpen;
227 TCHAR szNewTitle[MAX_PATH];
228 DWORD dwError;
229
230 if (bIsOpened)
231 {
232 CloseMciDevice();
233 }
234
235 mciOpen.lpstrDeviceType = lpType;
236 mciOpen.lpstrElementName = lpFileName;
237 mciOpen.dwCallback = 0;
238 mciOpen.wDeviceID = 0;
239 mciOpen.lpstrAlias = NULL;
240
241 dwError = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT | MCI_WAIT, (DWORD_PTR)&mciOpen);
242 if (dwError != 0)
243 {
244 return dwError;
245 }
246
247 mciStatus.dwItem = MCI_STATUS_LENGTH;
248
249 dwError = mciSendCommand(mciOpen.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR)&mciStatus);
250 if (dwError != 0)
251 {
252 return dwError;
253 }
254
255 SendMessage(hTrackBar, TBM_SETRANGEMIN, (WPARAM) TRUE, (LPARAM) 1);
256 SendMessage(hTrackBar, TBM_SETRANGEMAX, (WPARAM) TRUE, (LPARAM) mciStatus.dwReturn);
257 SendMessage(hTrackBar, TBM_SETPAGESIZE, 0, 10);
258 SendMessage(hTrackBar, TBM_SETLINESIZE, 0, 1);
259 SendMessage(hTrackBar, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 1);
260
261 if (mciStatus.dwReturn < 10000)
262 {
263 SendMessage(hTrackBar, TBM_SETTICFREQ, (WPARAM) 100, (LPARAM) 0);
264 }
265 else if (mciStatus.dwReturn < 100000)
266 {
267 SendMessage(hTrackBar, TBM_SETTICFREQ, (WPARAM) 1000, (LPARAM) 0);
268 }
269 else if (mciStatus.dwReturn < 1000000)
270 {
271 SendMessage(hTrackBar, TBM_SETTICFREQ, (WPARAM) 10000, (LPARAM) 0);
272 }
273 else
274 {
275 SendMessage(hTrackBar, TBM_SETTICFREQ, (WPARAM) 100000, (LPARAM) 0);
276 }
277
278 _stprintf(szNewTitle, _T("%s - %s"), szAppTitle, lpFileName);
279 SetWindowText(hwnd, szNewTitle);
280
281 MaxFilePos = mciStatus.dwReturn;
282 wDeviceId = mciOpen.wDeviceID;
283 bIsOpened = TRUE;
284 _tcscpy(szPrevFile, lpFileName);
285
286 EnableMenuItems();
287
288 return 0;
289 }
290
291 static VOID
292 StopPlayback(HWND hwnd)
293 {
294 if (bIsOpened)
295 {
296 SendMessage(hTrackBar, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 1);
297 KillTimer(hwnd, IDT_PLAYTIMER);
298 CloseMciDevice();
299 }
300 }
301
302 static VOID
303 SeekPlayback(HWND hwnd, DWORD dwNewPos)
304 {
305 MCI_SEEK_PARMS mciSeek;
306 MCI_PLAY_PARMS mciPlay;
307 DWORD dwError;
308
309 if (bIsOpened)
310 {
311 mciSeek.dwTo = (DWORD_PTR)dwNewPos;
312 dwError = mciSendCommand(wDeviceId, MCI_SEEK, MCI_WAIT | MCI_TO, (DWORD_PTR)&mciSeek);
313 if (dwError != 0)
314 {
315 ShowMCIError(hwnd, dwError);
316 }
317
318 mciPlay.dwCallback = (DWORD_PTR)hwnd;
319 dwError = mciSendCommand(wDeviceId, MCI_PLAY, MCI_NOTIFY, (DWORD_PTR)&mciPlay);
320 if (dwError != 0)
321 {
322 ShowMCIError(hwnd, dwError);
323 }
324 }
325 }
326
327 static VOID
328 SeekBackPlayback(HWND hwnd)
329 {
330 MCI_STATUS_PARMS mciStatus;
331 DWORD dwNewPos;
332
333 if (!bIsOpened) return;
334
335 mciStatus.dwItem = MCI_STATUS_POSITION;
336 mciSendCommand(wDeviceId, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&mciStatus);
337
338 dwNewPos = mciStatus.dwReturn - 1;
339
340 if((UINT)dwNewPos <= 1)
341 {
342 StopPlayback(hwnd);
343 }
344 else
345 {
346 SeekPlayback(hwnd, dwNewPos);
347 }
348 }
349
350 static VOID
351 SeekForwPlayback(HWND hwnd)
352 {
353 MCI_STATUS_PARMS mciStatus;
354 DWORD dwNewPos;
355
356 if (!bIsOpened) return;
357
358 mciStatus.dwItem = MCI_STATUS_POSITION;
359 mciSendCommand(wDeviceId, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&mciStatus);
360
361 dwNewPos = mciStatus.dwReturn + 1;
362
363 if((UINT)dwNewPos >= MaxFilePos)
364 {
365 StopPlayback(hwnd);
366 }
367 else
368 {
369 SeekPlayback(hwnd, dwNewPos);
370 }
371 }
372
373 static VOID
374 PausePlayback(HWND hwnd)
375 {
376 MCI_GENERIC_PARMS mciGeneric;
377 DWORD dwError;
378
379 if (bIsOpened)
380 {
381 dwError = mciSendCommand(wDeviceId, MCI_PAUSE, MCI_WAIT, (DWORD_PTR)&mciGeneric);
382 if (dwError != 0)
383 {
384 ShowMCIError(hwnd, dwError);
385 }
386 bIsPaused = TRUE;
387 }
388 }
389
390 static VOID
391 ResumePlayback(HWND hwnd)
392 {
393 MCI_GENERIC_PARMS mciGeneric;
394 DWORD dwError;
395
396 if (bIsPaused)
397 {
398 dwError = mciSendCommand(wDeviceId, MCI_RESUME, MCI_WAIT, (DWORD_PTR)&mciGeneric);
399 if (dwError != 0)
400 {
401 ShowMCIError(hwnd, dwError);
402 }
403 bIsPaused = FALSE;
404 }
405 }
406
407 static VOID
408 ShowDeviceProperties(HWND hwnd)
409 {
410 MCI_GENERIC_PARMS mciGeneric;
411 DWORD dwError;
412
413 dwError = mciSendCommand(wDeviceId, MCI_CONFIGURE, MCI_WAIT, (DWORD_PTR)&mciGeneric);
414 if (dwError != 0)
415 {
416 ShowMCIError(hwnd, dwError);
417 }
418 }
419
420 VOID CALLBACK
421 PlayTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
422 {
423 MCI_STATUS_PARMS mciStatus;
424 DWORD dwPos;
425
426 if (!bIsOpened) KillTimer(hwnd, IDT_PLAYTIMER);
427
428 mciStatus.dwItem = MCI_STATUS_POSITION;
429 mciSendCommand(wDeviceId, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&mciStatus);
430 dwPos = mciStatus.dwReturn;
431
432 if((UINT)dwPos >= MaxFilePos)
433 {
434 StopPlayback(hwnd);
435 }
436 else
437 {
438 SendMessage(hTrackBar, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) dwPos);
439 }
440 }
441
442 static VOID
443 PlayFile(HWND hwnd, LPTSTR lpFileName)
444 {
445 MCI_PLAY_PARMS mciPlay;
446 TCHAR szLocalFileName[MAX_PATH];
447 TCHAR szDeviceName[MAX_PATH];
448 DWORD dwSize;
449 MCIERROR mciError;
450
451 if (lpFileName == NULL)
452 {
453 if (szPrevFile[0] == _T('\0'))
454 return;
455
456 _tcscpy(szLocalFileName, szPrevFile);
457 }
458 else
459 {
460 _tcscpy(szLocalFileName, lpFileName);
461 }
462
463 if (GetFileAttributes(szLocalFileName) == INVALID_FILE_ATTRIBUTES)
464 {
465 return;
466 }
467
468 dwSize = sizeof(szDeviceName) - 2;
469 _tcsnset(szDeviceName, _T('\0'), dwSize / sizeof(TCHAR));
470
471 if (!IsSupportedFileExtension(szLocalFileName, szDeviceName, &dwSize))
472 {
473 TCHAR szErrorMessage[256];
474
475 LoadString(hInstance, IDS_UNKNOWNFILEEXT, szErrorMessage, sizeof(szErrorMessage) / sizeof(TCHAR));
476 MessageBox(hwnd, szErrorMessage, szAppTitle, MB_OK | MB_ICONEXCLAMATION);
477 return;
478 }
479
480 mciError = OpenMciDevice(hwnd, szDeviceName, szLocalFileName);
481 if (mciError != 0)
482 {
483 ShowMCIError(hwnd, mciError);
484 return;
485 }
486
487 SetTimer(hwnd, IDT_PLAYTIMER, 100, (TIMERPROC) PlayTimerProc);
488
489 mciSendCommand(wDeviceId, MCI_SEEK, MCI_WAIT | MCI_SEEK_TO_START, 0);
490
491 mciPlay.dwCallback = (DWORD_PTR)hwnd;
492 mciPlay.dwFrom = 0;
493 mciPlay.dwTo = MaxFilePos;
494
495 mciError = mciSendCommand(wDeviceId, MCI_PLAY, MCI_NOTIFY | MCI_FROM /*| MCI_TO*/, (DWORD_PTR)&mciPlay);
496 if (mciError != 0)
497 {
498 ShowMCIError(hwnd, mciError);
499 }
500 }
501
502 static VOID
503 OpenFileDialog(HWND hwnd)
504 {
505 OPENFILENAME OpenFileName;
506 TCHAR szFile[MAX_PATH + 1] = _T("\0");
507 TCHAR szFilter[MAX_PATH], szCurrentDir[MAX_PATH];
508
509 ZeroMemory(&OpenFileName, sizeof(OpenFileName));
510
511 LoadString(hInstance, IDS_ALL_TYPES_FILTER, szFilter, sizeof(szFilter) / sizeof(TCHAR));
512
513 if (!GetCurrentDirectory(sizeof(szCurrentDir) / sizeof(TCHAR), szCurrentDir))
514 {
515 _tcscpy(szCurrentDir, _T("c:\\"));
516 }
517
518 OpenFileName.lStructSize = sizeof(OpenFileName);
519 OpenFileName.hwndOwner = hwnd;
520 OpenFileName.hInstance = hInstance;
521 OpenFileName.lpstrFilter = szFilter;
522 OpenFileName.lpstrFile = szFile;
523 OpenFileName.nMaxFile = sizeof(szFile) / sizeof((szFile)[0]);
524 OpenFileName.lpstrInitialDir = szCurrentDir;
525 OpenFileName.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_SHAREAWARE;
526 OpenFileName.lpstrDefExt = _T("\0");
527
528 if (GetOpenFileName(&OpenFileName))
529 {
530 PlayFile(hwnd, OpenFileName.lpstrFile);
531 }
532 }
533
534 LRESULT CALLBACK
535 MainWndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
536 {
537 switch (Message)
538 {
539 case WM_CREATE:
540 InitControls(hwnd);
541 hMainMenu = GetMenu(hwnd);
542 break;
543
544 case WM_DROPFILES:
545 {
546 HDROP drophandle;
547 TCHAR droppedfile[MAX_PATH];
548
549 drophandle = (HDROP)wParam;
550 DragQueryFile(drophandle, 0, droppedfile, sizeof(droppedfile) / sizeof(TCHAR));
551 DragFinish(drophandle);
552 PlayFile(hwnd, droppedfile);
553 break;
554 }
555
556 case WM_NOTIFY:
557 {
558 LPNMHDR pnmhdr = (LPNMHDR)lParam;
559
560 switch (pnmhdr->code)
561 {
562 case TTN_GETDISPINFO:
563 {
564 LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT)lParam;
565 UINT idButton = (UINT)lpttt->hdr.idFrom;
566
567 switch (idButton)
568 {
569 case IDC_PLAY:
570 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PLAY);
571 break;
572 case IDC_STOP:
573 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_STOP);
574 break;
575 case IDC_EJECT:
576 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EJECT);
577 break;
578 case IDC_BACKWARD:
579 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_BACKWARD);
580 break;
581 case IDC_SEEKBACK:
582 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_SEEKBACK);
583 break;
584 case IDC_SEEKFORW:
585 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_SEEKFORW);
586 break;
587 case IDC_FORWARD:
588 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_FORWARD);
589 break;
590 }
591 break;
592 }
593 }
594 }
595 break;
596
597 case WM_SIZING:
598 {
599 LPRECT pRect = (LPRECT)lParam;
600
601 if (pRect->right - pRect->left < MAIN_WINDOW_MIN_WIDTH)
602 pRect->right = pRect->left + MAIN_WINDOW_MIN_WIDTH;
603
604 if (pRect->bottom - pRect->top != MAIN_WINDOW_HEIGHT)
605 pRect->bottom = pRect->top + MAIN_WINDOW_HEIGHT;
606
607 return TRUE;
608 }
609
610 case WM_SIZE:
611 {
612 RECT Rect;
613 UINT Size;
614
615 if (hToolBar && hTrackBar)
616 {
617 SendMessage(hToolBar, TB_AUTOSIZE, 0, 0);
618 SendMessage(hToolBar, TB_GETITEMRECT, 1, (LPARAM)&Rect);
619
620 Size = GetSystemMetrics(SM_CYMENU) + Rect.bottom;
621 MoveWindow(hTrackBar, 0, 0, LOWORD(lParam), HIWORD(lParam) - Size, TRUE);
622 }
623 return 0L;
624 }
625
626 case WM_HSCROLL:
627 {
628 if (hTrackBar == (HWND) lParam)
629 {
630 if (bIsOpened)
631 {
632 DWORD dwNewPos = (DWORD) SendMessage(hTrackBar, TBM_GETPOS, 0, 0);
633 SeekPlayback(hwnd, dwNewPos);
634 }
635 else
636 {
637 SendMessage(hTrackBar, TBM_SETPOS, TRUE, 0);
638 }
639 }
640 }
641 break;
642
643 case WM_COMMAND:
644 switch (LOWORD(wParam))
645 {
646 case IDC_PLAY:
647 if (bIsOpened)
648 {
649 if (bIsPaused)
650 ResumePlayback(hwnd);
651 else
652 PausePlayback(hwnd);
653 }
654 else
655 {
656 if (szPrevFile[0] == _T('\0'))
657 OpenFileDialog(hwnd);
658 else
659 PlayFile(hwnd, NULL);
660 }
661 break;
662
663 case IDC_STOP:
664 StopPlayback(hwnd);
665 break;
666
667 case IDC_EJECT:
668 break;
669
670 case IDC_BACKWARD:
671 break;
672
673 case IDC_SEEKBACK:
674 SeekBackPlayback(hwnd);
675 break;
676
677 case IDC_SEEKFORW:
678 SeekForwPlayback(hwnd);
679 break;
680
681 case IDC_FORWARD:
682 break;
683
684 case IDM_OPEN_FILE:
685 OpenFileDialog(hwnd);
686 return 0;
687
688 case IDM_CLOSE_FILE:
689 StopPlayback(hwnd);
690 _tcscpy(szPrevFile, _T("\0"));
691 break;
692
693 case IDM_DEVPROPS:
694 ShowDeviceProperties(hwnd);
695 break;
696
697 case IDM_VOLUMECTL:
698 ShellExecute(hwnd, NULL, _T("SNDVOL32.EXE"), NULL, NULL, SW_SHOWNORMAL);
699 break;
700
701 case IDM_ABOUT:
702 {
703 HICON mplayIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAIN));
704 ShellAbout(hwnd, szAppTitle, 0, mplayIcon);
705 DeleteObject(mplayIcon);
706 break;
707 }
708 case IDM_EXIT:
709 PostMessage(hwnd, WM_CLOSE, 0, 0);
710 return 0;
711 }
712 break;
713
714 case WM_DESTROY:
715 StopPlayback(hwnd);
716 PostQuitMessage(0);
717 return 0;
718 }
719
720 return DefWindowProc(hwnd, Message, wParam, lParam);
721 }
722
723 INT WINAPI
724 _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow)
725 {
726 WNDCLASSEX WndClass = {0};
727 TCHAR szClassName[] = _T("ROSMPLAY32");
728 HWND hwnd;
729 MSG msg;
730 DWORD dwError;
731
732 hInstance = hInst;
733
734 LoadString(hInstance, IDS_APPTITLE, szAppTitle, sizeof(szAppTitle) / sizeof(TCHAR));
735
736 WndClass.cbSize = sizeof(WNDCLASSEX);
737 WndClass.lpszClassName = szClassName;
738 WndClass.lpfnWndProc = MainWndProc;
739 WndClass.hInstance = hInstance;
740 WndClass.style = CS_HREDRAW | CS_VREDRAW;
741 WndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAIN));
742 WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
743 WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
744 WndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
745
746 RegisterClassEx(&WndClass);
747
748 hwnd = CreateWindow(szClassName,
749 szAppTitle,
750 WS_SYSMENU | WS_MINIMIZEBOX | WS_THICKFRAME | WS_OVERLAPPED | WS_CAPTION | WS_CLIPCHILDREN,
751 CW_USEDEFAULT,
752 CW_USEDEFAULT,
753 350,
754 MAIN_WINDOW_HEIGHT,
755 NULL,
756 NULL,
757 hInstance,
758 NULL);
759
760 DragAcceptFiles(hwnd, TRUE);
761
762 DisableMenuItems();
763
764 dwError = SearchPath(NULL, _T("SNDVOL32.EXE"), NULL, 0, NULL, NULL);
765 if (dwError == 0)
766 {
767 EnableMenuItem(hMainMenu, IDM_VOLUMECTL, MF_BYCOMMAND | MF_GRAYED);
768 }
769
770 /* Show it */
771 ShowWindow(hwnd, SW_SHOW);
772 UpdateWindow(hwnd);
773
774 PlayFile(hwnd, lpCmdLine);
775
776 /* Message Loop */
777 while (GetMessage(&msg, NULL, 0, 0))
778 {
779 TranslateMessage(&msg);
780 DispatchMessage(&msg);
781 }
782
783 return 0;
784 }