[MPLAY32] Add entries for found mci devices in the "Device" menu. By Ricardo Hanke...
authorAmine Khaldi <amine.khaldi@reactos.org>
Fri, 20 Mar 2015 10:44:36 +0000 (10:44 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Fri, 20 Mar 2015 10:44:36 +0000 (10:44 +0000)
svn path=/trunk/; revision=66833

24 files changed:
reactos/base/applications/mplay32/lang/bg-BG.rc
reactos/base/applications/mplay32/lang/cs-CZ.rc
reactos/base/applications/mplay32/lang/de-DE.rc
reactos/base/applications/mplay32/lang/en-US.rc
reactos/base/applications/mplay32/lang/es-ES.rc
reactos/base/applications/mplay32/lang/fr-FR.rc
reactos/base/applications/mplay32/lang/he-IL.rc
reactos/base/applications/mplay32/lang/it-IT.rc
reactos/base/applications/mplay32/lang/ja-JP.rc
reactos/base/applications/mplay32/lang/nl-NL.rc
reactos/base/applications/mplay32/lang/no-NO.rc
reactos/base/applications/mplay32/lang/pl-PL.rc
reactos/base/applications/mplay32/lang/pt-BR.rc
reactos/base/applications/mplay32/lang/ro-RO.rc
reactos/base/applications/mplay32/lang/ru-RU.rc
reactos/base/applications/mplay32/lang/sk-SK.rc
reactos/base/applications/mplay32/lang/sq-AL.rc
reactos/base/applications/mplay32/lang/sv-SE.rc
reactos/base/applications/mplay32/lang/tr-TR.rc
reactos/base/applications/mplay32/lang/uk-UA.rc
reactos/base/applications/mplay32/lang/zh-CN.rc
reactos/base/applications/mplay32/lang/zh-TW.rc
reactos/base/applications/mplay32/mplay32.c
reactos/base/applications/mplay32/resource.h

index fa68fc9..566e247 100644 (file)
@@ -26,6 +26,7 @@ BEGIN
     END
     POPUP "&Device"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Properties", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Volume Control", IDM_VOLUMECTL
index 3a5e5f3..a31d185 100644 (file)
@@ -27,6 +27,7 @@ BEGIN
     END
     POPUP "&Zařízení"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Vlastnosti", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "Ovládání &hlasitosti", IDM_VOLUMECTL
index b3d6afc..62fbeb0 100644 (file)
@@ -22,6 +22,7 @@ BEGIN
     END
     POPUP "&Gerät"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Eigenschaften", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Lautstärkeregelung", IDM_VOLUMECTL
index e4b0898..3dc25d1 100644 (file)
@@ -22,6 +22,7 @@ BEGIN
     END
     POPUP "&Device"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Properties", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Volume Control", IDM_VOLUMECTL
index b386f98..76726b3 100644 (file)
@@ -22,6 +22,7 @@ BEGIN
     END
     POPUP "&Dispositivo"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Propiedades", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "Control de &volumen", IDM_VOLUMECTL
index c29ee2d..d7eaa04 100644 (file)
@@ -22,6 +22,7 @@ BEGIN
     END
     POPUP "Périp&hérique"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Propriétés", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "Contrôle du &volume", IDM_VOLUMECTL
index e443085..2464880 100644 (file)
@@ -22,6 +22,7 @@ BEGIN
     END
     POPUP "&Device"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Properties", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Volume Control", IDM_VOLUMECTL
index 09f5202..34d0aa7 100644 (file)
@@ -22,6 +22,7 @@ BEGIN
     END
     POPUP "&Device"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Properties", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Volume Control", IDM_VOLUMECTL
index 3c07586..21217cf 100644 (file)
@@ -22,6 +22,7 @@ BEGIN
     END
     POPUP "&Device"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Properties", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Volume Control", IDM_VOLUMECTL
index e71afa1..09f8ca4 100644 (file)
@@ -22,6 +22,7 @@ BEGIN
     END
     POPUP "&Device"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Properties", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Volume Control", IDM_VOLUMECTL
index f0056fe..1ddc2bd 100644 (file)
@@ -22,6 +22,7 @@ BEGIN
     END
     POPUP "&Device"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Properties", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Volume Control", IDM_VOLUMECTL
index 2a47d97..a210973 100644 (file)
@@ -30,6 +30,7 @@ BEGIN
     END
     POPUP "&Urządzenie"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "Właś&ciwości", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Regulacja głośności", IDM_VOLUMECTL
index d9b5f50..d37f0f0 100644 (file)
@@ -24,6 +24,7 @@ BEGIN
     END
     POPUP "&Device"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Properties", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Volume Control", IDM_VOLUMECTL
index aa3b295..70ee6a0 100644 (file)
@@ -28,6 +28,7 @@ BEGIN
     END
     POPUP "&Dispozitiv"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Proprietăți…", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "Control &volum…", IDM_VOLUMECTL
index 57a893f..a7b0b4a 100644 (file)
@@ -22,6 +22,7 @@ BEGIN
     END
     POPUP "&Устройство"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Свойства", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Громкость", IDM_VOLUMECTL
index 895a585..ac6835e 100644 (file)
@@ -27,6 +27,7 @@ BEGIN
     END
     POPUP "&Device"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Properties", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Volume Control", IDM_VOLUMECTL
index b3eb502..aa63c98 100644 (file)
@@ -26,6 +26,7 @@ BEGIN
     END
     POPUP "&Device"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Properties", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Volume Control", IDM_VOLUMECTL
index 9e9fb5c..c184729 100644 (file)
@@ -29,6 +29,7 @@ BEGIN
     END
     POPUP "&Device"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Properties", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Volume Control", IDM_VOLUMECTL
index 4368980..d85e381 100644 (file)
@@ -24,6 +24,7 @@ BEGIN
     END
     POPUP "&Aygıt"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Husûsiyetler", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Ses Düzeyi Denetimi", IDM_VOLUMECTL
index b5d3ead..c806627 100644 (file)
@@ -30,6 +30,7 @@ BEGIN
     END
     POPUP "&Device"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Properties", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Volume Control", IDM_VOLUMECTL
index 9b25bd2..ace824e 100644 (file)
@@ -24,6 +24,7 @@ BEGIN
     END
     POPUP "设备(&D)"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "属性(&P)", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "音量控制(&V)", IDM_VOLUMECTL
index 4cd5bda..2517925 100644 (file)
@@ -30,6 +30,7 @@ BEGIN
     END
     POPUP "&Device"
     BEGIN
+        MENUITEM SEPARATOR
         MENUITEM "&Properties", IDM_DEVPROPS
         MENUITEM SEPARATOR
         MENUITEM "&Volume Control", IDM_VOLUMECTL
index 95e03b6..46f33d4 100644 (file)
@@ -483,6 +483,38 @@ GetDeviceFriendlyName(LPTSTR lpDeviceName, LPTSTR lpFriendlyName, DWORD dwFriend
     return mciError;
 }
 
+static BOOL
+DeviceUsesFiles(LPTSTR lpDeviceName)
+{
+    MCIERROR mciError;
+    MCI_OPEN_PARMS mciOpen;
+    MCI_GETDEVCAPS_PARMS mciDevCaps;
+    MCI_GENERIC_PARMS mciGeneric;
+
+    mciOpen.dwCallback = 0;
+    mciOpen.wDeviceID  = 0;
+    mciOpen.lpstrDeviceType  = lpDeviceName;
+    mciOpen.lpstrElementName = NULL;
+    mciOpen.lpstrAlias = NULL;
+
+    mciError = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_WAIT, (DWORD_PTR)&mciOpen);
+    if (mciError != 0)
+        return FALSE;
+
+    mciDevCaps.dwCallback  = 0;
+    mciDevCaps.dwReturn = 0;
+    mciDevCaps.dwItem = MCI_GETDEVCAPS_USES_FILES;
+
+    mciError = mciSendCommand(mciOpen.wDeviceID, MCI_GETDEVCAPS, MCI_WAIT | MCI_GETDEVCAPS_ITEM, (DWORD_PTR)&mciDevCaps);
+    if (mciError != 0)
+        return FALSE;
+
+    mciGeneric.dwCallback = 0;
+    mciSendCommand(mciOpen.wDeviceID, MCI_CLOSE, MCI_WAIT, (DWORD_PTR)&mciGeneric);
+
+    return (BOOL)mciDevCaps.dwReturn;
+}
+
 static MCIERROR
 CloseMciDevice(VOID)
 {
@@ -509,7 +541,7 @@ OpenMciDevice(HWND hwnd, LPTSTR lpType, LPTSTR lpFileName)
     MCIERROR mciError;
     MCI_STATUS_PARMS mciStatus;
     MCI_OPEN_PARMS mciOpen;
-    DWORD dwFlags = MCI_OPEN_ELEMENT | MCI_WAIT;
+    DWORD dwFlags = MCI_WAIT;
     LPTSTR lpStr;
 
     if (wDeviceId)
@@ -524,6 +556,9 @@ OpenMciDevice(HWND hwnd, LPTSTR lpType, LPTSTR lpFileName)
     if (lpType)
         dwFlags |= MCI_OPEN_TYPE;
 
+    if (lpFileName)
+        dwFlags |= MCI_OPEN_ELEMENT;
+
     mciError = mciSendCommand(0, MCI_OPEN, dwFlags, (DWORD_PTR)&mciOpen);
     if (mciError != 0)
         return mciError;
@@ -562,11 +597,16 @@ OpenMciDevice(HWND hwnd, LPTSTR lpType, LPTSTR lpFileName)
 
     /* NOTE: Everything above this line may be done instead in OpenMediaFile() */
 
-    lpStr = _tcsrchr(lpFileName, _T('\\'));
-    if (lpStr) // Get only the file name (skip the last path separator)
-        lpStr++;
+    if (lpFileName)
+    {
+        lpStr = _tcsrchr(lpFileName, _T('\\'));
+        if (lpStr) // Get only the file name (skip the last path separator)
+            lpStr++;
+        else
+            lpStr = lpFileName;
+    }
     else
-        lpStr = lpFileName;
+        lpStr = lpType;
 
     StringCbCopy(szCurrentFile, sizeof(szCurrentFile), lpStr);
 
@@ -852,7 +892,7 @@ CloseMediaFile(HWND hwnd)
 }
 
 static VOID
