Author: hbelusca
Date: Mon Mar 16 20:37:53 2015
New Revision: 66744
URL:
http://svn.reactos.org/svn/reactos?rev=66744&view=rev
Log:
[MPLAY32]: Some improvements to TogglePlaybackState(). By Ricardo Hanke.
CORE-9378 #resolve #comment Committed, thanks!
Modified:
trunk/reactos/base/applications/mplay32/mplay32.c
Modified: trunk/reactos/base/applications/mplay32/mplay32.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mplay32/…
==============================================================================
--- trunk/reactos/base/applications/mplay32/mplay32.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mplay32/mplay32.c [iso-8859-1] Mon Mar 16 20:37:53
2015
@@ -26,7 +26,6 @@
BOOL bIsSingleWindow = FALSE;
UINT MaxFilePos = 0;
RECT PrevWindowPos;
-
/* ToolBar Buttons */
static const TBBUTTON Buttons[] =
@@ -552,31 +551,110 @@
}
}
+VOID CALLBACK
+PlayTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
+{
+ MCI_STATUS_PARMS mciStatus;
+ MCI_PLAY_PARMS mciPlay;
+ DWORD dwPos;
+
+ if (wDeviceId == 0) KillTimer(hwnd, IDT_PLAYTIMER);
+
+ mciStatus.dwItem = MCI_STATUS_POSITION;
+ mciSendCommand(wDeviceId, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&mciStatus);
+ dwPos = mciStatus.dwReturn;
+
+ if ((UINT)dwPos >= MaxFilePos)
+ {
+ if (!bRepeat)
+ {
+ StopPlayback(hwnd);
+ }
+ else
+ {
+ mciSendCommand(wDeviceId, MCI_SEEK, MCI_WAIT | MCI_SEEK_TO_START, 0);
+ mciPlay.dwCallback = (DWORD_PTR)hwnd;
+ mciSendCommand(wDeviceId, MCI_PLAY, MCI_NOTIFY, (DWORD_PTR)&mciPlay);
+ }
+ }
+ else
+ {
+ SendMessage(hTrackBar, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)dwPos);
+ }
+}
+
+static VOID
+StartPlayback(HWND hwnd)
+{
+ MCIERROR mciError;
+ MCI_PLAY_PARMS mciPlay;
+
+ SetTimer(hwnd, IDT_PLAYTIMER, 100, (TIMERPROC)PlayTimerProc);
+
+ mciSendCommand(wDeviceId, MCI_SEEK, MCI_WAIT | MCI_SEEK_TO_START, 0);
+
+ mciPlay.dwCallback = (DWORD_PTR)hwnd;
+ mciPlay.dwFrom = 0;
+ mciPlay.dwTo = MaxFilePos;
+
+ mciError = mciSendCommand(wDeviceId, MCI_PLAY, MCI_NOTIFY | MCI_FROM /*| MCI_TO*/,
(DWORD_PTR)&mciPlay);
+ if (mciError != 0)
+ {
+ ShowMCIError(hwnd, mciError);
+ return;
+ }
+
+ SendMessage(hToolBar,
+ TB_SETCMDID,
+ 0,
+ IDC_PAUSE);
+ SendMessage(hToolBar,
+ TB_CHANGEBITMAP,
+ IDC_PAUSE,
+ IDB_PAUSEICON - IDB_PLAYICON);
+}
+
static VOID
TogglePlaybackState(HWND hwnd)
{
MCIERROR mciError;
MCI_GENERIC_PARMS mciGeneric;
- DWORD dwMode;
ULONG idBmp = IDB_PLAYICON;
ULONG idCmd = IDC_PLAY;
if (wDeviceId == 0) return;
- dwMode = GetDeviceMode(hwnd);
- if (dwMode == MCI_MODE_PLAY)
- {
- mciGeneric.dwCallback = (DWORD_PTR)hwnd;
- mciError = mciSendCommand(wDeviceId, MCI_PAUSE, MCI_NOTIFY,
(DWORD_PTR)&mciGeneric);
- idBmp = IDB_PLAYICON;
- idCmd = IDC_PLAY;
- }
- else if (dwMode == MCI_MODE_PAUSE)
- {
- mciGeneric.dwCallback = (DWORD_PTR)hwnd;
- mciError = mciSendCommand(wDeviceId, MCI_RESUME, MCI_NOTIFY,
(DWORD_PTR)&mciGeneric);
- idBmp = IDB_PAUSEICON;
- idCmd = IDC_PAUSE;
+ switch (GetDeviceMode(hwnd))
+ {
+ case MCI_MODE_OPEN:
+ case MCI_MODE_STOP:
+ {
+ StartPlayback(hwnd);
+ return;
+ }
+
+ case MCI_MODE_PLAY:
+ {
+ mciGeneric.dwCallback = (DWORD_PTR)hwnd;
+ mciError = mciSendCommand(wDeviceId, MCI_PAUSE, MCI_NOTIFY,
(DWORD_PTR)&mciGeneric);
+ idBmp = IDB_PLAYICON;
+ idCmd = IDC_PLAY;
+ break;
+ }
+
+ case MCI_MODE_PAUSE:
+ {
+ mciGeneric.dwCallback = (DWORD_PTR)hwnd;
+ mciError = mciSendCommand(wDeviceId, MCI_RESUME, MCI_NOTIFY,
(DWORD_PTR)&mciGeneric);
+ idBmp = IDB_PAUSEICON;
+ idCmd = IDC_PAUSE;
+ break;
+ }
+
+ default:
+ {
+ return;
+ }
}
if (mciError != 0)
@@ -606,69 +684,6 @@
{
ShowMCIError(hwnd, mciError);
}
-}
-
-VOID CALLBACK
-PlayTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
-{
- MCI_STATUS_PARMS mciStatus;
- MCI_PLAY_PARMS mciPlay;
- DWORD dwPos;
-
- if (wDeviceId == 0) KillTimer(hwnd, IDT_PLAYTIMER);
-
- mciStatus.dwItem = MCI_STATUS_POSITION;
- mciSendCommand(wDeviceId, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&mciStatus);
- dwPos = mciStatus.dwReturn;
-
- if ((UINT)dwPos >= MaxFilePos)
- {
- if (!bRepeat)
- {
- StopPlayback(hwnd);
- }
- else
- {
- mciSendCommand(wDeviceId, MCI_SEEK, MCI_WAIT | MCI_SEEK_TO_START, 0);
- mciPlay.dwCallback = (DWORD_PTR)hwnd;
- mciSendCommand(wDeviceId, MCI_PLAY, MCI_NOTIFY, (DWORD_PTR)&mciPlay);
- }
- }
- else
- {
- SendMessage(hTrackBar, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)dwPos);
- }
-}
-
-static VOID
-StartPlayback(HWND hwnd)
-{
- MCIERROR mciError;
- MCI_PLAY_PARMS mciPlay;
-
- SetTimer(hwnd, IDT_PLAYTIMER, 100, (TIMERPROC)PlayTimerProc);
-
- mciSendCommand(wDeviceId, MCI_SEEK, MCI_WAIT | MCI_SEEK_TO_START, 0);
-
- mciPlay.dwCallback = (DWORD_PTR)hwnd;
- mciPlay.dwFrom = 0;
- mciPlay.dwTo = MaxFilePos;
-
- mciError = mciSendCommand(wDeviceId, MCI_PLAY, MCI_NOTIFY | MCI_FROM /*| MCI_TO*/,
(DWORD_PTR)&mciPlay);
- if (mciError != 0)
- {
- ShowMCIError(hwnd, mciError);
- return;
- }
-
- SendMessage(hToolBar,
- TB_SETCMDID,
- 0,
- IDC_PAUSE);
- SendMessage(hToolBar,
- TB_CHANGEBITMAP,
- IDC_PAUSE,
- IDB_PAUSEICON - IDB_PLAYICON);
}
static VOID
@@ -1012,7 +1027,6 @@
case WM_SIZE:
{
RECT Rect;
- UINT Size;
RECT ToolbarRect;
MCI_DGV_PUT_PARMS mciPut;
@@ -1023,6 +1037,8 @@
if (!bIsSingleWindow)
{
+ UINT Size;
+
Size = GetSystemMetrics(SM_CYMENU) + Rect.bottom;
MoveWindow(hTrackBar, 0, 0, LOWORD(lParam), HIWORD(lParam) - Size,
TRUE);
}
@@ -1079,12 +1095,7 @@
{
if (wDeviceId)
{
- DWORD dwMode = GetDeviceMode(hwnd);
-
- if ((dwMode == MCI_MODE_STOP) || (dwMode == MCI_MODE_OPEN))
- StartPlayback(hwnd);
- else if ((dwMode == MCI_MODE_PAUSE) || (dwMode = MCI_MODE_PLAY))
- TogglePlaybackState(hwnd);
+ TogglePlaybackState(hwnd);
}
else
{