Sync to trunk revision 61757.
[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 TRUE;
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 ShowMCIError(hwnd, dwError);
245 return dwError;
246 }
247
248 mciStatus.dwItem = MCI_STATUS_LENGTH;
249
250 dwError = mciSendCommand(mciOpen.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD_PTR)&mciStatus);
251 if (dwError != 0)
252 {
253 ShowMCIError(hwnd, dwError);
254 return dwError;
255 }
256
257 SendMessage(hTrackBar, TBM_SETRANGEMIN, (WPARAM) TRUE, (LPARAM) 1);
258 SendMessage(hTrackBar, TBM_SETRANGEMAX, (WPARAM) TRUE, (LPARAM) mciStatus.dwReturn);
259 SendMessage(hTrackBar, TBM_SETPAGESIZE, 0, 10);
260 SendMessage(hTrackBar, TBM_SETLINESIZE, 0, 1);
261 SendMessage(hTrackBar, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 1);
262
263 if (mciStatus.dwReturn < 10000)
264 {
265 SendMessage(hTrackBar, TBM_SETTICFREQ, (WPARAM) 100, (LPARAM) 0);
266 }
267 else if (mciStatus.dwReturn < 100000)
268 {
269 SendMessage(hTrackBar, TBM_SETTICFREQ, (WPARAM) 1000, (LPARAM) 0);
270 }
271 else if (mciStatus.dwReturn < 1000000)
272 {
273 SendMessage(hTrackBar, TBM_SETTICFREQ, (WPARAM) 10000, (LPARAM) 0);
274 }
275 else
276 {
277 SendMessage(hTrackBar, TBM_SETTICFREQ, (WPARAM) 100000, (LPARAM) 0);
278 }
279
280 _stprintf(szNewTitle, _T("%s - %s"), szAppTitle, lpFileName);
281 SetWindowText(hwnd, szNewTitle);
282
283 MaxFilePos = mciStatus.dwReturn;
284 wDeviceId = mciOpen.wDeviceID;
285 bIsOpened = TRUE;
286 _tcscpy(szPrevFile, lpFileName);
287
288 EnableMenuItems();
289
290 return TRUE;
291 }
292
293 static VOID
294 StopPlayback(HWND hwnd)
295 {
296 if (bIsOpened)
297 {
298 SendMessage(hTrackBar, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 1);
299 KillTimer(hwnd, IDT_PLAYTIMER);
300 CloseMciDevice();
301 }
302 }
303
304 static VOID
305 SeekPlayback(HWND hwnd, DWORD dwNewPos)
306 {
307 MCI_SEEK_PARMS mciSeek;
308 MCI_PLAY_PARMS mciPlay;
309 DWORD dwError;
310
311 if (bIsOpened)
312 {
313 mciSeek.dwTo = (DWORD_PTR)dwNewPos;
314 dwError = mciSendCommand(wDeviceId, MCI_SEEK, MCI_WAIT | MCI_TO, (DWORD_PTR)&mciSeek);
315 if (dwError != 0)
316 {
317 ShowMCIError(hwnd, dwError);
318 }
319
320 mciPlay.dwCallback = (DWORD_PTR)hwnd;
321 dwError = mciSendCommand(wDeviceId, MCI_PLAY, MCI_NOTIFY, (DWORD_PTR)&mciPlay);
322 if (dwError != 0)
323 {
324 ShowMCIError(hwnd, dwError);
325 }
326 }
327 }
328
329 static VOID
330 SeekBackPlayback(HWND hwnd)
331 {
332 MCI_STATUS_PARMS mciStatus;
333 DWORD dwNewPos;
334
335 if (!bIsOpened) return;
336
337 mciStatus.dwItem = MCI_STATUS_POSITION;
338 mciSendCommand(wDeviceId, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&mciStatus);
339
340 dwNewPos = mciStatus.dwReturn - 1;
341
342 if((UINT)dwNewPos <= 1)
343 {
344 StopPlayback(hwnd);
345 }
346 else
347 {
348 SeekPlayback(hwnd, dwNewPos);
349 }
350 }
351
352 static VOID
353 SeekForwPlayback(HWND hwnd)
354 {
355 MCI_STATUS_PARMS mciStatus;
356 DWORD dwNewPos;
357
358 if (!bIsOpened) return;
359
360 mciStatus.dwItem = MCI_STATUS_POSITION;
361 mciSendCommand(wDeviceId, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&mciStatus);
362
363 dwNewPos = mciStatus.dwReturn + 1;
364
365 if((UINT)dwNewPos >= MaxFilePos)
366 {
367 StopPlayback(hwnd);
368 }
369 else
370 {
371 SeekPlayback(hwnd, dwNewPos);
372 }
373 }
374
375 static VOID
376 PausePlayback(HWND hwnd)
377 {
378 MCI_GENERIC_PARMS mciGeneric;
379 DWORD dwError;
380
381 if (bIsOpened)
382 {
383 dwError = mciSendCommand(wDeviceId, MCI_PAUSE, MCI_WAIT, (DWORD_PTR)&mciGeneric);
384 if (dwError != 0)
385 {
386 ShowMCIError(hwnd, dwError);
387 }
388 bIsPaused = TRUE;
389 }
390 }
391
392 static VOID
393 ResumePlayback(HWND hwnd)
394 {
395 MCI_GENERIC_PARMS mciGeneric;
396 DWORD dwError;
397
398 if (bIsPaused)
399 {
400 dwError = mciSendCommand(wDeviceId, MCI_RESUME, MCI_WAIT, (DWORD_PTR)&mciGeneric);
401 if (dwError != 0)
402 {
403 ShowMCIError(hwnd, dwError);
404 }
405 bIsPaused = FALSE;
406 }
407 }
408
409 static VOID
410 ShowDeviceProperties(HWND hwnd)
411 {
412 MCI_GENERIC_PARMS mciGeneric;
413 DWORD dwError;
414
415 dwError = mciSendCommand(wDeviceId, MCI_CONFIGURE, MCI_WAIT, (DWORD_PTR)&mciGeneric);
416 if (dwError != 0)
417 {
418 MessageBox(0, _T("Can't display the device properties!"), NULL, MB_OK);
419 }
420 }
421
422 VOID CALLBACK
423 PlayTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
424 {
425 MCI_STATUS_PARMS mciStatus;
426 DWORD dwPos;
427
428 if (!bIsOpened) KillTimer(hwnd, IDT_PLAYTIMER);
429
430 mciStatus.dwItem = MCI_STATUS_POSITION;
431 mciSendCommand(wDeviceId, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&mciStatus);
432 dwPos = mciStatus.dwReturn;
433
434 if((UINT)dwPos >= MaxFilePos)
435 {
436 StopPlayback(hwnd);
437 }
438 else
439 {
440 SendMessage(hTrackBar, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) dwPos);
441 }
442 }
443
444 static VOID
445 PlayFile(HWND hwnd, LPTSTR lpFileName)
446 {
447 MCI_PLAY_PARMS mciPlay;
448 TCHAR szLocalFileName[MAX_PATH];
449 TCHAR szDeviceName[MAX_PATH];
450 DWORD dwSize;
451 BOOL IsSupported;
452 MCIERROR mciError;
453
454 if (lpFileName == NULL)
455 {
456 if (szPrevFile[0] == _T('\0'))
457 return;
458
459 _tcscpy(szLocalFileName, szPrevFile);
460 }
461 else
462 {
463 _tcscpy(szLocalFileName, lpFileName);
464 }
465
466 if (GetFileAttributes(szLocalFileName) == INVALID_FILE_ATTRIBUTES)
467 {
468 return;
469 }
470
471 dwSize = sizeof(szDeviceName) - 2;
472 _tcsnset(szDeviceName, _T('\0'), dwSize / sizeof(TCHAR));
473 IsSupported = IsSupportedFileExtension(szLocalFileName, szDeviceName, &dwSize);
474
475 if (IsSupported == TRUE)
476 {
477 OpenMciDevice(hwnd, szDeviceName, szLocalFileName);
478 }
479
480 SetTimer(hwnd, IDT_PLAYTIMER, 100, (TIMERPROC) PlayTimerProc);
481
482 mciSendCommand(wDeviceId, MCI_SEEK, MCI_WAIT | MCI_SEEK_TO_START, 0);
483
484 mciPlay.dwCallback = (DWORD_PTR)hwnd;
485 mciPlay.dwFrom = 0;
486 mciPlay.dwTo = MaxFilePos;
487
488 mciError = mciSendCommand(wDeviceId, MCI_PLAY, MCI_NOTIFY | MCI_FROM /*| MCI_TO*/, (DWORD_PTR)&mciPlay);
489 if (mciError != 0)
490 {
491 ShowMCIError(hwnd, mciError);
492 }
493 }
494
495 static VOID
496 OpenFileDialog(HWND hwnd)
497 {
498 OPENFILENAME OpenFileName;
499 TCHAR szFile[MAX_PATH + 1] = _T("\0");
500 TCHAR szFilter[MAX_PATH], szCurrentDir[MAX_PATH];
501
502 ZeroMemory(&OpenFileName, sizeof(OpenFileName));
503
504 LoadString(hInstance, IDS_ALL_TYPES_FILTER, szFilter, sizeof(szFilter) / sizeof(TCHAR));
505
506 if (!GetCurrentDirectory(sizeof(szCurrentDir) / sizeof(TCHAR), szCurrentDir))
507 {
508 _tcscpy(szCurrentDir, _T("c:\\"));
509 }
510
511 OpenFileName.lStructSize = sizeof(OpenFileName);
512 OpenFileName.hwndOwner = hwnd;
513 OpenFileName.hInstance = hInstance;
514 OpenFileName.lpstrFilter = szFilter;
515 OpenFileName.lpstrFile = szFile;
516 OpenFileName.nMaxFile = sizeof(szFile) / sizeof((szFile)[0]);
517 OpenFileName.lpstrInitialDir = szCurrentDir;
518 OpenFileName.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_SHAREAWARE;
519 OpenFileName.lpstrDefExt = _T("\0");
520
521 if (GetOpenFileName(&OpenFileName))
522 {
523 PlayFile(hwnd, OpenFileName.lpstrFile);
524 }
525 }
526
527 LRESULT CALLBACK
528 MainWndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
529 {
530 switch (Message)
531 {
532 case WM_CREATE:
533 InitControls(hwnd);
534 hMainMenu = GetMenu(hwnd);
535 break;
536
537 case WM_DROPFILES:
538 {
539 HDROP drophandle;
540 TCHAR droppedfile[MAX_PATH];
541
542 drophandle = (HDROP)wParam;
543 DragQueryFile(drophandle, 0, droppedfile, sizeof(droppedfile));
544 DragFinish(drophandle);
545 PlayFile(hwnd, droppedfile);
546 break;
547 }
548
549 case WM_NOTIFY:
550 {
551 LPNMHDR pnmhdr = (LPNMHDR)lParam;
552
553 switch (pnmhdr->code)
554 {
555 case TTN_GETDISPINFO:
556 {
557 LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT)lParam;
558 UINT idButton = (UINT)lpttt->hdr.idFrom;
559
560 switch (idButton)
561 {
562 case IDC_PLAY:
563 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PLAY);
564 break;
565 case IDC_STOP:
566 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_STOP);
567 break;
568 case IDC_EJECT:
569 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EJECT);
570 break;
571 case IDC_BACKWARD:
572 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_BACKWARD);
573 break;
574 case IDC_SEEKBACK:
575 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_SEEKBACK);
576 break;
577 case IDC_SEEKFORW:
578 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_SEEKFORW);
579 break;
580 case IDC_FORWARD:
581 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_FORWARD);
582 break;
583 }
584 break;
585 }
586 }
587 }
588 break;
589
590 case WM_SIZING:
591 {
592 LPRECT pRect = (LPRECT)lParam;
593
594 if (pRect->right - pRect->left < MAIN_WINDOW_MIN_WIDTH)
595 pRect->right = pRect->left + MAIN_WINDOW_MIN_WIDTH;
596
597 if (pRect->bottom - pRect->top != MAIN_WINDOW_HEIGHT)
598 pRect->bottom = pRect->top + MAIN_WINDOW_HEIGHT;
599
600 return TRUE;
601 }
602
603 case WM_SIZE:
604 {
605 RECT Rect;
606 UINT Size;
607
608 if (hToolBar && hTrackBar)
609 {
610 SendMessage(hToolBar, TB_AUTOSIZE, 0, 0);
611 SendMessage(hToolBar, TB_GETITEMRECT, 1, (LPARAM)&Rect);
612
613 Size = GetSystemMetrics(SM_CYMENU) + Rect.bottom;
614 MoveWindow(hTrackBar, 0, 0, LOWORD(lParam), HIWORD(lParam) - Size, TRUE);
615 }
616 return 0L;
617 }
618
619 case WM_HSCROLL:
620 {
621 if (hTrackBar == (HWND) lParam)
622 {
623 if (bIsOpened)
624 {
625 DWORD dwNewPos = (DWORD) SendMessage(hTrackBar, TBM_GETPOS, 0, 0);
626 SeekPlayback(hwnd, dwNewPos);
627 }
628 else
629 {
630 SendMessage(hTrackBar, TBM_SETPOS, TRUE, 0);
631 }
632 }
633 }
634 break;
635
636 case WM_COMMAND:
637 switch (LOWORD(wParam))
638 {
639 case IDC_PLAY:
640 if (bIsOpened)
641 {
642 if (bIsPaused)
643 ResumePlayback(hwnd);
644 else
645 PausePlayback(hwnd);
646 }
647 else
648 {
649 if (szPrevFile[0] == _T('\0'))
650 OpenFileDialog(hwnd);
651 else
652 PlayFile(hwnd, NULL);
653 }
654 break;
655
656 case IDC_STOP:
657 StopPlayback(hwnd);
658 break;
659
660 case IDC_EJECT:
661 break;
662
663 case IDC_BACKWARD:
664 break;
665
666 case IDC_SEEKBACK:
667 SeekBackPlayback(hwnd);
668 break;
669
670 case IDC_SEEKFORW:
671 SeekForwPlayback(hwnd);
672 break;
673
674 case IDC_FORWARD:
675 break;
676
677 case IDM_OPEN_FILE:
678 OpenFileDialog(hwnd);
679 return 0;
680
681 case IDM_CLOSE_FILE:
682 StopPlayback(hwnd);
683 _tcscpy(szPrevFile, _T("\0"));
684 break;
685
686 case IDM_DEVPROPS:
687 ShowDeviceProperties(hwnd);
688 break;
689
690 case IDM_VOLUMECTL:
691 ShellExecute(hwnd, NULL, _T("SNDVOL32.EXE"), NULL, NULL, SW_SHOWNORMAL);
692 break;
693
694 case IDM_ABOUT:
695 {
696 HICON mplayIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAIN));
697 ShellAbout(hwnd, szAppTitle, 0, mplayIcon);
698 DeleteObject(mplayIcon);
699 break;
700 }
701 case IDM_EXIT:
702 PostMessage(hwnd, WM_CLOSE, 0, 0);
703 return 0;
704 }
705 break;
706
707 case WM_DESTROY:
708 StopPlayback(hwnd);
709 PostQuitMessage(0);
710 return 0;
711 }
712
713 return DefWindowProc(hwnd, Message, wParam, lParam);
714 }
715
716 INT WINAPI
717 _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow)
718 {
719 WNDCLASSEX WndClass = {0};
720 TCHAR szClassName[] = _T("ROSMPLAY32");
721 HWND hwnd;
722 MSG msg;
723 DWORD dwError;
724
725 hInstance = hInst;
726
727 LoadString(hInstance, IDS_APPTITLE, szAppTitle, sizeof(szAppTitle) / sizeof(TCHAR));
728
729 WndClass.cbSize = sizeof(WNDCLASSEX);
730 WndClass.lpszClassName = szClassName;
731 WndClass.lpfnWndProc = MainWndProc;
732 WndClass.hInstance = hInstance;
733 WndClass.style = CS_HREDRAW | CS_VREDRAW;
734 WndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAIN));
735 WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
736 WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
737 WndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
738
739 RegisterClassEx(&WndClass);
740
741 hwnd = CreateWindow(szClassName,
742 szAppTitle,
743 WS_SYSMENU | WS_MINIMIZEBOX | WS_THICKFRAME | WS_OVERLAPPED | WS_CAPTION | WS_CLIPCHILDREN,
744 CW_USEDEFAULT,
745 CW_USEDEFAULT,
746 350,
747 MAIN_WINDOW_HEIGHT,
748 NULL,
749 NULL,
750 hInstance,
751 NULL);
752
753 DragAcceptFiles(hwnd, TRUE);
754
755 DisableMenuItems();
756
757 dwError = SearchPath(NULL, _T("SNDVOL32.EXE"), NULL, 0, NULL, NULL);
758 if (dwError == 0)
759 {
760 EnableMenuItem(hMainMenu, IDM_VOLUMECTL, MF_BYCOMMAND | MF_GRAYED);
761 }
762
763 /* Show it */
764 ShowWindow(hwnd, SW_SHOW);
765 UpdateWindow(hwnd);
766
767 PlayFile(hwnd, lpCmdLine);
768
769 /* Message Loop */
770 while (GetMessage(&msg, NULL, 0, 0))
771 {
772 TranslateMessage(&msg);
773 DispatchMessage(&msg);
774 }
775
776 return 0;
777 }