-OpenMediaFile(HWND hwnd, LPTSTR lpFileName)
+OpenMediaFile(HWND hwnd, LPTSTR lpFileName, LPTSTR lpType)
 {
     MCIERROR mciError;
 
@@ -862,7 +902,7 @@ OpenMediaFile(HWND hwnd, LPTSTR lpFileName)
     if (wDeviceId)
         CloseMediaFile(hwnd);
 
-    mciError = OpenMciDevice(hwnd, NULL, lpFileName);
+    mciError = OpenMciDevice(hwnd, lpType, lpFileName);
     if (mciError != 0)
     {
         ShowMCIError(hwnd, mciError);
@@ -872,8 +912,45 @@ OpenMediaFile(HWND hwnd, LPTSTR lpFileName)
     StartPlayback(hwnd);
 }
 
+static DWORD
+InsertDeviceMenuItem(HMENU hMenu, UINT uItem, BOOL fByPosition, UINT uItemID, DWORD dwDeviceIndex)
+{
+    MENUITEMINFO lpmii;
+    MCIERROR mciError;
+    TCHAR szDeviceName[MAX_MCISTR];
+    TCHAR szFriendlyName[MAX_MCISTR];
+
+    mciError = GetDeviceName(dwDeviceIndex, szDeviceName, sizeof(szDeviceName));
+    if (mciError)
+    {
+        return mciError;
+    }
+
+    mciError = GetDeviceFriendlyName(szDeviceName, szFriendlyName, sizeof(szFriendlyName));
+    if (mciError)
+    {
+        return mciError;
+    }
+
+    if (DeviceUsesFiles(szDeviceName))
+    {
+        StringCbCat(szFriendlyName, sizeof(szFriendlyName), _T("..."));
+    }
+
+    ZeroMemory(&lpmii, sizeof(MENUITEMINFO));
+    lpmii.cbSize = sizeof(lpmii);
+    lpmii.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID;
+    lpmii.wID = uItemID;
+    lpmii.fType = MF_STRING;
+    lpmii.dwTypeData = szFriendlyName;
+    lpmii.dwItemData = dwDeviceIndex;
+    InsertMenuItem(hMenu, uItem, fByPosition, &lpmii);
+
+    return 0;
+}
+
 static VOID
-BuildFileFilter(VOID)
+BuildFileFilterAndDeviceMenu(VOID)
 {
     TCHAR szDeviceName[MAX_MCISTR];
     TCHAR szFriendlyName[MAX_MCISTR];
@@ -891,6 +968,7 @@ BuildFileFilter(VOID)
     DWORD dwFilterSize;
     DWORD dwDeviceSize;
     DWORD dwExtensionLen;
+    DWORD dwPosition = 0;
     DWORD i;
     DWORD j;
     UINT uSizeRemain;
@@ -953,6 +1031,10 @@ BuildFileFilter(VOID)
             continue;
         }
 
+        /* Insert a menu item under the "Device" menu for every found MCI device */
+        InsertDeviceMenuItem(GetSubMenu(hMainMenu, 3), dwPosition, TRUE, IDM_DEVICE_FIRST + dwPosition, j);
+        dwPosition++;
+
         /* Copy the default extension list, that may be overwritten after... */
         StringCbCopy(szExtensionList, dwMaskLen * sizeof(TCHAR), szDefaultExtension);
 
@@ -1065,7 +1147,7 @@ CleanupFileFilter(VOID)
 }
 
 static VOID
-OpenFileDialog(HWND hwnd)
+OpenFileDialog(HWND hwnd, DWORD dwFilterIndex, LPTSTR lpType)
 {
     OPENFILENAME OpenFileName;
     TCHAR szFile[MAX_PATH + 1] = _T("");
@@ -1087,11 +1169,46 @@ OpenFileDialog(HWND hwnd)
     OpenFileName.lpstrInitialDir = szCurrentDir;
     OpenFileName.Flags           = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_SHAREAWARE;
     OpenFileName.lpstrDefExt     = _T("\0");
+    OpenFileName.nFilterIndex = dwFilterIndex;
 
     if (!GetOpenFileName(&OpenFileName))
         return;
 
-    OpenMediaFile(hwnd, OpenFileName.lpstrFile);
+    OpenMediaFile(hwnd, OpenFileName.lpstrFile, lpType);
+}
+
+static VOID
+HandleDeviceMenuItem(HWND hwnd, UINT uItem)
+{
+    MENUITEMINFO lpmii;
+    TCHAR szDeviceName[MAX_MCISTR];
+    MCIERROR mciError;
+
+    ZeroMemory(&lpmii, sizeof(MENUITEMINFO));
+    lpmii.cbSize = sizeof(lpmii);
+    lpmii.fMask = MIIM_DATA;
+    GetMenuItemInfo(hMainMenu, uItem, FALSE, &lpmii);
+
+    mciError = GetDeviceName(lpmii.dwItemData, szDeviceName, sizeof(szDeviceName));
+    if (mciError)
+    {
+        ShowMCIError(hwnd, mciError);
+        return;
+    }
+
+    if (DeviceUsesFiles(szDeviceName))
+    {
+        OpenFileDialog(hwnd, uItem - IDM_DEVICE_FIRST + 1, szDeviceName);
+        return;
+    }
+
+    mciError = OpenMciDevice(hwnd, szDeviceName, NULL);
+    if (mciError)
+    {
+        ShowMCIError(hwnd, mciError);
+    }
+
+    return;
 }
 
 LRESULT CALLBACK
@@ -1114,7 +1231,7 @@ MainWndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
             drophandle = (HDROP)wParam;
             DragQueryFile(drophandle, 0, droppedfile, ARRAYSIZE(droppedfile));
             DragFinish(drophandle);
-            OpenMediaFile(hwnd, droppedfile);
+            OpenMediaFile(hwnd, droppedfile, NULL);
             break;
         }
 
@@ -1241,6 +1358,12 @@ MainWndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
 
         case WM_COMMAND:
         {
+            if (LOWORD(wParam) >= IDM_DEVICE_FIRST)
+            {
+                HandleDeviceMenuItem(hwnd, LOWORD(wParam));
+                break;
+            }
+
             switch (LOWORD(wParam))
             {
                 case IDC_PLAY:
@@ -1249,7 +1372,7 @@ MainWndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
                     if (wDeviceId)
                         TogglePlaybackState(hwnd);
                     else
-                        OpenFileDialog(hwnd);
+                        OpenFileDialog(hwnd, 1, NULL);
 
                     break;
                 }
@@ -1276,7 +1399,7 @@ MainWndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
                     break;
 
                 case IDM_OPEN_FILE:
-                    OpenFileDialog(hwnd);
+                    OpenFileDialog(hwnd, 1, NULL);
                     return 0;
 
                 case IDM_CLOSE_FILE:
@@ -1383,7 +1506,7 @@ _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow)
 
     hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(ID_ACCELERATORS));
 
-    BuildFileFilter();
+    BuildFileFilterAndDeviceMenu();
 
     DragAcceptFiles(hwnd, TRUE);
 
@@ -1399,7 +1522,7 @@ _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow)
     ShowWindow(hwnd, SW_SHOW);
     UpdateWindow(hwnd);
 
-    OpenMediaFile(hwnd, lpCmdLine);
+    OpenMediaFile(hwnd, lpCmdLine, NULL);
 
     /* Message Loop */
     while (GetMessage(&msg, NULL, 0, 0))
index c1150c0..7a0276f 100644 (file)
@@ -52,6 +52,9 @@
 #define IDM_REPEAT     1006
 #define IDM_SWITCHVIEW 1007
 
+/* The device specific items in the device menu start here */
+#define IDM_DEVICE_FIRST 10000
+
 /* ToolBar Icons */
 #define TBICON_PLAY     0
 #define TBICON_STOP     1